Skip to content

Commit

Permalink
fix: Fix normalization of extension paths on the annoying operating s…
Browse files Browse the repository at this point in the history
…ystem and Python 3.13

Python 3.13 changed `os.path.isabs`:

> On Windows, `isabs()` no longer considers paths starting with exactly one slash (`\` or `/`) to be absolute.

See https://docs.python.org/3/whatsnew/3.13.html#os-path.
  • Loading branch information
pawamoy committed Nov 26, 2024
1 parent 6c5b5c3 commit 647afb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,9 @@ def normalize_extension_paths(self, extensions: Sequence) -> Sequence:
pth = str(ext)
options = None

if pth.endswith(".py") or ".py:" in pth or "/" in pth or "\\" in pth: # noqa: SIM102
# This is a sytem path. Normalize it.
if not os.path.isabs(pth):
# Make path absolute relative to config file path.
pth = os.path.normpath(os.path.join(base_path, pth))
if pth.endswith(".py") or ".py:" in pth or "/" in pth or "\\" in pth:
# This is a system path. Normalize it, make it absolute relative to config file path.
pth = os.path.abspath(os.path.join(base_path, pth))

if options is not None:
normalized.append({pth: options})
Expand Down
4 changes: 2 additions & 2 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def test_extension_paths(tmp_path: Path, expect_change: bool, extension: str | d
normalized = handler.normalize_extension_paths([extension])[0]
if expect_change:
if isinstance(normalized, str) and isinstance(extension, str):
assert normalized == str(tmp_path.joinpath(extension))
assert normalized == os.fspath(tmp_path.joinpath(extension))
elif isinstance(normalized, dict) and isinstance(extension, dict):
pth, options = next(iter(extension.items()))
assert normalized == {str(tmp_path.joinpath(pth)): options}
assert normalized == {os.fspath(tmp_path.joinpath(pth)): options}
else:
raise ValueError("Normalization must not change extension items type")
else:
Expand Down

0 comments on commit 647afb5

Please sign in to comment.