{"record":{"id":"f085545ee02b878a","repo":"zylon-ai/private-gpt","slug":"failed-to-update-project-version-in-pyproject-toml","errorCode":null,"errorMessage":"Failed to update project version in pyproject.toml","messagePattern":"Failed to update project version in pyproject\\.toml","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/set_version.py","lineNumber":48,"sourceCode":"\ndef write_text(path: Path, content: str) -> None:\n    path.write_text(content, encoding=\"utf-8\")\n\n\ndef update_version_txt(version: str) -> None:\n    write_text(VERSION_TXT, f\"{version}\\n\")\n\n\ndef update_pyproject(version: str) -> None:\n    content = PYPROJECT.read_text(encoding=\"utf-8\")\n    updated, count = re.subn(\n        r'(?m)^version = \"[^\"]+\"$',\n        f'version = \"{version}\"',\n        content,\n        count=1,\n    )\n    if count != 1:\n        raise RuntimeError(\"Failed to update project version in pyproject.toml\")\n    write_text(PYPROJECT, updated)\n\n\ndef refresh_uv_lock() -> None:\n    result = subprocess.run(\n        [\"uv\", \"lock\"],\n        cwd=REPO_ROOT,\n        check=False,\n    )\n    if result.returncode != 0:\n        raise RuntimeError(\"`uv lock` failed\")\n\n\ndef main() -> int:\n    args = parse_args()\n\n    update_version_txt(args.version)\n    update_pyproject(args.version)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/scripts/set_version.py#L30-L66","documentation":"Raised by update_pyproject in scripts/set_version.py when the regex ^version = \"...\" (multiline, first match) does not substitute exactly once in pyproject.toml. Zero matches means the file has no top-level version line (version may be delegated to dynamic = [\"version\"]); more than one match is impossible with count=1, so the error in practice means 'not found', protecting against silently writing a version into the wrong place or nowhere.","triggerScenarios":"pyproject.toml using dynamic versioning (version supplied by hatch-vcs/setuptools-scm) so no literal version = line exists; the version line having different formatting (extra spaces, single quotes, trailing comment) that fails the exact regex; version = key present only under [tool.poetry] or another table, not at the top level; running the script from a fork whose pyproject was restructured.","commonSituations":"Rebasing set_version.py onto a project layout that moved to dynamic versions; minor formatting drift in pyproject.toml after a formatting tool ran; a stale VERSION_TXT/pyproject pair where a previous partial run already changed things.","solutions":["Ensure pyproject.toml has a literal top-level 'version = \"x.y.z\"' line under [project] with exact double-quote formatting","If the project switched to dynamic versioning, remove the update_pyproject step (or the script) instead of forcing a literal line","Fix formatting: version = \"0.1.0\" on its own line at column 0, no trailing comment","Re-run the script after correcting; it rewrites VERSION_TXT first so verify both files end up consistent"],"exampleFix":"# pyproject.toml - before (dynamic version, no literal line)\n[project]\nname = \"private-gpt\"\ndynamic = [\"version\"]\n\n# after\n[project]\nname = \"private-gpt\"\nversion = \"0.1.0\"","handlingStrategy":"validation","validationCode":"import re\nfrom pathlib import Path\n\ndef pyproject_version_writable(path: Path = Path(\"pyproject.toml\")) -> bool:\n    content = path.read_text(encoding=\"utf-8\")\n    return re.search(r'(?m)^version = \"[^\"]+\"$', content) is not None\n\n# check before running scripts/set_version.py","typeGuard":"null","tryCatchPattern":"try:\n    update_pyproject(new_version)\nexcept RuntimeError as e:\n    raise SystemExit(\n        \"pyproject.toml has no literal top-level version line; \"\n        \"add one or switch the project off dynamic versioning\"\n    ) from e","preventionTips":["Keep a literal 'version = \"x.y.z\"' line at the top level of [project] in pyproject.toml","Protect the line's exact formatting (double quotes, no trailing comment) in review","If adopting dynamic versioning, remove the pyproject-update step from set_version.py in the same change","Run the version script in CI so drift is caught immediately after pyproject restructuring"],"tags":["versioning","build","scripts","pyproject"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}