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 Aug 31, 2024
1 parent 2d88580 commit ef8c7f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 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 @@ -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"

Expand Down
5 changes: 2 additions & 3 deletions src/pepotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ef8c7f8

Please sign in to comment.