Skip to content

Commit ec1a336

Browse files
committed
build: remove update-version.sh wrappers, patch repo.ini in Python
Both .github/scripts/update-version*.sh existed only to sed the new version into repo.ini before invoking the corresponding Python script, a holdover from eachdist.py never accepting a target version as a CLI argument. update_version.py and update_patch_version.py now take the new versions directly and patch repo.ini themselves via update_repo_ini_version() (an in-place text substitution equivalent to the old sed command, not a ConfigParser round-trip, so comments and formatting in repo.ini are preserved). The 3 call sites in prepare-release-branch.yml and prepare-patch-release.yml now invoke the Python scripts directly.
1 parent cecb734 commit ec1a336

8 files changed

Lines changed: 41 additions & 28 deletions

File tree

.changelog/5381.removed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Removed `scripts/eachdist.py` in favor of tox and small purpose-built scripts: `scripts/version.py`, `scripts/update_version.py`, and `scripts/update_patch_version.py` for release version bumping, and `scripts/repo_targets.py` for distribution discovery. Renamed `eachdist.ini` to `repo.ini`.
1+
Removed `scripts/eachdist.py` and the `.github/scripts/update-version*.sh` wrappers in favor of tox and small purpose-built scripts: `scripts/version.py`, `scripts/update_version.py`, and `scripts/update_patch_version.py` for release version bumping, and `scripts/repo_targets.py` for distribution discovery. Renamed `eachdist.ini` to `repo.ini`.

.github/scripts/update-version-patch.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/scripts/update-version.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/prepare-patch-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
echo "UNSTABLE_VERSION_PREV=$unstable_version_prev" >> $GITHUB_ENV
5656
5757
- name: Update version
58-
run: .github/scripts/update-version-patch.sh $STABLE_VERSION $UNSTABLE_VERSION $STABLE_VERSION_PREV $UNSTABLE_VERSION_PREV
58+
run: ./scripts/update_patch_version.py --stable_version=$STABLE_VERSION --unstable_version=$UNSTABLE_VERSION --stable_version_prev=$STABLE_VERSION_PREV --unstable_version_prev=$UNSTABLE_VERSION_PREV
5959

6060
- name: Generate changelog
6161
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"

.github/workflows/prepare-release-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV
8282
8383
- name: Update version
84-
run: .github/scripts/update-version.sh $STABLE_VERSION $UNSTABLE_VERSION
84+
run: ./scripts/update_version.py --stable_version=$STABLE_VERSION --unstable_version=$UNSTABLE_VERSION
8585

8686
- name: Generate changelog
8787
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"
@@ -175,7 +175,7 @@ jobs:
175175
echo "UNSTABLE_NEXT_VERSION=${unstable_next_version}.dev" >> $GITHUB_ENV
176176
177177
- name: Update version
178-
run: .github/scripts/update-version.sh $STABLE_NEXT_VERSION $UNSTABLE_NEXT_VERSION
178+
run: ./scripts/update_version.py --stable_version=$STABLE_NEXT_VERSION --unstable_version=$UNSTABLE_NEXT_VERSION
179179

180180
- name: Generate changelog
181181
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"

scripts/update_patch_version.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from sys import exit
88

99
from repo_targets import find_projectroot, find_targets_unordered
10-
from version_files import update_patch_dependencies, update_version_files
10+
from version_files import (
11+
update_patch_dependencies,
12+
update_repo_ini_version,
13+
update_version_files,
14+
)
1115

1216

1317
def parse_args():
@@ -28,6 +32,10 @@ def main():
2832

2933
rootpath = find_projectroot()
3034
targets = list(find_targets_unordered(rootpath))
35+
36+
update_repo_ini_version(rootpath, "stable", args.stable_version)
37+
update_repo_ini_version(rootpath, "prerelease", args.unstable_version)
38+
3139
cfg = ConfigParser()
3240
cfg.read(str(rootpath / "repo.ini"))
3341

scripts/update_version.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
from sys import exit
88

99
from repo_targets import find_projectroot, find_targets_unordered
10-
from version_files import update_dependencies, update_version_files
10+
from version_files import (
11+
update_dependencies,
12+
update_repo_ini_version,
13+
update_version_files,
14+
)
1115

1216

1317
def parse_args():
1418
parser = ArgumentParser(
1519
description="Updates version numbers, used by maintainers and CI"
1620
)
17-
parser.add_argument("--versions", required=True)
21+
parser.add_argument("--stable_version", required=True)
22+
parser.add_argument("--unstable_version", required=True)
1823
return parser.parse_args()
1924

2025

@@ -25,13 +30,18 @@ def main():
2530

2631
rootpath = find_projectroot()
2732
targets = list(find_targets_unordered(rootpath))
33+
34+
update_repo_ini_version(rootpath, "stable", args.stable_version)
35+
update_repo_ini_version(rootpath, "prerelease", args.unstable_version)
36+
2837
cfg = ConfigParser()
2938
cfg.read(str(rootpath / "repo.ini"))
3039

31-
for group in args.versions.split(","):
32-
mcfg = cfg[group]
33-
version = mcfg["version"]
34-
packages = mcfg["packages"].split()
40+
for group, version in (
41+
("stable", args.stable_version),
42+
("prerelease", args.unstable_version),
43+
):
44+
packages = cfg[group]["packages"].split()
3545
print(f"update {group} packages to {version}")
3646
update_dependencies(targets, version, packages)
3747
update_version_files(targets, version, packages)

scripts/version_files.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def update_files(targets, filename, search, replace):
7272
_file.write(sub(search, replace, text))
7373

7474

75+
def update_repo_ini_version(rootpath, section, version):
76+
repo_ini_path = rootpath / "repo.ini"
77+
text = repo_ini_path.read_text(encoding="utf-8")
78+
text = sub(
79+
rf"(\[{section}\]\nversion=).*",
80+
lambda match: match.group(1) + version,
81+
text,
82+
count=1,
83+
)
84+
repo_ini_path.write_text(text, encoding="utf-8")
85+
86+
7587
def update_dependencies(targets, version, packages):
7688
print("updating dependencies")
7789
for pkg in packages:

0 commit comments

Comments
 (0)