Skip to content

Commit

Permalink
fix: Fix discovery of packages in the current working directory
Browse files Browse the repository at this point in the history
Discussion-mkdocstrings#654: mkdocstrings/mkdocstrings#654
  • Loading branch information
pawamoy committed Mar 3, 2024
1 parent 5ae1cf5 commit 44f9617
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/griffe/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def submodules(self, module: Module) -> list[NamePartsAndPathType]:
)

def _module_name_path(self, path: Path) -> tuple[str, Path]:
# Always return absolute paths to avoid working-directory-dependent issues.
path = path.absolute()
if path.is_dir():
for ext in self.accepted_py_module_extensions:
module_path = path / f"__init__{ext}"
Expand All @@ -354,9 +356,7 @@ def _module_name_path(self, path: Path) -> tuple[str, Path]:
return path.name, path
if path.exists():
if path.stem == "__init__":
if path.parent.is_absolute():
return path.parent.name, path
return path.parent.resolve().name, path
return path.parent.name, path
return path.stem, path
raise FileNotFoundError

Expand Down Expand Up @@ -392,10 +392,11 @@ def _filter_py_modules(self, path: Path) -> Iterator[Path]:
def _top_module_name(self, path: Path) -> str:
# First find if a parent is in search paths.
parent_path = path if path.is_dir() else path.parent
# Always resolve parent path to compare for relativeness against resolved search paths.
parent_path = parent_path.resolve()
for search_path in self.search_paths:
with suppress(ValueError):
# FIXME: It does not work when `parent_path` is relative and `search_path` absolute.
rel_path = parent_path.relative_to(search_path)
rel_path = parent_path.relative_to(search_path.resolve())
top_path = search_path / rel_path.parts[0]
return top_path.name
# If not, get the highest directory with an `__init__` module,
Expand Down

0 comments on commit 44f9617

Please sign in to comment.