Skip to content

Commit 2522acf

Browse files
tonybaloneyCopilot
andauthored
Single-source versioning: derive Python version from Cargo.toml (#255)
Replace the hardcoded __version__ in __init__.py with importlib.metadata.version('wily'). Maturin already derives the Python package version from backend/Cargo.toml, so Cargo.toml is now the single source of truth for the version number. - src/wily/__init__.py: Use importlib.metadata instead of hardcoded string - backend/Cargo.toml: Sync version to 2.0.0-alpha.2 - release.toml: Add cargo-release config for local version bumps - CONTRIBUTING.md: Document release process using cargo-release Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9998058 commit 2522acf

4 files changed

Lines changed: 68 additions & 5 deletions

File tree

CONTRIBUTING.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,59 @@ Please note we have a code of conduct, please follow it in all your interactions
1111
build.
1212
2. Update the README.md with details of changes to the interface, this includes new environment
1313
variables, exposed ports, useful file locations and container parameters.
14-
3. Increase the version numbers in any examples files and the README.md to the new version that this
15-
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
16-
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
14+
3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
1715
do not have permission to do that, you may request the second reviewer to merge it for you.
1816

17+
## Development Setup
18+
19+
```console
20+
$ uv sync --all-groups
21+
$ maturin develop
22+
```
23+
24+
## Releasing a New Version
25+
26+
The version is defined in a single place: `backend/Cargo.toml`. The Python package version is derived automatically via maturin at build time and read at runtime using `importlib.metadata`.
27+
28+
### Prerequisites
29+
30+
Install [cargo-release](https://github.com/crate-ci/cargo-release):
31+
32+
```console
33+
$ cargo install cargo-release
34+
```
35+
36+
### Cutting a release
37+
38+
1. **Bump the version** using `cargo-release`:
39+
40+
```console
41+
# For a patch release (e.g., 2.0.1 -> 2.0.2):
42+
$ cargo release patch --manifest-path backend/Cargo.toml --execute
43+
44+
# For a minor release (e.g., 2.0.x -> 2.1.0):
45+
$ cargo release minor --manifest-path backend/Cargo.toml --execute
46+
47+
# For a major release (e.g., 2.x.x -> 3.0.0):
48+
$ cargo release major --manifest-path backend/Cargo.toml --execute
49+
50+
# For a pre-release (e.g., 2.0.0-alpha.2 -> 2.0.0-alpha.3):
51+
$ cargo release alpha --manifest-path backend/Cargo.toml --execute
52+
```
53+
54+
This will:
55+
- Update the version in `backend/Cargo.toml`
56+
- Create a commit: `chore: release v<version>`
57+
- Create a git tag: `v<version>`
58+
59+
2. **Review** the commit and tag, then **push**:
60+
61+
```console
62+
$ git push && git push --tags
63+
```
64+
65+
3. **Create a GitHub Release** from the tag. The release workflow will automatically build all wheels and publish to PyPI.
66+
1967
## Code of Conduct
2068

2169
### Our Pledge

backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wily_backend"
3-
version = "2.0.0-alpha.1"
3+
version = "2.0.0-alpha.2"
44
edition = "2021"
55

66
[lib]

release.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cargo-release configuration
2+
# Install: cargo install cargo-release
3+
# Usage: cargo release patch|minor|major|alpha|rc --execute
4+
#
5+
# This bumps the version in backend/Cargo.toml, commits, and creates a git tag.
6+
# The Python package version is derived automatically via maturin + importlib.metadata.
7+
8+
[workspace]
9+
sign-tag = false
10+
tag-name = "v{{version}}"
11+
tag-message = "Release v{{version}}"
12+
pre-release-commit-message = "chore: release v{{version}}"
13+
publish = false
14+
push = false

src/wily/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
import datetime
4141
import logging
4242
import tempfile
43+
from importlib.metadata import version
4344

4445
from rich.logging import RichHandler
4546

46-
__version__ = "2.0.0a2"
47+
__version__ = version("wily")
4748

4849
_, WILY_LOG_NAME = tempfile.mkstemp(suffix="wily_log")
4950

0 commit comments

Comments
 (0)