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 10, 2024
1 parent 9be9f71 commit 5844f85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 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
23 changes: 11 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ keywords = [
"rst",
]
license = { text = "MIT" }
authors = [
{ name = "Hugo van Kemenade" },
]
authors = [ { name = "Hugo van Kemenade" } ]
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -35,9 +33,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = [
"version",
]
dynamic = [ "version" ]
dependencies = [
"pyperclip; platform_system=='Darwin'",
"pyperclip; platform_system=='Windows'",
Expand All @@ -55,6 +51,9 @@ scripts.linky = "linkotron.cli:main"
[tool.hatch]
version.source = "vcs"

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

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

Expand All @@ -67,9 +66,11 @@ lint.select = [
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"PYI", # flake8-pyi
"RUF022", # unsorted-dunder-all
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
Expand All @@ -82,12 +83,10 @@ lint.ignore = [
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]
lint.isort.known-first-party = [
"linkotron",
]
lint.isort.required-imports = [
"from __future__ import annotations",
]
lint.flake8-import-conventions.aliases.datetime = "dt"
lint.flake8-import-conventions.banned-from = [ "datetime" ]
lint.isort.known-first-party = [ "linkotron" ]
lint.isort.required-imports = [ "from __future__ import annotations" ]

[tool.pyproject-fmt]
max_supported_python = "3.13"
Expand Down
3 changes: 1 addition & 2 deletions src/linkotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from __future__ import annotations

import importlib.metadata
import re
from typing import Any

__version__ = importlib.metadata.version(__name__)
from ._version import __version__ as __version__


# https://github.com/nedbat/adventofcode2022/blob/main/day07.py
Expand Down

0 comments on commit 5844f85

Please sign in to comment.