8000 Merge branch 'master' of github.com:mkdocstrings/python · laysauchoa/python@7ec02fb · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ec02fb

Browse files
committed
Merge branch 'master' of github.com:mkdocstrings/python
2 parents b4fb4db + 67206aa commit 7ec02fb

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: ci
22

33
on:
44
push:
5-
branches:
6-
- master
75
pull_request:
86
branches:
97
- master
@@ -77,7 +75,7 @@ jobs:
7775
python-version: ${{ matrix.python-version }}
7876

7977
- name: Install dependencies
80-
run: pdm install --no-editable -G duty -G tests
78+
run: pdm install --no-editable -G duty -G tests -G docs
8179

8280
- name: Run the test suite
8381
run: pdm run duty test

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
<!-- insertion marker -->
8+
## [0.8.2](https://github.com/mkdocstrings/python/releases/tag/0.8.2) - 2022-11-19
9+
10+
<small>[Compare with 0.8.1](https://github.com/mkdocstrings/python/compare/0.8.1...0.8.2)</small>
11+
12+
### Bug Fixes
13+
- Fix base directory used to expand globs ([34cfa4b](https://github.com/mkdocstrings/python/commit/34cfa4b41f264437a338e66f6060ceeee134ba15) by Florian Hofer). [PR #45](https://github.com/mkdocstrings/python/pull/45)
14+
15+
16+
## [0.8.1](https://github.com/mkdocstrings/python/releases/tag/0.8.1) - 2022-11-19
17+
18+
<small>[Compare with 0.8.0](https://github.com/mkdocstrings/python/compare/0.8.0...0.8.1)</small>
19+
20+
### Bug Fixes
21+
- Expand globs relative to configuration file path ([0dc45ae](https://github.com/mkdocstrings/python/commit/0dc45aeb7c7f9b2f15118ebf1584baa06d365c9b) by David Vegh). [Issue #42](https://github.com/mkdocstrings/python/issues/42), [PR #43](https://github.com/mkdocstrings/python/pull/43)
22+
23+
824
## [0.8.0](https://github.com/mkdocstrings/python/releases/tag/0.8.0) - 2022-11-13
925

1026
<small>[Compare with 0.7.1](https://github.com/mkdocstrings/python/compare/0.7.1...0.8.0)</small>

src/mkdocstrings_handlers/python/handler.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525

2626
from mkdocstrings_handlers.python import rendering
2727

28+
if sys.version_info >= (3, 11):
29+
from contextlib import chdir
30+
else:
31+
# TODO: remove once support for Python 3.10 is dropped
32+
from contextlib import contextmanager
33+
34+
@contextmanager # noqa: WPS440
35+
def chdir(path: str): # noqa: D103,WPS440
36+
old_wd = os.getcwd()
37+
os.chdir(path)
38+
try:
39+
yield
40+
finally:
41+
os.chdir(old_wd)
42+
43+
2844
logger = get_logger(__name__)
2945

3046
patch_loggers(get_logger)
@@ -129,7 +145,9 @@ def __init__(
129145
super().__init__(*args, **kwargs)
130146
self._config_file_path = config_file_path
131147
paths = paths or []
132-
resolved_globs = [glob.glob(path) for path in paths]
148+
glob_base_dir = os.path.dirname(os.path.abspath(config_file_path)) if config_file_path else "."
149+
with chdir(glob_base_dir):
150+
resolved_globs = [glob.glob(path) for path in paths]
133151
paths = [path for glob_list in resolved_globs for path in glob_list]
134152
if not paths and config_file_path:
135153
paths.append(os.path.dirname(config_file_path))

tests/test_handler.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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

6-
from mkdocstrings_handlers.python.handler import CollectionError, get_handler
9+
from mkdocstrings_handlers.python.handler import CollectionError, PythonHandler, get_handler
710

811

912
def test_collect_missing_module():
@@ -58,3 +61,40 @@ def test_render_docstring_examples_section(handler):
5861
assert "<p>This is an example.</p>" in rendered
5962
assert "print" in rendered
6063
assert "Hello" in rendered
64+
65+
66+
def test_expand_globs(tmp_path):
67+
"""Assert globs are correctly expanded.
68+
69+
Parameters:
70+
tmp_path: Pytext fixture that creates a temporary directory.
71+
"""
72+
globbed_names = (
73+
"expanded_a",
74+
"expanded_b",
75+
"other_expanded_c",
76+
"other_expanded_d",
77+
)
78+
globbed_paths = [tmp_path.joinpath(globbed_name) for globbed_name in globbed_names]
79+
for path in globbed_paths:
80+
path.touch()
81+
handler = PythonHandler(
82+
handler="python",
83+
theme="material",
84+
config_file_path=tmp_path / "mkdocs.yml",
85+
paths=["*exp*"],
86+
)
87+
for path in globbed_paths: # noqa: WPS440
88+
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