open-standards/wai/wai-quantum-cli/release/formulae.py
Transaction Science 4d4c6dd147
All checks were successful
standards workspaces build + test / which workspaces this change touches (pull_request) Successful in 13s
wai-quantum command line / does this change touch it (pull_request) Successful in 16s
wai-quantum studio and desktop / does this change touch it (pull_request) Successful in 32s
wai-quantum command line / command line · linux (pull_request) Successful in 1m9s
repository checks / lockfiles, tests in CI, workflow hygiene, spec and section references, public text (pull_request) Successful in 2m4s
wai-quantum studio and desktop / studio · browser (pull_request) Successful in 2m41s
standards workspaces build + test / joule-code-rs (joule-code/joule-code-rs, joule-code-rs, linux-arm64, true) (pull_request) Successful in 10m11s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 13m29s
wai-quantum command line / command line · macos (pull_request) Successful in 39s
wai-quantum studio and desktop / desktop app · macos (pull_request) Successful in 2m21s
wai-quantum-cli release: read the SHA-256 files over the private network
The formulae job of the first full release run (wai-quantum-cli-v0.1.0) failed with a
403: it read each archive's .sha256 through its public download URL, and the public
address refuses the Python library's default user agent. formulae.py now reads them
at the forge's own address, the API's (over the private network, as the uploads go),
with a user agent of its own. The formula and the manifest still point users at the
public URLs. Run by hand against that release, it wrote both, which are attached there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 22:40:03 -04:00

99 lines
3.5 KiB
Python

"""The package managers' entries for a wai-quantum release, from the SHA-256 files
attached to it:
python3 release/formulae.py <version> <tag> <forge-api> <owner/repo> <public-url> <out-dir>
Writes <out-dir>/wai-quantum.rb (a Homebrew formula for macOS and Linux) and
<out-dir>/wai-quantum.json (a Scoop manifest for Windows). A platform whose archive
is not attached is left out, and stderr says so; with none at all, it fails.
"""
import json
import os
import pathlib
import sys
import urllib.request
version, tag, api, repo, public, out = sys.argv[1:7]
token = os.environ.get("FORGE_TOKEN", "")
# A user agent of our own: the public address refuses the library's default one.
headers = {"User-Agent": "wai-quantum-release"}
if token:
headers["Authorization"] = f"token {token}"
# The forge's own address, as the API's: the SHA-256 files are read there, over the
# private network, not through the public address the formula points users to.
web = api.rsplit("/api/v1", 1)[0]
def get(url):
with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=60) as r:
return r.read()
release = json.loads(get(f"{api}/repos/{repo}/releases/tags/{tag}"))
assets = {a["name"]: a for a in release.get("assets", [])}
def digest(archive):
"""The SHA-256 its .sha256 file states, or None when either is missing."""
if archive not in assets or archive + ".sha256" not in assets:
print(f"note: {archive} is not attached; left out", file=sys.stderr)
return None
return get(f"{web}/{repo}/releases/download/{tag}/{archive}.sha256").decode().split()[0]
def url(archive):
return f"{public}/releases/download/{tag}/{archive}"
targets = {
("macos", "arm"): "aarch64-apple-darwin",
("macos", "intel"): "x86_64-apple-darwin",
("linux", "arm"): "aarch64-unknown-linux-musl",
("linux", "intel"): "x86_64-unknown-linux-musl",
}
blocks = {}
for (os_name, cpu), triple in targets.items():
archive = f"wai-quantum-{version}-{triple}.tar.gz"
sha = digest(archive)
if sha:
blocks.setdefault(os_name, []).append(f' on_{cpu} do\n url "{url(archive)}"\n sha256 "{sha}"\n end\n')
win = f"wai-quantum-{version}-x86_64-pc-windows-msvc"
win_sha = digest(win + ".zip")
if not blocks and not win_sha:
sys.exit("no archive is attached to the release")
formula = f'''class WaiQuantum < Formula
desc "OpenQASM programs run as the WAI quantum job service runs them, signed"
homepage "https://wai.transaction.science/quantum-studio/"
version "{version}"
license "Apache-2.0"
'''
for os_name in ("macos", "linux"):
if os_name in blocks:
formula += f" on_{os_name} do\n" + "".join(blocks[os_name]) + " end\n"
formula += '''
def install
bin.install "wai-quantum"
generate_completions_from_executable(bin/"wai-quantum", "completions")
end
test do
assert_match "did:key:z6Mk", shell_output("#{bin}/wai-quantum key --demo-key")
end
end
'''
pathlib.Path(out, "wai-quantum.rb").write_text(formula)
sha = win_sha
if sha:
manifest = {
"version": version,
"description": "OpenQASM programs run as the WAI quantum job service runs them, signed",
"homepage": "https://wai.transaction.science/quantum-studio/",
"license": "Apache-2.0",
"architecture": {"64bit": {"url": url(win + ".zip"), "hash": sha, "extract_dir": win}},
"bin": "wai-quantum.exe",
}
pathlib.Path(out, "wai-quantum.json").write_text(json.dumps(manifest, indent=2) + "\n")
print(f"wrote the formula{' and the manifest' if sha else ''} for wai-quantum {version}")