From 639d11e6858e3dd0c32c8c35e29fa4f00b26480b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Wed, 17 Aug 2022 22:12:47 +0200 Subject: [PATCH 1/8] docs: Add note about Black formatting for signatures --- src/mkdocstrings_handlers/python/handler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 301f02fc..73247f68 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -106,7 +106,8 @@ class PythonHandler(BaseHandler): annotations_path (str): The verbosity for annotations path: `brief` (recommended), or `source` (as written in the source). Default: `"brief"`. show_signature (bool): Show methods and functions signatures. Default: `True`. show_signature_annotations (bool): Show the type annotations in methods and functions signatures. Default: `False`. - separate_signature (bool): Whether to put the whole signature in a code block below the heading. Default: `False`. + separate_signature (bool): Whether to put the whole signature in a code block below the heading. + If Black is installed, the signature is also formatted using it. Default: `False`. Attributes: Additional options: show_bases (bool): Show the base classes of a class. Default: `True`. From 0cb1630ccb1c2e0290c89daafe0a49461443d27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Wed, 17 Aug 2022 22:14:34 +0200 Subject: [PATCH 2/8] chore: Template upgrade --- .copier-answers.yml | 2 +- pyproject.toml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 97027f2b..d16f80a7 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier -_commit: 0.9.7 +_commit: 0.9.10 _src_path: gh:pawamoy/copier-pdm author_email: pawamoy@pm.me author_fullname: Timothée Mazzucotelli diff --git a/pyproject.toml b/pyproject.toml index 409a40be..05550314 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,10 @@ Gitter = "https://gitter.im/python/community" Funding = "https://github.com/sponsors/mkdocstrings" [tool.pdm] -version = {use_scm = true} +version = {source = "scm"} + +[tool.pdm.build] +package-dir = "src" includes = ["src/mkdocstrings_handlers"] editable-backend = "editables" From 29edd02e7a4d83f6b7e8555d4d5b03a79882eb07 Mon Sep 17 00:00:00 2001 From: Andrew Guenther Date: Fri, 23 Sep 2022 11:32:45 -0700 Subject: [PATCH 3/8] feat: Add support for globs in paths configuration This change allows for values in the paths configuration option to be globs by resolving them before passing them off to Griffe. Issue #33: https://github.com/mkdocstrings/python/issues/33 PR #34: https://github.com/mkdocstrings/python/pull/34 --- src/mkdocstrings_handlers/python/handler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 73247f68..bb731154 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -2,6 +2,7 @@ from __future__ import annotations +import glob import os import posixpath import re @@ -128,6 +129,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] + 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)) search_paths = [path for path in sys.path if path] # eliminate empty path From 32030df6a98b527a3f5167e1836a36efae6530d4 Mon Sep 17 00:00:00 2001 From: Nazia Povey Date: Fri, 23 Sep 2022 14:34:17 -0400 Subject: [PATCH 4/8] docs: Fix edit page link to python files for reference pages We need to provide a relative path to go up out of the docs dir. See https://github.com/mkdocstrings/mkdocstrings/pull/443. Co-authored-by: Hashem Nasarat --- docs/gen_ref_nav.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gen_ref_nav.py b/docs/gen_ref_nav.py index 1b9fbda1..14f0f4ad 100755 --- a/docs/gen_ref_nav.py +++ b/docs/gen_ref_nav.py @@ -26,7 +26,7 @@ ident = ".".join(parts) fd.write(f"::: {ident}") - mkdocs_gen_files.set_edit_path(full_doc_path, path) + mkdocs_gen_files.set_edit_path(full_doc_path, ".." / path) with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file: nav_file.writelines(nav.build_literate_nav()) From 4de70245341bef8182663d6e8717caf6868fcac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 13 Nov 2022 17:53:06 +0100 Subject: [PATCH 5/8] chore: Template upgrade --- .copier-answers.yml | 2 +- .github/workflows/ci.yml | 38 ++++-------------------- duties.py | 62 +++++++++------------------------------- pyproject.toml | 8 ++++-- scripts/gen_credits.py | 2 +- 5 files changed, 27 insertions(+), 85 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index d16f80a7..8cacdedb 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier -_commit: 0.9.10 +_commit: 0.10.6 _src_path: gh:pawamoy/copier-pdm author_email: pawamoy@pm.me author_fullname: Timothée Mazzucotelli diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 201e8d52..287efc83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,27 +25,13 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up PDM - uses: pdm-project/setup-pdm@v2.6 + uses: pdm-project/setup-pdm@v3 with: python-version: "3.8" - - name: Set cache variables - id: set_variables - run: | - echo "::set-output name=PIP_CACHE::$(pip cache dir)" - echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)" - - - name: Set up cache - uses: actions/cache@v2 - with: - path: | - ${{ steps.set_variables.outputs.PIP_CACHE }} - ${{ steps.set_variables.outputs.PDM_CACHE }} - key: checks-cache - - name: Resolving dependencies run: pdm lock @@ -77,33 +63,19 @@ jobs: - "3.8" - "3.9" - "3.10" - - "3.11-dev" + - "3.11" runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up PDM - uses: pdm-project/setup-pdm@v2.6 + uses: pdm-project/setup-pdm@v3 with: python-version: ${{ matrix.python-version }} - - name: Set cache variables - id: set_variables - run: | - echo "::set-output name=PIP_CACHE::$(pip cache dir)" - echo "::set-output name=PDM_CACHE::$(pdm config cache_dir)" - - - name: Set up cache - uses: actions/cache@v2 - with: - path: | - ${{ steps.set_variables.outputs.PIP_CACHE }} - ${{ steps.set_variables.outputs.PDM_CACHE }} - key: tests-cache-${{ runner.os }}-${{ matrix.python-version }} - - name: Install dependencies run: pdm install --no-editable -G duty -G tests diff --git a/duties.py b/duties.py index 3ad804dd..7dd2fb15 100644 --- a/duties.py +++ b/duties.py @@ -4,8 +4,6 @@ import os import re import sys -import tempfile -from contextlib import suppress from io import StringIO from pathlib import Path from typing import List, Optional, Pattern @@ -145,7 +143,8 @@ def check_dependencies(ctx): importlib.invalidate_caches() # reload original, unpatched safety - from safety.formatter import report + from safety.formatter import SafetyFormatter + from safety.safety import calculate_remediations from safety.safety import check as safety_check from safety.util import read_requirements @@ -159,10 +158,19 @@ def check_dependencies(ctx): # check using safety as a library def safety(): # noqa: WPS430 packages = list(read_requirements(StringIO(requirements))) - vulns = safety_check(packages=packages, ignore_ids="", key="", db_mirror="", cached=False, proxy={}) - output_report = report(vulns=vulns, full=True, checked_packages=len(packages)) + vulns, db_full = safety_check(packages=packages, ignore_vulns="") + remediations = calculate_remediations(vulns, db_full) + output_report = SafetyFormatter("text").render_vulnerabilities( + announcements=[], + vulnerabilities=vulns, + remediations=remediations, + full=True, + packages=packages, + ) if vulns: print(output_report) + return False + return True ctx.run(safety, title="Checking dependencies") @@ -188,49 +196,7 @@ def check_types(ctx): # noqa: WPS231 Arguments: ctx: The context instance (passed automatically). """ - # NOTE: the following code works around this issue: - # https://github.com/python/mypy/issues/10633 - - # compute packages directory path - py = f"{sys.version_info.major}.{sys.version_info.minor}" - pkgs_dir = Path("__pypackages__", py, "lib").resolve() - - # build the list of available packages - packages = {} - for package in pkgs_dir.glob("*"): - if package.suffix not in {".dist-info", ".pth"} and package.name != "__pycache__": - packages[package.name] = package - - # handle .pth files - for pth in pkgs_dir.glob("*.pth"): - with suppress(OSError): - for package in Path(pth.read_text().splitlines()[0]).glob("*"): # noqa: WPS440 - if package.suffix != ".dist-info": - packages[package.name] = package - - # create a temporary directory to assign to MYPYPATH - with tempfile.TemporaryDirectory() as tmpdir: - - # symlink the stubs - ignore = set() - for stubs in (path for name, path in packages.items() if name.endswith("-stubs")): # noqa: WPS335 - Path(tmpdir, stubs.name).symlink_to(stubs, target_is_directory=True) - # try to symlink the corresponding package - # see https://www.python.org/dev/peps/pep-0561/#stub-only-packages - pkg_name = stubs.name.replace("-stubs", "") - if pkg_name in packages: - ignore.add(pkg_name) - Path(tmpdir, pkg_name).symlink_to(packages[pkg_name], target_is_directory=True) - - # create temporary mypy config to ignore stubbed packages - newconfig = Path("config", "mypy.ini").read_text() - newconfig += "\n" + "\n\n".join(f"[mypy-{pkg}.*]\nignore_errors=true" for pkg in ignore) - tmpconfig = Path(tmpdir, "mypy.ini") - tmpconfig.write_text(newconfig) - - # set MYPYPATH and run mypy - os.environ["MYPYPATH"] = tmpdir - ctx.run(f"mypy --config-file {tmpconfig} {PY_SRC}", title="Type-checking", pty=PTY) + ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY) @duty(silent=True) diff --git a/pyproject.toml b/pyproject.toml index 05550314..b48e9481 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "pdm.pep517.api" name = "mkdocstrings-python" description = "A Python handler for mkdocstrings." authors = [{name = "Timothée Mazzucotelli", email = "pawamoy@pm.me"}] -license-expression = "ISC" +license = "ISC" readme = "README.md" requires-python = ">=3.7" keywords = [] @@ -73,6 +73,10 @@ maintain = [ "git-changelog>=0.4", ] quality = [ + # TODO: remove once importlib-metadata version conflict is resolved + "importlib-metadata<5; python_version < '3.8'", + "flake8>=4; python_version >= '3.8'", + "darglint>=1.8", "flake8-bandit>=2.1", "flake8-black>=0.2", @@ -98,7 +102,7 @@ typing = [ "types-markdown>=3.3", "types-toml>=0.10", ] -security = ["safety>=1.10"] +security = ["safety>=2"] [tool.black] line-length = 120 diff --git a/scripts/gen_credits.py b/scripts/gen_credits.py index a21a1e4a..10f5647d 100644 --- a/scripts/gen_credits.py +++ b/scripts/gen_credits.py @@ -58,7 +58,7 @@ def get_deps(base_deps): if dep_name not in deps: deps[dep_name] = {"license": get_license(dep_name), **parsed, **lock_pkgs[dep_name]} again = True - + return deps dev_dependencies = get_deps(chain(*pdm.get("dev-dependencies", {}).values())) From 12cd342fbef210f09b1d33c72f5db80a6b1562f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 13 Nov 2022 18:29:11 +0100 Subject: [PATCH 6/8] ci: Fix type checking --- config/mypy.ini | 2 ++ duties.py | 1 + tests/conftest.py | 13 +------------ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/config/mypy.ini b/config/mypy.ini index 814e2ac8..cb0dd886 100644 --- a/config/mypy.ini +++ b/config/mypy.ini @@ -3,3 +3,5 @@ ignore_missing_imports = true exclude = tests/fixtures/ warn_unused_ignores = true show_error_codes = true +namespace_packages = true +explicit_package_bases = true diff --git a/duties.py b/duties.py index 7dd2fb15..1b64bcda 100644 --- a/duties.py +++ b/duties.py @@ -196,6 +196,7 @@ def check_types(ctx): # noqa: WPS231 Arguments: ctx: The context instance (passed automatically). """ + os.environ["MYPYPATH"] = "src" ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY) diff --git a/tests/conftest.py b/tests/conftest.py index 6e7766b1..ce71a665 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,18 +7,7 @@ import pytest from markdown.core import Markdown from mkdocs import config - -try: - from mkdocs.config.defaults import get_schema -except ImportError: - - def get_schema() -> tuple[tuple]: # noqa: WPS440 - """Fallback for old versions of MkDocs. - - Returns: - The default schema. - """ - return config.DEFAULT_SCHEMA +from mkdocs.config.defaults import get_schema @pytest.fixture(name="mkdocs_conf") From 3b9f7013a7367f18e4354c37f029f9caf3ad0a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 13 Nov 2022 18:29:37 +0100 Subject: [PATCH 7/8] refactor: Support Griffe 0.24 --- pyproject.toml | 2 +- src/mkdocstrings_handlers/python/handler.py | 2 +- .../python/templates/material/_base/signature.html | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b48e9481..914bd58b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ ] dependencies = [ "mkdocstrings>=0.19", - "griffe>=0.11.1", + "griffe>=0.24", ] [project.urls] diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index bb731154..0288afa5 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -196,7 +196,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102 except ImportError as error: raise CollectionError(str(error)) from error - unresolved, iterations = loader.resolve_aliases(only_exported=True, only_known_modules=True) + unresolved, iterations = loader.resolve_aliases(implicit=False, external=False) if unresolved: logger.warning(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations") diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html index d571c73e..bc24ea35 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html @@ -35,6 +35,7 @@ {%- set ns.render_kw_only_separator = False -%} {%- endif -%} + {% if parameter.kind.value == "variadic positional" %}*{% elif parameter.kind.value == "variadic keyword" %}**{% endif -%} {{ parameter.name }}{{ annotation }}{{ default }} {%- if not loop.last %}, {% endif -%} From c4d32e185bb74682f4583db1e24b8a583441e2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 13 Nov 2022 18:30:35 +0100 Subject: [PATCH 8/8] chore: Prepare release 0.8.0 --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 379d6671..b7389238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ 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.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) + +### Features +- Add support for globs in paths configuration ([29edd02](https://github.com/mkdocstrings/python/commit/29edd02e7a4d83f6b7e8555d4d5b03a79882eb07) by Andrew Guenther). [Issue #33](https://github.com/mkdocstrings/python/issues/33), [PR #34](https://github.com/mkdocstrings/python/pull/34) + +### Code Refactoring +- Support Griffe 0.24 ([3b9f701](https://github.com/mkdocstrings/python/commit/3b9f7013a7367f18e4354c37f029f9caf3ad0a4e) by Timothée Mazzucotelli). + + ## [0.7.1](https://github.com/mkdocstrings/python/releases/tag/0.7.1) - 2022-06-12 [Compare with 0.7.0](https://github.com/mkdocstrings/python/compare/0.7.0...0.7.1)