From 2f5f5f664e282bed6dc05beed81ae17612a52c6d Mon Sep 17 00:00:00 2001 From: Yossi <54272821+Apakottur@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:51:17 +0000 Subject: [PATCH] Retry uv lock until PyPI's simple index names the release PyPI's JSON API named unref 0.5.1 before the simple index that uv lock reads, so the mirror started by unref's release failed to lock it. The index is cached for up to 10 minutes, so uv lock is retried for 12. Assisted-by: Claude:claude-opus-5-5 --- mirror.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mirror.py b/mirror.py index 98ac917..cd20ef3 100644 --- a/mirror.py +++ b/mirror.py @@ -6,6 +6,7 @@ """ import re +import time import tomllib from pathlib import Path @@ -20,6 +21,10 @@ "pyproject.toml": r'("unref==)[0-9.]+', "README.md": r'(rev: v|rev = "v)[0-9.]+', } +# PyPI's JSON API can name a release before the simple index that `uv lock` reads, which is cached for up to 10 +# minutes. `uv lock` is retried for longer than that. +_LOCK_ATTEMPTS = 48 +_LOCK_DELAY_SECONDS = 15 def _released_versions() -> list[Version]: @@ -52,13 +57,29 @@ def _set_version(version: Version) -> None: file.write_text(text) +def _lock(version: Version) -> None: + for attempt in range(1, _LOCK_ATTEMPTS + 1): + try: + # Without the refresh, uv could reuse its own cache of the index from the attempt before. + shpyx.run(["uv", "lock", "--refresh-package", "unref"], exec_dir=_ROOT) + return + except shpyx.ShpyxVerificationError as error: + if attempt == _LOCK_ATTEMPTS: + raise + print( + f"Attempt {attempt} of {_LOCK_ATTEMPTS} to lock unref {version} failed:\n{error.result.stderr}", + flush=True, + ) + time.sleep(_LOCK_DELAY_SECONDS) + + def main() -> None: current = _current_version() for version in _released_versions(): if version <= current: continue _set_version(version) - shpyx.run(["uv", "lock"], exec_dir=_ROOT) + _lock(version) shpyx.run(["git", "add", *_FILES, "uv.lock"], exec_dir=_ROOT) shpyx.run(["git", "commit", "--message", f"Mirror unref {version}"], exec_dir=_ROOT) shpyx.run(["git", "tag", f"v{version}"], exec_dir=_ROOT)