Skip to content

Commit

Permalink
refactor: Catch index errors when finding top module in case of searc…
Browse files Browse the repository at this point in the history
…h path misconfiguration

Issue-#246: #246
  • Loading branch information
pawamoy committed Mar 4, 2024
1 parent e49e7f6 commit 46c56c7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/griffe/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,9 @@ def _top_module_name(self, path: Path) -> str:
# 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):
with suppress(ValueError, IndexError):
rel_path = parent_path.relative_to(search_path.resolve())
top_path = search_path / rel_path.parts[0]
return top_path.name
return rel_path.parts[0]
# If not, get the highest directory with an `__init__` module,
# add its parent to search paths and return it.
while parent_path.parent != parent_path and (parent_path.parent / "__init__.py").exists():
Expand Down

0 comments on commit 46c56c7

Please # to comment.