From 766020af592aa1f905a8a9d00a6becacc6aa4270 Mon Sep 17 00:00:00 2001 From: Patrick Kidger <33688385+patrick-kidger@users.noreply.github.com> Date: Wed, 14 Jun 2023 13:23:50 -0700 Subject: [PATCH] Switched to pyproject; support collections.abc types --- .flake8 | 4 --- .github/FUNDING.yml | 1 + .github/workflows/release.yml | 23 +++++++++++++ .isort.cfg | 6 ---- .pre-commit-config.yaml | 14 ++++---- MANIFEST.in | 1 - pyproject.toml | 43 +++++++++++++++++++++++ pytkdocs_tweaks/__init__.py | 14 ++++++-- setup.py | 64 ----------------------------------- 9 files changed, 86 insertions(+), 84 deletions(-) delete mode 100644 .flake8 create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .isort.cfg delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 76ba422..0000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 88 -ignore = W291,W503,W504,E121,E123,E126,E203,E402,E701,E702,E731 -per-file-ignores = __init__.py: F401 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..aa6159b --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [patrick-kidger] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f30ba81 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,23 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Release + uses: patrick-kidger/action_update_python_project@v2 + with: + python-version: "3.11" + test-script: "" + pypi-token: ${{ secrets.pypi_token }} + github-user: patrick-kidger + github-token: ${{ github.token }} + email-user: ${{ secrets.email_user }} + email-token: ${{ secrets.email_token }} + email-server: ${{ secrets.email_server }} + email-target: ${{ secrets.email_target }} diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 3ab2ac2..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -force_alphabetical_sort_within_sections=true -lines_after_imports=2 -profile=black -treat_comments_as_code=true -default_section=FIRSTPARTY diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35d7d54..a86bbd3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,11 +3,13 @@ repos: rev: 22.3.0 hooks: - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.255' hooks: - - id: isort - - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + - id: ruff + args: ["--fix"] + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.314 hooks: - - id: flake8 + - id: pyright + additional_dependencies: ["pytkdocs==0.15.0"] diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 1aba38f..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include LICENSE diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4f1cc84 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[project] +name = "pytkdocs_tweaks" +version = "0.0.7" +description = "Some custom tweaks to the results produced by pytkdocs (part of mkdocstrings)." +readme = "README.md" +requires-python ="~=3.8" +license = {file = "LICENSE"} +authors = [ + {name = "Patrick Kidger", email = "contact@kidger.site"}, +] +keywords = ["documentation", "mkdocs", "mkdocs-material", "mkdocstrings"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Natural Language :: English", + "Programming Language :: Python :: 3", +] +urls = {repository = "https://github.com/patrick-kidger/pytkdocs_tweaks" } +dependencies = ["pytkdocs>=0.15.0"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build] +include = ["pytkdocs_tweaks/*"] + +[tool.ruff] +select = ["E", "F", "I001"] +ignore = ["E402", "E721", "E731", "E741", "F722"] +ignore-init-module-imports = true +fixable = ["I001", "F401"] + +[tool.ruff.isort] +combine-as-imports = true +lines-after-imports = 2 +extra-standard-library = ["typing_extensions"] +order-by-type = false + +[tool.pyright] +reportIncompatibleMethodOverride = true +include = ["pytkdocs_tweaks"] diff --git a/pytkdocs_tweaks/__init__.py b/pytkdocs_tweaks/__init__.py index 8558dea..169b1e6 100644 --- a/pytkdocs_tweaks/__init__.py +++ b/pytkdocs_tweaks/__init__.py @@ -3,7 +3,6 @@ import inspect import json import pathlib -import sys import traceback import typing import warnings @@ -89,11 +88,17 @@ def _postprocess(data, cache, bases): parameter["annotation"] = parameter["annotation"].replace( p, p.rsplit(".", 1)[1] ) + parameter["annotation"] = parameter["annotation"].replace( + "collections.abc.", "" + ) if "return_annotation" in signature: for p in cache: signature["return_annotation"] = signature["return_annotation"].replace( p, p.rsplit(".", 1)[1] ) + signature["return_annotation"] = signature["return_annotation"].replace( + "collections.abc.", "" + ) if "bases" in data: # Find those base classes which are part of our public documentation. @@ -155,6 +160,7 @@ def _postprocess(data, cache, bases): if isinstance(_base_obj, property): # Property objects don't inherit module or qualname _base_obj = _base_obj.fget + assert _base_obj is not None _base_path = _base_obj.__module__ + "." + _base_obj.__qualname__ _base_config = {"objects": [{"path": _base_path}]} _base_result = pytkdocs.cli.process_config(_base_config) @@ -250,8 +256,10 @@ def serialize_signature_parameter(parameter): # By default pytkdocs has some really weird behaviour in which the docstring for # inherited magic methods are removed. This removes that behaviour. - pytkdocs.loader.RE_SPECIAL = argparse.Namespace(match=lambda _: False) + pytkdocs.loader.RE_SPECIAL = argparse.Namespace( # pyright: ignore + match=lambda _: False + ) # Set a flag to say we're generating documentation, which the library can use to # customise how its types are displayed. - typing.GENERATING_DOCUMENTATION = True + typing.GENERATING_DOCUMENTATION = True # pyright: ignore diff --git a/setup.py b/setup.py deleted file mode 100644 index 51b8bb6..0000000 --- a/setup.py +++ /dev/null @@ -1,64 +0,0 @@ -import pathlib -import re - -import setuptools - - -_here = pathlib.Path(__file__).resolve().parent - -name = "pytkdocs_tweaks" - -# for simplicity we actually store the version in the __version__ attribute in the -# source -with open(_here / name / "__init__.py") as f: - meta_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M) - if meta_match: - version = meta_match.group(1) - else: - raise RuntimeError("Unable to find __version__ string.") - -author = "Patrick Kidger" - -author_email = "contact@kidger.site" - -description = ( - "Some custom tweaks to the results produced by pytkdocs (part of mkdocstrings)." -) - -with open(_here / "README.md", "r") as f: - readme = f.read() - -url = "https://github.com/patrick-kidger/" + name - -license = "Apache-2.0" - -classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Natural Language :: English", - "Programming Language :: Python :: 3", -] - -python_requires = "~=3.8" - -install_requires = ["pytkdocs>=0.15.0"] - -setuptools.setup( - name=name, - version=version, - author=author, - author_email=author_email, - maintainer=author, - maintainer_email=author_email, - description=description, - long_description=readme, - long_description_content_type="text/markdown", - url=url, - license=license, - classifiers=classifiers, - zip_safe=False, - python_requires=python_requires, - install_requires=install_requires, - packages=[name], -)