From be2364eb0b73390deb188628159564dcbe265e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 26 Nov 2024 15:18:52 +0100 Subject: [PATCH] fix: Fix normalization of extension paths on the annoying operating system 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. --- src/mkdocstrings_handlers/python/handler.py | 8 +++----- tests/test_handler.py | 9 +++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 0aac3cdc..628b56ec 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -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}) diff --git a/tests/test_handler.py b/tests/test_handler.py index 0717dc48..6c2381db 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -119,10 +119,11 @@ def test_expand_globs_without_changing_directory() -> None: (True, {"extension.py:SomeExtension": {"option": "value"}}), (True, {"path/to/extension.py": {"option": "value"}}), (True, {"path/to/extension.py:SomeExtension": {"option": "value"}}), - (False, "/absolute/path/to/extension.py"), - (False, "/absolute/path/to/extension.py:SomeExtension"), - (False, {"/absolute/path/to/extension.py": {"option": "value"}}), - (False, {"/absolute/path/to/extension.py:SomeExtension": {"option": "value"}}), + # True because OS path normalization. + (True, "/absolute/path/to/extension.py"), + (True, "/absolute/path/to/extension.py:SomeExtension"), + (True, {"/absolute/path/to/extension.py": {"option": "value"}}), + (True, {"/absolute/path/to/extension.py:SomeExtension": {"option": "value"}}), (False, "dot.notation.path.to.extension"), (False, "dot.notation.path.to.pyextension"), (False, {"dot.notation.path.to.extension": {"option": "value"}}),