From fe2464ee3e58cd6e31bb93ac3dc718cc619daa36 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:18:06 +0300 Subject: [PATCH] Generate __version__ at build to avoid slow importlib.metadata import --- .gitignore | 3 +++ pyproject.toml | 3 +++ src/tinytext/__init__.py | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2dc53ca3..4a1862f2 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/tinytext/_version.py diff --git a/pyproject.toml b/pyproject.toml index 9df898f8..298ec6ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,9 @@ scripts.tinytext = "tinytext.cli:main" [tool.hatch] version.source = "vcs" +[tool.hatch.build.hooks.vcs] +version-file = "src/tinytext/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/tinytext/__init__.py b/src/tinytext/__init__.py index f3fa199e..271ac98d 100644 --- a/src/tinytext/__init__.py +++ b/src/tinytext/__init__.py @@ -1,8 +1,8 @@ from __future__ import annotations -import importlib.metadata +from tinytext import _version # type: ignore[attr-defined] -__version__ = importlib.metadata.version(__name__) +__version__ = _version.__version__ __all__ = ["__version__"]