Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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