Skip to content

Commit

Permalink
Generate __version__ at build to avoid slow importlib.metadata import
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 9, 2024
1 parent e1d862f commit 6fe2efe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 1 addition & 4 deletions src/humanize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -24,8 +22,7 @@
precisedelta,
)

__version__ = importlib.metadata.version(__name__)

from ._version import __version__

__all__ = [
"__version__",
Expand Down

0 comments on commit 6fe2efe

Please sign in to comment.