From 106239bcf1c224e70a048f9989c5a4d491e47dff Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:31:19 +0300 Subject: [PATCH 1/2] Generate __version__ at build to avoid slow importlib.metadata import --- .gitignore | 3 +++ pyproject.toml | 3 +++ src/pypistats/__init__.py | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 614bc494..afe52d07 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,6 @@ venv.bak/ .mypy_cache/ .dmypy.json dmypy.json + +# hatch-vcs +src/pypistats/_version.py diff --git a/pyproject.toml b/pyproject.toml index 02df183d..fdf7f5ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,9 @@ scripts.pypistats = "pypistats.cli:main" [tool.hatch] version.source = "vcs" +[tool.hatch.build.hooks.vcs] +version-file = "src/pypistats/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/pypistats/__init__.py b/src/pypistats/__init__.py index db31394b..ee5f7ad9 100644 --- a/src/pypistats/__init__.py +++ b/src/pypistats/__init__.py @@ -7,7 +7,6 @@ import atexit import datetime as dt -import importlib.metadata import json import sys import warnings @@ -17,7 +16,9 @@ from slugify import slugify from termcolor import colored -__version__ = importlib.metadata.version(__name__) +from . import _version + +__version__ = _version.__version__ BASE_URL = "https://pypistats.org/api/" CACHE_DIR = Path(user_cache_dir("pypistats")) From 920596dd9f580d6311149e0571eaf87410db4cba Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:33:52 +0300 Subject: [PATCH 2/2] Update config --- .github/workflows/deploy.yml | 3 +++ pyproject.toml | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5d3589ca..d5abdb8c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,9 @@ on: permissions: contents: read +env: + FORCE_COLOR: 1 + jobs: # Always build & lint package. build-package: diff --git a/pyproject.toml b/pyproject.toml index fdf7f5ac..f428fe3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,20 +84,27 @@ lint.select = [ "EM", # flake8-errmsg "F", # pyflakes errors "I", # isort + "ICN", # flake8-import-conventions "ISC", # flake8-implicit-str-concat "LOG", # flake8-logging "PGH", # pygrep-hooks + "PYI", # flake8-pyi + "RUF022", # unsorted-dunder-all "RUF100", # unused noqa (yesqa) "UP", # pyupgrade "W", # pycodestyle warnings "YTT", # flake8-2020 ] -lint.extend-ignore = [ +lint.ignore = [ "E203", # Whitespace before ':' "E221", # Multiple spaces before operator "E226", # Missing whitespace around arithmetic operator "E241", # Multiple spaces after ',' ] +lint.flake8-import-conventions.aliases.datetime = "dt" +lint.flake8-import-conventions.banned-from = [ + "datetime", +] lint.isort.known-first-party = [ "pypistats", ]