Skip to content

Commit

Permalink
fix: Fix base directory used to expand globs
Browse files Browse the repository at this point in the history
PR #45: #45
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
  • Loading branch information
hofaflo committed Nov 19, 2022
1 parent 10a7884 commit 34cfa4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mkdocstrings_handlers/python/handler.py
Expand Up @@ -145,7 +145,8 @@ def __init__(
super().__init__(*args, **kwargs)
self._config_file_path = config_file_path
paths = paths or []
with chdir(os.path.dirname(config_file_path) if config_file_path else "."):
glob_base_dir = os.path.dirname(os.path.abspath(config_file_path)) if config_file_path else "."
with chdir(glob_base_dir):
resolved_globs = [glob.glob(path) for path in paths]
paths = [path for glob_list in resolved_globs for path in glob_list]
if not paths and config_file_path:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_handler.py
@@ -1,5 +1,8 @@
"""Tests for the `handler` module."""

import os
from glob import glob

import pytest
from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind

Expand Down Expand Up @@ -83,3 +86,15 @@ def test_expand_globs(tmp_path):
)
for path in globbed_paths: # noqa: WPS440
assert str(path) in handler._paths # noqa: WPS437


def test_expand_globs_without_changing_directory():
"""Assert globs are correctly expanded when we are already in the right directory."""
handler = PythonHandler(
handler="python",
theme="material",
config_file_path="mkdocs.yml",
paths=["*.md"],
)
for path in list(glob(os.path.abspath(".") + "/*.md")):
assert path in handler._paths # noqa: WPS437

0 comments on commit 34cfa4b

Please sign in to comment.