Skip to content

Commit 01f6bf5

Browse files
committed
feat: implement dynamic versioning with setuptools_scm
1 parent 87ee129 commit 01f6bf5

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,4 @@ bandit_report.csv
144144
tests/fixtures/http-test-local/qdt-files.json
145145
docs/reference/rules_context.json
146146
safety_report.html
147+
qgis_deployment_toolbelt/_version.py

docs/development/releasing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
1. In `Choose a tag`, enter the new tag (obviously complying with [SemVer](https://semver.org/))
66
1. Click on `Generate release notes`
77
1. Copy/paste the generated text from `## What's changed` until the line before `**Full changelog**:...` in the CHANGELOG.md replacing `What's changed` with the tag and the publication date
8-
1. Change the version number in `__about__.py`
98
1. Commit changes with a message like `release: bump version to X.x.x` to the main branch
109
1. Apply a git tag with the relevant version: `git tag -a 0.3.0 {git commit hash} -m "New awesome feature"`
1110
1. Push commit and tag to main branch: `git push --tags`

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ norecursedirs = ".* build dev development dist docs CVS fixtures _darcs {arch} *
161161
python_files = "test_*.py"
162162
testpaths = ["tests"]
163163

164+
[tool.setuptools_scm]
165+
write_to = "qgis_deployment_toolbelt/_version.py"
164166

165167
[tool.setuptools.dynamic]
166-
version = { attr = "qgis_deployment_toolbelt.__about__.__version__" }
168+
version = { attr = "qgis_deployment_toolbelt._version.version" }
167169

168170
[tool.setuptools.package-data]
169171
qgis_deployment_toolbelt = ["shortcuts/*.template"]

qgis_deployment_toolbelt/__about__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@
4040
__uri_tracker__ = f"{__uri_repository__}issues/"
4141
__uri__ = __uri_repository__
4242

43-
__version__ = "0.38.0"
44-
__version_info__ = tuple(
45-
[
46-
int(num) if num.isdigit() else num
47-
for num in __version__.replace("-", ".", 1).split(".")
48-
]
49-
)
43+
try:
44+
from ._version import version as __version__
45+
except ImportError:
46+
try:
47+
# Fallback for development versions or when package is not installed
48+
from importlib.metadata import version
49+
50+
__version__ = version("qgis-deployment-toolbelt")
51+
except ImportError:
52+
# Final fallback
53+
__version__ = "0.0.0+unknown"

tests/test_about.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def test_metadata_types(self):
4646
self.assertIsInstance(__about__.__uri_tracker__, str)
4747
self.assertIsInstance(__about__.__uri__, str)
4848
self.assertIsInstance(__about__.__version__, str)
49-
self.assertIsInstance(__about__.__version_info__, tuple)
5049

5150
# misc
5251
self.assertLessEqual(len(__about__.__title_clean__), len(__about__.__title__))

0 commit comments

Comments
 (0)