Skip to content

Commit 3ed0110

Browse files
committed
refactor: stop reading VERSION.txt to set the version attribute
1 parent 874a23e commit 3ed0110

File tree

6 files changed

+6
-28
lines changed

6 files changed

+6
-28
lines changed

changelog.d/+26b364b2.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stop reading `VERSION.txt` to set the version attribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/VERSION.txt

template/src/{{ package_name }}/__init__.py.jinja

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
from __future__ import annotations
44

55
__all__ = ("__version__",)
6-
{% if dynamic_version %}
7-
from .__version__ import __version__
8-
{%- else %}
6+
97
import importlib.metadata
108

119
__version__ = importlib.metadata.version("{{ distribution_name }}")
12-
{%- endif %}

template/src/{{ package_name }}/{% if dynamic_version %}.{% endif %}/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

template/src/{{ package_name }}/{% if dynamic_version %}.{% endif %}/__version__.py.jinja

Lines changed: 0 additions & 21 deletions
This file was deleted.

template/tests/{% if dynamic_version %}test_version.py{% endif %}.jinja

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from __future__ import annotations
44

5-
import importlib.metadata
5+
import importlib.resources
66

77
from {{ package_name }} import __version__
88

99

1010
# https://packaging.python.org/discussions/single-source-version/#single-sourcing-the-project-version
1111
def test_version() -> None:
1212
"""Test that the version attribute matches the package version."""
13-
version = importlib.metadata.version("{{ distribution_name }}")
13+
version_path = importlib.resources.files("{{ package_name }}")
14+
version = version_path.read_text().rstrip()
1415
assert __version__ == version

0 commit comments

Comments
 (0)