()
| 116 | |
| 117 | |
| 118 | def main() -> int: |
| 119 | ap = argparse.ArgumentParser() |
| 120 | g = ap.add_mutually_exclusive_group(required=True) |
| 121 | g.add_argument("--set", dest="set_version", help="Set exact version (e.g., 0.6.0)") |
| 122 | g.add_argument("--part", choices=["major", "minor", "patch"], help="Bump semver part") |
| 123 | ap.add_argument("--dry-run", action="store_true") |
| 124 | args = ap.parse_args() |
| 125 | |
| 126 | current = get_current_versions() |
| 127 | # Choose baseline current version from python/pyproject if available |
| 128 | baseline = current.get("python/pyproject.toml") or current.get("pyproject.toml:[project]") or current.get("Cargo.toml:[workspace.package]") |
| 129 | if not baseline: |
| 130 | print("Could not determine current version.", file=sys.stderr) |
| 131 | return 2 |
| 132 | |
| 133 | if args.set_version: |
| 134 | new_version = args.set_version |
| 135 | if not SEMVER_RE.match(new_version): |
| 136 | print("--set must be a semantic version like 1.2.3", file=sys.stderr) |
| 137 | return 2 |
| 138 | else: |
| 139 | new_version = bump_part(str(baseline), args.part) |
| 140 | |
| 141 | print("Current versions:") |
| 142 | for k, v in current.items(): |
| 143 | print(f" {k}: {v}") |
| 144 | print(f"New version: {new_version}") |
| 145 | |
| 146 | # Apply replacements |
| 147 | # 1) python/pyproject.toml [project].version |
| 148 | if PY_PYPROJECT.exists(): |
| 149 | txt = read_text(PY_PYPROJECT) |
| 150 | new_txt, changed = replace_version_in_project_section(txt, new_version) |
| 151 | if changed: |
| 152 | write_text(PY_PYPROJECT, new_txt, args.dry_run) |
| 153 | print(f"Updated: {PY_PYPROJECT}") |
| 154 | else: |
| 155 | print(f"No change in: {PY_PYPROJECT}") |
| 156 | |
| 157 | # 2) root pyproject.toml [project].version and [tool.poetry].version |
| 158 | if ROOT_PYPROJECT.exists(): |
| 159 | txt = read_text(ROOT_PYPROJECT) |
| 160 | txt2, ch1 = replace_version_in_project_section(txt, new_version) |
| 161 | txt3, ch2 = replace_poetry_version(txt2, new_version) |
| 162 | if ch1 or ch2: |
| 163 | write_text(ROOT_PYPROJECT, txt3, args.dry_run) |
| 164 | print(f"Updated: {ROOT_PYPROJECT}") |
| 165 | else: |
| 166 | print(f"No change in: {ROOT_PYPROJECT}") |
| 167 | |
| 168 | # 3) root Cargo.toml [workspace.package].version |
| 169 | if ROOT_CARGO.exists(): |
| 170 | txt = read_text(ROOT_CARGO) |
| 171 | new_txt, changed = replace_workspace_package_version(txt, new_version) |
| 172 | if changed: |
| 173 | write_text(ROOT_CARGO, new_txt, args.dry_run) |
| 174 | print(f"Updated: {ROOT_CARGO}") |
| 175 | else: |
no test coverage detected