Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import re
import time
import tomllib
from pathlib import Path

Expand All @@ -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]:
Expand Down Expand Up @@ -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)
Expand Down