From cfbd7bb4761691ef36100962c775ed1d0a247514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 14 Jan 2022 20:30:48 +0100 Subject: [PATCH 1/5] build: Require griffe 0.10 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4b3dec58..712b079c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "griffe>=0.7.1", + "griffe>=0.10", ] [project.urls] From 27af4c12087538626d42744d3e735105edcb4488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 14 Jan 2022 20:31:09 +0100 Subject: [PATCH 2/5] chore: Reduce impact of fixsetup script --- scripts/fixsetup.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/fixsetup.sh b/scripts/fixsetup.sh index 4be38461..368474f1 100755 --- a/scripts/fixsetup.sh +++ b/scripts/fixsetup.sh @@ -6,9 +6,6 @@ PYTHON_VERSIONS="${PYTHON_VERSIONS-3.7 3.8 3.9 3.10 3.11}" for python_version in ${PYTHON_VERSIONS}; do rm -rf "__pypackages__/${python_version}/lib/mkdocstrings" rm -f "__pypackages__/${python_version}/lib/mkdocstrings.pth" - rm -rf "__pypackages__/${python_version}/lib/mkdocs_autorefs" - rm -f "__pypackages__/${python_version}/lib/mkdocs_autorefs.pth" cp -r ../mkdocstrings/src/mkdocstrings "__pypackages__/${python_version}/lib/" cp -r src/mkdocstrings/* "__pypackages__/${python_version}/lib/mkdocstrings" - cp -r ../mkdocs-autorefs/src/mkdocs_autorefs "__pypackages__/${python_version}/lib/" done From 4cdb2921b3a9292db3ef0663c63f148a4eec3966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 14 Jan 2022 20:31:31 +0100 Subject: [PATCH 3/5] refactor: Use new logger patching utility --- src/mkdocstrings/handlers/python/__init__.py | 4 +++- src/mkdocstrings/handlers/python/collector.py | 11 ++++------- src/mkdocstrings/handlers/python/renderer.py | 3 --- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/mkdocstrings/handlers/python/__init__.py b/src/mkdocstrings/handlers/python/__init__.py index 5d289836..fbcd5ade 100644 --- a/src/mkdocstrings/handlers/python/__init__.py +++ b/src/mkdocstrings/handlers/python/__init__.py @@ -3,13 +3,15 @@ import posixpath from typing import Any, BinaryIO, Iterator, Optional, Tuple +from griffe.logger import patch_loggers + from mkdocstrings.handlers.base import BaseHandler from mkdocstrings.handlers.python.collector import PythonCollector from mkdocstrings.handlers.python.renderer import PythonRenderer from mkdocstrings.inventory import Inventory from mkdocstrings.loggers import get_logger -log = get_logger(__name__) +patch_loggers(get_logger) class PythonHandler(BaseHandler): diff --git a/src/mkdocstrings/handlers/python/collector.py b/src/mkdocstrings/handlers/python/collector.py index ac0b6846..1c2a3fb9 100644 --- a/src/mkdocstrings/handlers/python/collector.py +++ b/src/mkdocstrings/handlers/python/collector.py @@ -5,17 +5,14 @@ from collections import ChainMap -from griffe import logger as griffe_logger +from griffe.agents.extensions import load_extensions +from griffe.collections import LinesCollection, ModulesCollection +from griffe.docstrings.parsers import Parser +from griffe.loader import GriffeLoader from mkdocstrings.handlers.base import BaseCollector, CollectionError, CollectorItem from mkdocstrings.loggers import get_logger -griffe_logger.get_logger = get_logger # patch logger to blend in MkDocs logs -from griffe.agents.extensions import load_extensions # noqa: E402 -from griffe.collections import LinesCollection, ModulesCollection # noqa: E402 -from griffe.docstrings.parsers import Parser # noqa: E402 -from griffe.loader import GriffeLoader # noqa: E402 - logger = get_logger(__name__) diff --git a/src/mkdocstrings/handlers/python/renderer.py b/src/mkdocstrings/handlers/python/renderer.py index 77465398..68cb9d20 100644 --- a/src/mkdocstrings/handlers/python/renderer.py +++ b/src/mkdocstrings/handlers/python/renderer.py @@ -14,9 +14,6 @@ from mkdocstrings.extension import PluginError from mkdocstrings.handlers.base import BaseRenderer, CollectorItem -from mkdocstrings.loggers import get_logger - -log = get_logger(__name__) # TODO: CSS classes everywhere in templates # TODO: name normalization (filenames, Jinja2 variables, HTML tags, CSS classes) From 28061de20094c510f27bb375b2e1dc44a699809d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 14 Jan 2022 20:33:03 +0100 Subject: [PATCH 4/5] feat: Support griffe 0.10 --- src/mkdocstrings/handlers/python/collector.py | 16 +++++++--------- .../python/material/_base/attribute.html | 2 +- .../templates/python/material/_base/class.html | 2 +- .../python/material/_base/docstring.html | 5 +++++ .../python/material/_base/function.html | 2 +- .../templates/python/material/_base/module.html | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/mkdocstrings/handlers/python/collector.py b/src/mkdocstrings/handlers/python/collector.py index 1c2a3fb9..98dfeaff 100644 --- a/src/mkdocstrings/handlers/python/collector.py +++ b/src/mkdocstrings/handlers/python/collector.py @@ -62,17 +62,15 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2 lines_collection=self._lines_collection, ) try: - module = loader.load_module(module_name) - except ModuleNotFoundError as error: - raise CollectionError from error + loader.load_module(module_name) + except ImportError as error: + raise CollectionError(str(error)) from error - for _ in range(5): - if loader.follow_aliases(module): - break - else: - logger.warning("some aliases could not be resolved") + unresolved, iterations = loader.resolve_aliases(only_exported=True, only_known_modules=True) + if unresolved: + logger.warning(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations") try: return self._modules_collection[identifier] except KeyError as error: # noqa: WPS440 - raise CollectionError from error + raise CollectionError(f"{identifier} could not be found") from error diff --git a/src/mkdocstrings/templates/python/material/_base/attribute.html b/src/mkdocstrings/templates/python/material/_base/attribute.html index 4f8da7e7..31066fc8 100644 --- a/src/mkdocstrings/templates/python/material/_base/attribute.html +++ b/src/mkdocstrings/templates/python/material/_base/attribute.html @@ -1,5 +1,5 @@ {{ log.debug() }} -{% if config.show_if_no_docstring or attribute %} +{% if config.show_if_no_docstring or attribute.has_docstrings %}
{% with html_id = attribute.path %} diff --git a/src/mkdocstrings/templates/python/material/_base/class.html b/src/mkdocstrings/templates/python/material/_base/class.html index 37724e17..a5c9c879 100644 --- a/src/mkdocstrings/templates/python/material/_base/class.html +++ b/src/mkdocstrings/templates/python/material/_base/class.html @@ -1,5 +1,5 @@ {{ log.debug() }} -{% if config.show_if_no_docstring or class %} +{% if config.show_if_no_docstring or class.has_docstrings %}
{% with html_id = class.path %} diff --git a/src/mkdocstrings/templates/python/material/_base/docstring.html b/src/mkdocstrings/templates/python/material/_base/docstring.html index bdf60ffa..410e210b 100644 --- a/src/mkdocstrings/templates/python/material/_base/docstring.html +++ b/src/mkdocstrings/templates/python/material/_base/docstring.html @@ -21,6 +21,11 @@ {% include "docstring/returns.html" with context %} {% elif section.kind.value == "examples" %} {% include "docstring/examples.html" with context %} + {% elif section.kind.value == "admonition" %} +
+ {{ section.title|convert_markdown(heading_level, html_id) }} + {{ section.value.contents|convert_markdown(heading_level, html_id) }} +
{% endif %} {% endfor %} {% endif %} diff --git a/src/mkdocstrings/templates/python/material/_base/function.html b/src/mkdocstrings/templates/python/material/_base/function.html index 39f8333e..fa190793 100644 --- a/src/mkdocstrings/templates/python/material/_base/function.html +++ b/src/mkdocstrings/templates/python/material/_base/function.html @@ -1,5 +1,5 @@ {{ log.debug() }} -{% if config.show_if_no_docstring or function %} +{% if config.show_if_no_docstring or function.has_docstrings %}
{% with html_id = function.path %} diff --git a/src/mkdocstrings/templates/python/material/_base/module.html b/src/mkdocstrings/templates/python/material/_base/module.html index ad0cef4f..998f93e8 100644 --- a/src/mkdocstrings/templates/python/material/_base/module.html +++ b/src/mkdocstrings/templates/python/material/_base/module.html @@ -1,5 +1,5 @@ {{ log.debug() }} -{% if config.show_if_no_docstring or module %} +{% if config.show_if_no_docstring or module.has_docstrings %}
{% with html_id = module.path %} From e892f56baab96bf97d5005be76b7a5d80d2f0d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 14 Jan 2022 20:40:08 +0100 Subject: [PATCH 5/5] chore: Prepare release 0.3.0 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b369fcc7..9cb9926c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ 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.3.0](https://github.com/mkdocstrings/python/releases/tag/0.3.0) - 2022-01-14 + +[Compare with 0.2.0](https://github.com/mkdocstrings/python/compare/0.2.0...0.3.0) + +### Features +- Support griffe 0.10 ([28061de](https://github.com/mkdocstrings/python/commit/28061de20094c510f27bb375b2e1dc44a699809d) by Timothée Mazzucotelli). + +### Build +- Require griffe 0.10 ([cfbd7bb](https://github.com/mkdocstrings/python/commit/cfbd7bb4761691ef36100962c775ed1d0a247514) by Timothée Mazzucotelli). + +### Code Refactoring +- Use new logger patching utility ([4cdb292](https://github.com/mkdocstrings/python/commit/4cdb2921b3a9292db3ef0663c63f148a4eec3966) by Timothée Mazzucotelli). + + ## [0.2.0](https://github.com/mkdocstrings/python/releases/tag/0.2.0) - 2021-12-28 [Compare with 0.1.0](https://github.com/mkdocstrings/python/compare/0.1.0...0.2.0)