zylon-ai/private-gpt · error · RuntimeError
Failed to update project version in pyproject.toml
Error message
Failed to update project version in pyproject.toml
What it means
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.
Source
Thrown at scripts/set_version.py:48
def write_text(path: Path, content: str) -> None:
path.write_text(content, encoding="utf-8")
def update_version_txt(version: str) -> None:
write_text(VERSION_TXT, f"{version}\n")
def update_pyproject(version: str) -> None:
content = PYPROJECT.read_text(encoding="utf-8")
updated, count = re.subn(
r'(?m)^version = "[^"]+"$',
f'version = "{version}"',
content,
count=1,
)
if count != 1:
raise RuntimeError("Failed to update project version in pyproject.toml")
write_text(PYPROJECT, updated)
def refresh_uv_lock() -> None:
result = subprocess.run(
["uv", "lock"],
cwd=REPO_ROOT,
check=False,
)
if result.returncode != 0:
raise RuntimeError("`uv lock` failed")
def main() -> int:
args = parse_args()
update_version_txt(args.version)
update_pyproject(args.version)View on GitHub (pinned to 4a030776a3)
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
Example fix
# pyproject.toml - before (dynamic version, no literal line) [project] name = "private-gpt" dynamic = ["version"] # after [project] name = "private-gpt" version = "0.1.0"
Defensive patterns
Strategy: validation
Validate before calling
import re
from pathlib import Path
def pyproject_version_writable(path: Path = Path("pyproject.toml")) -> bool:
content = path.read_text(encoding="utf-8")
return re.search(r'(?m)^version = "[^"]+"$', content) is not None
# check before running scripts/set_version.py Type guard
null
Try / catch
try:
update_pyproject(new_version)
except RuntimeError as e:
raise SystemExit(
"pyproject.toml has no literal top-level version line; "
"add one or switch the project off dynamic versioning"
) from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No distributions found in {package_dir}
- `uv lock` failed
- Unknown message role {self.role}. Expected 'system', 'user',
- Image size {image_size} exceeds maximum allowed size of {set
- Audio size {audio_size} exceeds maximum allowed size of {set
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/f085545ee02b878a.
Report an issue: GitHub.