8000 fix: Fix base directory used to expand globs · FasterSpeeding/python@34cfa4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 34cfa4b

Browse files
hofaflopawamoy
andauthored
fix: Fix base directory used to expand globs
PR mkdocstrings#45: mkdocstrings#45 Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
1 parent 10a7884 commit 34cfa4b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/mkdocstrings_handlers/python/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def __init__(
145145
super().__init__(*args, **kwargs)
146146
self._config_file_path = config_file_path
147147
paths = paths or []
148-
with chdir(os.path.dirname(config_file_path) if config_file_path else "."):
148+
glob_base_dir = os.path.dirname(os.path.abspath(config_file_path)) if config_file_path else "."
149+
with chdir(glob_base_dir):
149150
resolved_globs = [glob.glob(path) for path in paths]
150151
paths = [path for glob_list in resolved_globs for path in glob_list]
151152
if not paths and config_file_path:

tests/test_handler.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Tests for the `handler` module."""
22

3+
import os
4+
from glob import glob
5+
36
import pytest
47
from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind
58

@@ -83,3 +86,15 @@ def test_expand_globs(tmp_path):
8386
)
8487
for path in globbed_paths: # noqa: WPS440
8588
assert str(path) in handler._paths # noqa: WPS437
89+
90+
91+
def test_expand_globs_without_changing_directory():
92+
"""Assert globs are correctly expanded when we are already in the right directory."""
93+
handler = PythonHandler(
94+
handler="python",
95+
theme="material",
96+
config_file_path="mkdocs.yml",
97+
paths=["*.md"],
98+
)
99+
for path in list(glob(os.path.abspath(".") + "/*.md")):
100+
assert path in handler._paths # noqa: WPS437

0 commit comments

Comments
 (0)
0