From 0dc45aeb7c7f9b2f15118ebf1584baa06d365c9b Mon Sep 17 00:00:00 2001 From: David Vegh <61405792+veghdev@users.noreply.github.com> Date: Sat, 19 Nov 2022 13:18:03 +0100 Subject: [PATCH 1/4] fix: Expand globs relative to configuration file path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timothée Mazzucotelli Issue #42: https://github.com/mkdocstrings/python/issues/42 PR #43: https://github.com/mkdocstrings/python/pull/43 --- src/mkdocstrings_handlers/python/handler.py | 19 ++++++++++++++- tests/test_handler.py | 27 ++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 0288afa5..4d076f8b 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -25,6 +25,22 @@ from mkdocstrings_handlers.python import rendering +if sys.version_info >= (3, 11): + from contextlib import chdir +else: + # TODO: remove once support for Python 3.10 is dropped + from contextlib import contextmanager + + @contextmanager # noqa: WPS440 + def chdir(path: str): # noqa: D103,WPS440 + old_wd = os.getcwd() + os.chdir(path) + try: + yield + finally: + os.chdir(old_wd) + + logger = get_logger(__name__) patch_loggers(get_logger) @@ -129,7 +145,8 @@ def __init__( super().__init__(*args, **kwargs) self._config_file_path = config_file_path paths = paths or [] - resolved_globs = [glob.glob(path) for path in paths] + with chdir(os.path.dirname(config_file_path) if config_file_path else "."): + 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: paths.append(os.path.dirname(config_file_path)) diff --git a/tests/test_handler.py b/tests/test_handler.py index 5a49a8b1..280e4791 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -3,7 +3,7 @@ import pytest from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind -from mkdocstrings_handlers.python.handler import CollectionError, get_handler +from mkdocstrings_handlers.python.handler import CollectionError, PythonHandler, get_handler def test_collect_missing_module(): @@ -58,3 +58,28 @@ def test_render_docstring_examples_section(handler): assert "

This is an example.

" in rendered assert "print" in rendered assert "Hello" in rendered + + +def test_expand_globs(tmp_path): + """Assert globs are correctly expanded. + + Parameters: + tmp_path: Pytext fixture that creates a temporary directory. + """ + globbed_names = ( + "expanded_a", + "expanded_b", + "other_expanded_c", + "other_expanded_d", + ) + globbed_paths = [tmp_path.joinpath(globbed_name) for globbed_name in globbed_names] + for path in globbed_paths: + path.touch() + handler = PythonHandler( + handler="python", + theme="material", + config_file_path=tmp_path / "mkdocs.yml", + paths=["*exp*"], + ) + for path in globbed_paths: # noqa: WPS440 + assert str(path) in handler._paths # noqa: WPS437 From de48df7095680f284140e93200b5d2cd3696fa60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 19 Nov 2022 13:19:21 +0100 Subject: [PATCH 2/4] ci: Install docs dependencies for tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 287efc83..bc13f190 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pdm install --no-editable -G duty -G tests + run: pdm install --no-editable -G duty -G tests -G docs - name: Run the test suite run: pdm run duty test From df1493c63d490cac602fa9831ed4e55a9d29216e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 19 Nov 2022 15:15:35 +0100 Subject: [PATCH 3/4] ci: Allow CI to run on branches --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc13f190..f9abeb46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,6 @@ name: ci on: push: - branches: - - master pull_request: branches: - master From 10a7884824fb14bcd5776e63fd5467e3105c95a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 19 Nov 2022 15:22:49 +0100 Subject: [PATCH 4/4] chore: Prepare release 0.8.1 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7389238..e2c57900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.8.1](https://github.com/mkdocstrings/python/releases/tag/0.8.1) - 2022-11-19 + +[Compare with 0.8.0](https://github.com/mkdocstrings/python/compare/0.8.0...0.8.1) + +### Bug Fixes +- 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) + + ## [0.8.0](https://github.com/mkdocstrings/python/releases/tag/0.8.0) - 2022-11-13 [Compare with 0.7.1](https://github.com/mkdocstrings/python/compare/0.7.1...0.8.0)