From ef8c7f8464e606976776cde440251eb5ddece369 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 31 Aug 2024 23:58:13 +0300 Subject: [PATCH 1/5] Generate __version__ at build to avoid slow importlib.metadata import --- .gitignore | 3 +++ pyproject.toml | 3 +++ src/pepotron/__init__.py | 5 ++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2dc53ca..efe4d34 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +# hatch-vcs +src/*/_version.py diff --git a/pyproject.toml b/pyproject.toml index 5cd99c2..604072e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,9 @@ scripts.pep = "pepotron.cli:main" [tool.hatch] version.source = "vcs" +[tool.hatch.build.hooks.vcs] +version-file = "src/pepotron/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/pepotron/__init__.py b/src/pepotron/__init__.py index a026683..93678f4 100644 --- a/src/pepotron/__init__.py +++ b/src/pepotron/__init__.py @@ -4,14 +4,13 @@ from __future__ import annotations -import importlib.metadata import logging from pathlib import Path from typing import Any -from . import _cache +from . import _cache, _version -__version__ = importlib.metadata.version(__name__) +__version__ = _version.__version__ BASE_URL = "https://peps.python.org" JSON_PATH = "/api/peps.json" From 4e19143cd4297d71e78fc96547c29597fbbc3229 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:02:31 +0300 Subject: [PATCH 2/5] Move mypy from pre-commit to tox --- .github/workflows/lint.yml | 9 +++++++++ .pre-commit-config.yaml | 8 -------- tox.ini | 12 ++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 88c0c7c..dd1dbbf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,7 @@ on: [push, pull_request, workflow_dispatch] env: FORCE_COLOR: 1 + PIP_DISABLE_PIP_VERSION_CHECK: 1 permissions: contents: read @@ -17,4 +18,12 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.x" + cache: pip - uses: pre-commit/action@v3.0.1 + + - name: Install dependencies + run: | + python3 -m pip install -U tox + + - name: Mypy + run: tox -e mypy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2e564f7..0ff6293 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,14 +35,6 @@ repos: hooks: - id: actionlint - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 - hooks: - - id: mypy - args: [--strict, --pretty, --show-error-codes] - additional_dependencies: - [platformdirs, pytest, python-slugify, rapidfuzz, types-freezegun, urllib3] - - repo: https://github.com/tox-dev/pyproject-fmt rev: 2.2.1 hooks: diff --git a/tox.ini b/tox.ini index 5334ace..1f22eb3 100644 --- a/tox.ini +++ b/tox.ini @@ -41,3 +41,15 @@ pass_env = PRE_COMMIT_COLOR commands = pre-commit run --all-files --show-diff-on-failure + +[testenv:mypy] +deps = + mypy==1.11.2 + platformdirs + pytest + python-slugify + rapidfuzz + types-freezegun + urllib3 +commands = + mypy --strict --pretty --show-error-codes . {posargs} From e1c242f6552f280e340a37f346a577cc2a24d698 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:16:21 +0300 Subject: [PATCH 3/5] Python 3.8 and 3.9 are now available on macos-14 aka macos-latest --- .github/workflows/test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb15489..eded593 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,17 +11,12 @@ env: jobs: test: - runs-on: "${{ matrix.os }}-${{ matrix.os-version || 'latest' }}" + runs-on: "${{ matrix.os }}-latest" strategy: fail-fast: false matrix: python-version: ["pypy3.10", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] os: [Windows, macOS, Ubuntu] - # Python 3.8 and 3.9 are on macos-13 but not macos-latest (macos-14-arm64) - # https://github.com/actions/setup-python/issues/696#issuecomment-1637587760 - include: - - { python-version: "3.8", os: "macOS", os-version: "13" } - - { python-version: "3.9", os: "macOS", os-version: "13" } steps: - uses: actions/checkout@v4 From 22727f3985c8e1b95381b133c0211b87a96b1710 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:23:55 +0300 Subject: [PATCH 4/5] ghapi: import-not-found -> import-untyped --- src/pepotron/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pepotron/__init__.py b/src/pepotron/__init__.py index 93678f4..21ddb29 100644 --- a/src/pepotron/__init__.py +++ b/src/pepotron/__init__.py @@ -119,7 +119,7 @@ def pairwise(iterable): # type: ignore[no-redef,no-untyped-def] def _get_github_prs() -> list[Any]: - from ghapi.all import GhApi # type: ignore[import-not-found] + from ghapi.all import GhApi # type: ignore[import-untyped] api = GhApi(owner="python", repo="peps", authenticate=False) return api.pulls.list(per_page=100) # type: ignore[no-any-return] From 9a38142708b11bfbfbe54259e94eeb8ee685ee8a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:26:12 +0300 Subject: [PATCH 5/5] tox+mypy in own job --- .github/workflows/lint.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dd1dbbf..9ec1f20 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,9 +21,17 @@ jobs: cache: pip - uses: pre-commit/action@v3.0.1 + mypy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + cache: pip - name: Install dependencies run: | python3 -m pip install -U tox - - name: Mypy run: tox -e mypy