Skip to content

Commit 4e67d8f

Browse files
committed
fix: Support absolute Windows paths for extensions
Issue mkdocstrings-python#116: mkdocstrings/python#116
1 parent 839c8cc commit 4e67d8f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/griffe/extensions/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections import defaultdict
99
from importlib.util import module_from_spec, spec_from_file_location
1010
from inspect import isclass
11+
from pathlib import Path
1112
from typing import TYPE_CHECKING, Any, Sequence, Union
1213

1314
from griffe.agents.nodes import ast_children, ast_kind
@@ -405,8 +406,9 @@ def _load_extension(
405406
options = {}
406407

407408
# If the import path contains a colon, we split into path and class name.
408-
if ":" in import_path:
409-
import_path, extension_name = import_path.split(":", 1)
409+
colons = import_path.count(":")
410+
if colons > 1 or (colons and ":" not in Path(import_path).drive):
411+
import_path, extension_name = import_path.rsplit(":", 1)
410412
else:
411413
extension_name = None
412414

tests/test_extensions.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from pathlib import Path
56
from typing import TYPE_CHECKING, Any
67

78
import pytest
@@ -82,6 +83,9 @@ def on_node(self, *, node: ast.AST | ObjectNode) -> None: # noqa: D102,ARG002
8283
ExtensionTest(option=0),
8384
# with class
8485
ExtensionTest,
86+
# with absolute paths (esp. important to test for Windows)
87+
Path("tests/test_extensions.py").absolute().as_posix(),
88+
Path("tests/test_extensions.py:ExtensionTest").absolute().as_posix(),
8589
],
8690
)
8791
def test_loading_extensions(extension: str | dict[str, dict[str, Any]] | Extension | type[Extension]) -> None:

0 commit comments

Comments
 (0)