|
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 | | -with open(pyproject_toml) as toml_file: |
16 | | - pyproject_data = tomlkit.parse(toml_file.read()) |
17 | | - |
18 | 11 | with open(juliapkg_json) as f: |
19 | 12 | juliapkg_data = json.load(f) |
20 | 13 |
|
21 | | -current_version = pyproject_data["project"]["version"] |
22 | | -parts = current_version.split(".") |
23 | | - |
24 | | -if len(parts) < 3: |
25 | | - raise ValueError( |
26 | | - f"Invalid version format: {current_version}. Expected at least 3 components (major.minor.patch)" |
27 | | - ) |
28 | | - |
29 | | -major, minor = parts[0], parts[1] |
30 | | - |
31 | | -patch_match = re.match(r"^(\d+)(.*)$", parts[2]) |
32 | | -if not patch_match: |
33 | | - raise ValueError( |
34 | | - f"Could not parse patch version from '{parts[2]}' in version {current_version}. " |
35 | | - f"Expected patch to start with a number (e.g., '0', '1a1', '2rc3')" |
36 | | - ) |
37 | | - |
38 | | -patch_num_str, patch_suffix = patch_match.groups() |
39 | | -patch_num = int(patch_num_str) |
40 | | - |
41 | | -pre_release_match = re.fullmatch(r"(a|b|rc)(\d+)", patch_suffix) |
42 | | -if pre_release_match: |
43 | | - pre_tag, pre_num = pre_release_match.groups() |
44 | | - new_patch = patch_num |
45 | | - new_suffix = f"{pre_tag}{int(pre_num) + 1}" |
46 | | -else: |
47 | | - new_patch = patch_num + 1 |
48 | | - new_suffix = patch_suffix |
49 | | - |
50 | | -# Add back any additional version components (e.g., "2.0.0.dev1" -> ".dev1") |
51 | | -extra_parts = "." + ".".join(parts[3:]) if len(parts) > 3 else "" |
52 | | -new_version = f"{major}.{minor}.{new_patch}{new_suffix}{extra_parts}" |
53 | | - |
54 | | -pyproject_data["project"]["version"] = new_version |
55 | | -# Update backend - maintain current format (either "rev" or "version") |
| 14 | +# Update backend, maintain current format (either "rev" or "version") |
56 | 15 | backend_pkg = juliapkg_data["packages"]["SymbolicRegression"] |
57 | 16 | if "rev" in backend_pkg: |
58 | 17 | backend_pkg["rev"] = f"v{new_backend_version}" |
|
63 | 22 | "SymbolicRegression package must have either 'rev' or 'version' field" |
64 | 23 | ) |
65 | 24 |
|
66 | | -with open(pyproject_toml, "w") as toml_file: |
67 | | - toml_file.write(tomlkit.dumps(pyproject_data)) |
68 | | - |
69 | 25 | with open(juliapkg_json, "w") as f: |
70 | 26 | json.dump(juliapkg_data, f, indent=4) |
71 | 27 | f.write("\n") |
0 commit comments