Skip to content

Commit 44f9617

Browse files
committed
fix: Fix discovery of packages in the current working directory
Discussion-mkdocstrings#654: mkdocstrings/mkdocstrings#654
1 parent 5ae1cf5 commit 44f9617

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/griffe/finder.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ def submodules(self, module: Module) -> list[NamePartsAndPathType]:
346346
)
347347

348348
def _module_name_path(self, path: Path) -> tuple[str, Path]:
349+
# Always return absolute paths to avoid working-directory-dependent issues.
350+
path = path.absolute()
349351
if path.is_dir():
350352
for ext in self.accepted_py_module_extensions:
351353
module_path = path / f"__init__{ext}"
@@ -354,9 +356,7 @@ def _module_name_path(self, path: Path) -> tuple[str, Path]:
354356
return path.name, path
355357
if path.exists():
356358
if path.stem == "__init__":
357-
if path.parent.is_absolute():
358-
return path.parent.name, path
359-
return path.parent.resolve().name, path
359+
return path.parent.name, path
360360
return path.stem, path
361361
raise FileNotFoundError
362362

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

0 commit comments

Comments
 (0)