Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate __version__ at build to avoid slow importlib.metadata #68

Merged
merged 5 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1
PIP_DISABLE_PIP_VERSION_CHECK: 1

permissions:
contents: read
Expand All @@ -17,4 +18,20 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: pip
- uses: pre-commit/[email protected]

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
7 changes: 1 addition & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 3 additions & 4 deletions src/pepotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -120,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]
Expand Down
12 changes: 12 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Loading