Skip to content

Commit 59e7752

Browse files
committed
Update bump-version to use mddj and packaging
Wrap in a `just` invocation so that we can use `uv run`.
1 parent e0cee6a commit 59e7752

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

RELEASING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releasing
22

3-
- Bump the version with `./scripts/bump-version.py NEW_VERSION`
3+
- Bump the version with `just bump-version NEW_VERSION`
44
- Add, commit with `git commit -m 'Bump version for release'`, and push
55
- Create a release tag, which will auto-publish to testpypi (`just tag-release`)
66
- Create a GitHub release, which will auto-publish to pypi (web UI)

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ vendor-schemas:
1414
generate-hooks:
1515
tox run -e generate-hooks-config
1616

17+
bump-version NEW_VERSION:
18+
uv run scripts/bump-version.py "{{NEW_VERSION}}"
19+
1720
tag-release:
1821
git tag -s "{{version}}" -m "v{{version}}"
1922
git push {{push_remote}} refs/tags/{{version}}

scripts/bump-version.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env python
2+
# /// script
3+
# dependencies = ["mddj==0.6.0", "packaging"]
4+
# ///
25
import re
36
import sys
47

8+
import mddj.api
9+
from packaging.version import Version
510

6-
def get_old_version():
7-
with open("pyproject.toml") as fp:
8-
content = fp.read()
9-
match = re.search(r'^version = "(\d+\.\d+\.\d+)"$', content, flags=re.MULTILINE)
10-
assert match
11-
return match.group(1)
11+
DJ = mddj.api.DJ()
1212

1313

1414
def replace_version(filename, formatstr, old_version, new_version):
@@ -48,26 +48,16 @@ def update_changelog(new_version):
4848
fp.write(content)
4949

5050

51-
def parse_version(s):
52-
vals = s.split(".")
53-
assert len(vals) == 3
54-
return tuple(int(x) for x in vals)
55-
56-
57-
def comparse_versions(old_version, new_version):
58-
assert parse_version(new_version) > parse_version(old_version)
59-
60-
6151
def main():
6252
if len(sys.argv) != 2:
6353
sys.exit(2)
6454

6555
new_version = sys.argv[1]
66-
old_version = get_old_version()
56+
old_version = DJ.read.version()
6757
print(f"old = {old_version}, new = {new_version}")
68-
comparse_versions(old_version, new_version)
58+
assert Version(new_version) > Version(old_version)
6959

70-
replace_version("pyproject.toml", 'version = "{}"', old_version, new_version)
60+
DJ.write.version(new_version)
7161
replace_version("README.md", "rev: {}", old_version, new_version)
7262
replace_version("docs/precommit_usage.rst", "rev: {}", old_version, new_version)
7363
replace_version("docs/optional_parsers.rst", "rev: {}", old_version, new_version)

0 commit comments

Comments
 (0)