Skip to content

Commit

Permalink
Generate __version__ at build to avoid slow importlib.metadata im…
Browse files Browse the repository at this point in the history
…port (#142)
  • Loading branch information
hugovk committed Aug 31, 2024
2 parents 4f00a1e + 8ccef3c commit a4d368d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ htmlcov/
nosetests.xml

.python-version

# 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 @@ -57,6 +57,9 @@ scripts.em = "em_keyboard:cli"
[tool.hatch]
version.source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/em_keyboard/_version.py"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

Expand Down
5 changes: 3 additions & 2 deletions src/em_keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from __future__ import annotations

import argparse
import importlib.metadata
import itertools
import json
import os
Expand All @@ -32,7 +31,9 @@
except ImportError:
copier = None

__version__: str = importlib.metadata.version("em_keyboard")
from em_keyboard import _version

__version__ = _version.__version__

try:
from importlib.resources import as_file, files
Expand Down

0 comments on commit a4d368d

Please sign in to comment.