Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make date/release more do-what-I-mean #2

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -56,10 +56,22 @@ In other words, if you specify `YYYY.MM.DD` as your scheme, and it's the 16th of
| Original version | Command | New version |
| ---------------- | ----------------------- | --------------- |
| `2024.07.22` | `hatch version release` | `2024.09.16` |
| `2024.07.22.1` | `hatch version release` | `2024.09.16` |
| `2024.07.22` | `hatch version date,a` | `2024.09.16a0` |
| `2021.01.01` | `hatch version rc` | `2021.01.01rc0` |
| `2024.7.22` | `hatch version patch` | `2024.07.22.1` |

## Version history

### 2024.9.17

- Initial release

### 2024.9.26

- Changed the `date`/`release` bump instructions to reset any non-date segments.
In other words, a `release` bump from `2024.07.22.1` no longer results in `2024.09.16.1`.

[hatch]: https://hatch.pypa.io/
[hatch_version_updating]: https://hatch.pypa.io/latest/version/#updating
[hatch_version_segments]: https://hatch.pypa.io/latest/version/#supported-segments
7 changes: 1 addition & 6 deletions src/hatch_calver/bump.py
Original file line number Diff line number Diff line change
@@ -72,12 +72,7 @@ def bump_calver(
instructions = desired_version.split(",")
for inst in instructions:
if inst in {"date", "release"}:
# Update the prefix of the current `release`,
# but keep the remaining (non-specified) parts as-is.
release = (
*(_map_scheme_part(part, version_date) for part in scheme_parts),
*v.release[len(scheme_parts) :],
)
release = tuple(_map_scheme_part(part, version_date) for part in scheme_parts)
v._version = v._version._replace(release=release)
_update_version(v, release=release)
elif inst in {"micro", "patch", "fix"}:
4 changes: 3 additions & 1 deletion tests/test_hatch_calver.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
("0", "release", "2024.9.16", "YYYY.MM.DD"),
("0", "date", "2024.09.16", "YYYY.0M.DD"),
("0.0", "date", "24.38", "YY.WW"),
# Test that `release`/`date` instructions reset the patch level
("2024.9.15.1", "release", "2024.9.16", "YYYY.MM.DD"),
# Test patch
("2024.09.16", "patch", "2024.09.16.1", "YYYY.0M.DD"),
("2024.09.16.1", "patch", "2024.09.16.2", "YYYY.0M.DD"),
@@ -24,7 +26,7 @@
("2024.09.16", "dev", "2024.9.16.dev0", "YYYY.M.DD"),
# Weird long instructions
("2024.09.16.42", "patch,micro,fix,post,post", "2024.09.16.45.post1", "YYYY.0M.DD"),
("2024.09.10.1.post3", "date,patch,micro,fix,post,post", "24.09.16.4.post1", "YY.0M.DD"),
("2024.09.10.1.post3", "date,patch,micro,fix,post,post", "24.09.16.3.post1", "YY.0M.DD"),
# Cases which do not update the date part (`release`/`date` not specified)
("2023", "patch", "2023.1", "YYYY"),
("2023.12", "patch", "2023.12.1", "YYYY.MM"),