diff --git a/CHANGELOG.md b/CHANGELOG.md index 20923eb..ffca4a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project are documented in this file and maintained manually. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [Unreleased] + +### Changed + +- `__version__` is read from the installed package metadata (`importlib.metadata`), not hardcoded, + so it can no longer disagree with `pyproject.toml` (a hardcoded one went stale in releases). + ## [0.1.0] - 2026-10-05 ### Added diff --git a/docs/src/content/docs/development/publishing.md b/docs/src/content/docs/development/publishing.md index 257fa4b..131f5e0 100644 --- a/docs/src/content/docs/development/publishing.md +++ b/docs/src/content/docs/development/publishing.md @@ -13,9 +13,9 @@ Enable GitHub Pages once in the repository settings, with "GitHub Actions" as th ## Releases and PyPI -Before merging a release to `main`, update the version in `pyproject.toml`, -`src/app/__init__.py` and `CITATION.cff` (including its release date), and add the release notes -to `CHANGELOG.md`. On every push to `main`, the `Release` workflow: +Before merging a release to `main`, update the version in `pyproject.toml` and `CITATION.cff` +(including its release date), and add the release notes to `CHANGELOG.md`. The package's +`__version__` is read from the installed metadata, so it follows `pyproject.toml`. On every push to `main`, the `Release` workflow: 1. tags the release `vX.Y.Z` and creates the GitHub release, 2. builds the package with `uv build` and publishes it to PyPI with trusted publishing (OIDC), diff --git a/src/app/__init__.py b/src/app/__init__.py index a9c4ac9..192583b 100644 --- a/src/app/__init__.py +++ b/src/app/__init__.py @@ -1,3 +1,8 @@ """Template python package.""" -__version__ = "0.1.0" +from importlib.metadata import PackageNotFoundError, version + +try: + __version__ = version("template-python") +except PackageNotFoundError: # not installed, e.g. run from a source tree + __version__ = "0.0.0+unknown"