Update the [project] version field in a pyproject.toml file. Args: file_path: Path to pyproject.toml file. new_version: New version string. Returns: True if version was updated, False otherwise.
(file_path: Path, new_version: str)
| 302 | |
| 303 | |
| 304 | def update_pyproject_version(file_path: Path, new_version: str) -> bool: |
| 305 | """Update the [project] version field in a pyproject.toml file. |
| 306 | |
| 307 | Args: |
| 308 | file_path: Path to pyproject.toml file. |
| 309 | new_version: New version string. |
| 310 | |
| 311 | Returns: |
| 312 | True if version was updated, False otherwise. |
| 313 | """ |
| 314 | if not file_path.exists(): |
| 315 | return False |
| 316 | |
| 317 | doc = tomlkit.parse(file_path.read_text()) |
| 318 | project = doc.get("project") |
| 319 | if project is None: |
| 320 | return False |
| 321 | old_version = project.get("version") |
| 322 | if old_version is None or old_version == new_version: |
| 323 | return False |
| 324 | |
| 325 | project["version"] = new_version |
| 326 | file_path.write_text(tomlkit.dumps(doc)) |
| 327 | return True |
| 328 | |
| 329 | |
| 330 | _DEFAULT_WORKSPACE_PACKAGES: Final[list[str]] = [ |