|
1 | 1 | import json |
2 | | -import re |
3 | 2 | import sys |
4 | 3 | from pathlib import Path |
5 | 4 |
|
6 | | -import tomlkit |
7 | | - |
8 | 5 | new_backend_version = sys.argv[1] |
9 | 6 |
|
10 | 7 | assert not new_backend_version.startswith("v"), "Version should not start with 'v'" |
11 | 8 |
|
12 | 9 | repo_root = Path(__file__).parent / ".." / ".." |
13 | | -pyproject_toml = repo_root / "pyproject.toml" |
14 | 10 | juliapkg_json = repo_root / "pysr" / "juliapkg.json" |
15 | | -release_please_manifest = repo_root / ".release-please-manifest.json" |
16 | | - |
17 | | -with open(pyproject_toml) as toml_file: |
18 | | - pyproject_data = tomlkit.parse(toml_file.read()) |
19 | | - |
20 | 11 | with open(juliapkg_json) as f: |
21 | 12 | juliapkg_data = json.load(f) |
22 | 13 |
|
23 | | -with open(release_please_manifest) as f: |
24 | | - release_please_manifest_data = json.load(f) |
25 | | - |
26 | | -current_version = pyproject_data["project"]["version"] |
27 | | -parts = current_version.split(".") |
28 | | - |
29 | | -if len(parts) < 3: |
30 | | - raise ValueError( |
31 | | - f"Invalid version format: {current_version}. Expected at least 3 components (major.minor.patch)" |
32 | | - ) |
33 | | - |
34 | | -major, minor = parts[0], parts[1] |
35 | | - |
36 | | -patch_match = re.match(r"^(\d+)(.*)$", parts[2]) |
37 | | -if not patch_match: |
38 | | - raise ValueError( |
39 | | - f"Could not parse patch version from '{parts[2]}' in version {current_version}. " |
40 | | - f"Expected patch to start with a number (e.g., '0', '1a1', '2rc3')" |
41 | | - ) |
42 | | - |
43 | | -patch_num_str, patch_suffix = patch_match.groups() |
44 | | -patch_num = int(patch_num_str) |
45 | | - |
46 | | -pre_release_match = re.fullmatch(r"(a|b|rc)(\d+)", patch_suffix) |
47 | | -if pre_release_match: |
48 | | - pre_tag, pre_num = pre_release_match.groups() |
49 | | - new_patch = patch_num |
50 | | - new_suffix = f"{pre_tag}{int(pre_num) + 1}" |
51 | | -else: |
52 | | - new_patch = patch_num + 1 |
53 | | - new_suffix = patch_suffix |
54 | | - |
55 | | -# Add back any additional version components (e.g., "2.0.0.dev1" -> ".dev1") |
56 | | -extra_parts = "." + ".".join(parts[3:]) if len(parts) > 3 else "" |
57 | | -new_version = f"{major}.{minor}.{new_patch}{new_suffix}{extra_parts}" |
58 | | - |
59 | | -pyproject_data["project"]["version"] = new_version |
60 | | -release_please_manifest_data["."] = new_version |
61 | | - |
62 | | -# Update backend - maintain current format (either "rev" or "version") |
| 14 | +# Update backend, maintain current format (either "rev" or "version") |
63 | 15 | backend_pkg = juliapkg_data["packages"]["SymbolicRegression"] |
64 | 16 | if "rev" in backend_pkg: |
65 | 17 | backend_pkg["rev"] = f"v{new_backend_version}" |
|
70 | 22 | "SymbolicRegression package must have either 'rev' or 'version' field" |
71 | 23 | ) |
72 | 24 |
|
73 | | -with open(pyproject_toml, "w") as toml_file: |
74 | | - toml_file.write(tomlkit.dumps(pyproject_data)) |
75 | | - |
76 | 25 | with open(juliapkg_json, "w") as f: |
77 | 26 | json.dump(juliapkg_data, f, indent=4) |
78 | 27 | f.write("\n") |
79 | | - |
80 | | -with open(release_please_manifest, "w") as f: |
81 | | - json.dump(release_please_manifest_data, f, indent=2) |
82 | | - f.write("\n") |
0 commit comments