From 9250ac866239d6b4392dbf9d4240d35c3271a3ef 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] 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"