Skip to content

Commit

Permalink
MAINT: reduce indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Feb 4, 2024
1 parent 351890b commit 9d0592a
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions mesonpy/_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,34 +261,38 @@ def find_spec(
path: Optional[Sequence[Union[bytes, str]]] = None,
target: Optional[ModuleType] = None
) -> Optional[importlib.machinery.ModuleSpec]:
if fullname.split('.', maxsplit=1)[0] in self._top_level_modules:
if self._build_path in os.environ.get(MARKER, '').split(os.pathsep):
return None
namespace = False
tree = self._rebuild()
parts = fullname.split('.')

# look for a package
package = tree.get(tuple(parts))
if isinstance(package, Node):
for loader, suffix in LOADERS:
src = package.get('__init__' + suffix)
if isinstance(src, str):
return build_module_spec(loader, fullname, src, package)
else:
namespace = True

# look for a module
if fullname.split('.', maxsplit=1)[0] not in self._top_level_modules:
return None

if self._build_path in os.environ.get(MARKER, '').split(os.pathsep):
return None

namespace = False
tree = self._rebuild()
parts = fullname.split('.')

# look for a package
package = tree.get(tuple(parts))
if isinstance(package, Node):
for loader, suffix in LOADERS:
src = tree.get((*parts[:-1], parts[-1] + suffix))
src = package.get('__init__' + suffix)
if isinstance(src, str):
return build_module_spec(loader, fullname, src, None)

# namespace
if namespace:
spec = importlib.machinery.ModuleSpec(fullname, None)
spec.submodule_search_locations = []
return spec
return build_module_spec(loader, fullname, src, package)
else:
namespace = True

# look for a module
for loader, suffix in LOADERS:
src = tree.get((*parts[:-1], parts[-1] + suffix))
if isinstance(src, str):
return build_module_spec(loader, fullname, src, None)

# namespace
if namespace:
spec = importlib.machinery.ModuleSpec(fullname, None)
spec.submodule_search_locations = []
return spec

return None

Expand Down

0 comments on commit 9d0592a

Please sign in to comment.