From e1d862f78904bcd4d949ac0d1dce4124051197e8 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:08:57 +0300 Subject: [PATCH 1/2] Move mypy from pre-commit to tox --- .github/workflows/lint.yml | 9 +++++++++ .pre-commit-config.yaml | 8 -------- pyproject.toml | 5 +++++ tox.ini | 10 ++++++++++ 4 files changed, 24 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 92c57c3..97e6c50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,14 +36,6 @@ repos: hooks: - id: actionlint - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 - hooks: - - id: mypy - additional_dependencies: [pytest, types-freezegun, types-setuptools] - args: [--strict, --pretty, --show-error-codes, .] - pass_filenames: false - - repo: https://github.com/tox-dev/pyproject-fmt rev: 2.2.3 hooks: diff --git a/pyproject.toml b/pyproject.toml index cb46e8b..d6e9aa3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,3 +105,8 @@ filterwarnings = [ "ignore:sys.monitoring isn't available, using default core:coverage.exceptions.CoverageWarning", ] testpaths = [ "tests" ] + +[tool.mypy] +pretty = true +strict = true +show_error_codes = true diff --git a/tox.ini b/tox.ini index e77bc92..cbdca49 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ requires = env_list = docs lint + mypy py{py3, 313, 312, 311, 310, 39, 38} [testenv] @@ -37,5 +38,14 @@ pass_env = commands = pre-commit run --all-files --show-diff-on-failure +[testenv:mypy] +deps = + mypy==1.11.2 + pytest + types-freezegun + types-setuptools +commands = + mypy --strict --pretty --show-error-codes . {posargs} + [pytest] addopts = --color=yes --doctest-modules From 6fe2efe5297d0ee8279e45266c8d88c1e252ecbc Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:13:23 +0300 Subject: [PATCH 2/2] Generate __version__ at build to avoid slow importlib.metadata import --- .gitignore | 3 +++ pyproject.toml | 3 +++ src/humanize/__init__.py | 5 +---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 68bc17f..bddede8 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 d6e9aa3..d670783 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,9 @@ version.source = "vcs" [tool.hatch.build] artifacts = [ "*.mo" ] +[tool.hatch.build.hooks.vcs] +version-file = "src/humanize/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/humanize/__init__.py b/src/humanize/__init__.py index 19c7c91..60390e2 100644 --- a/src/humanize/__init__.py +++ b/src/humanize/__init__.py @@ -2,8 +2,6 @@ from __future__ import annotations -import importlib.metadata - from humanize.filesize import naturalsize from humanize.i18n import activate, deactivate, decimal_separator, thousands_separator from humanize.number import ( @@ -24,8 +22,7 @@ precisedelta, ) -__version__ = importlib.metadata.version(__name__) - +from ._version import __version__ __all__ = [ "__version__",