cupel-cli 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cupel_cli-0.3.0/PKG-INFO +7 -0
- cupel_cli-0.3.0/cupel.py +130 -0
- cupel_cli-0.3.0/pyproject.toml +22 -0
cupel_cli-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cupel-cli
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Verification suite that grades what a coding agent produced. Runs the cupel release binary for this platform.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/tysont/cupel
|
cupel_cli-0.3.0/cupel.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# ABOUTME: The `cupel` console script of the Python package (ADR-125): downloads this platform's release binary on
|
|
2
|
+
# ABOUTME: first run, checks it against the release's SHA256SUMS, caches it, and runs it with the caller's arguments.
|
|
3
|
+
"""Verification suite that grades what a coding agent produced. Runs the cupel release binary for this platform."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import hashlib
|
|
8
|
+
import io
|
|
9
|
+
import os
|
|
10
|
+
import platform
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import tarfile
|
|
14
|
+
import tempfile
|
|
15
|
+
import urllib.error
|
|
16
|
+
import urllib.request
|
|
17
|
+
import zipfile
|
|
18
|
+
|
|
19
|
+
# The release this package runs.
|
|
20
|
+
__version__ = "0.3.0"
|
|
21
|
+
|
|
22
|
+
RELEASES = "https://github.com/tysont/cupel/releases"
|
|
23
|
+
|
|
24
|
+
# Each release target's triple and archive format, by `<os>-<arch>` in Rust's spelling, as
|
|
25
|
+
# dist/targets.toml lists them.
|
|
26
|
+
TARGETS: dict[str, list[str]] = {
|
|
27
|
+
"linux-x86_64": ["x86_64-unknown-linux-musl", "tar.gz"],
|
|
28
|
+
"linux-aarch64": ["aarch64-unknown-linux-musl", "tar.gz"],
|
|
29
|
+
"macos-x86_64": ["x86_64-apple-darwin", "tar.gz"],
|
|
30
|
+
"macos-aarch64": ["aarch64-apple-darwin", "tar.gz"],
|
|
31
|
+
"windows-x86_64": ["x86_64-pc-windows-msvc", "zip"],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
OS = {"Linux": "linux", "Darwin": "macos", "Windows": "windows"}
|
|
35
|
+
ARCH = {"x86_64": "x86_64", "AMD64": "x86_64", "aarch64": "aarch64", "arm64": "aarch64", "ARM64": "aarch64"}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class InstallError(Exception):
|
|
39
|
+
"""The release binary could not be downloaded or checked."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def target() -> list[str]:
|
|
43
|
+
system, machine = platform.system(), platform.machine()
|
|
44
|
+
found = TARGETS.get(f"{OS.get(system)}-{ARCH.get(machine)}")
|
|
45
|
+
if found is None:
|
|
46
|
+
raise InstallError(f"no release for {system} {machine}; see {RELEASES}")
|
|
47
|
+
return found
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def cache_dir() -> str:
|
|
51
|
+
"""Where downloaded binaries are kept: CUPEL_CACHE_DIR, else the user's cache directory."""
|
|
52
|
+
if os.environ.get("CUPEL_CACHE_DIR"):
|
|
53
|
+
return os.environ["CUPEL_CACHE_DIR"]
|
|
54
|
+
if os.name == "nt":
|
|
55
|
+
return os.path.join(os.environ.get("LOCALAPPDATA", os.path.expanduser("~")), "cupel")
|
|
56
|
+
return os.path.join(os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")), "cupel")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def download(url: str) -> bytes:
|
|
60
|
+
try:
|
|
61
|
+
with urllib.request.urlopen(url) as response:
|
|
62
|
+
body: bytes = response.read()
|
|
63
|
+
return body
|
|
64
|
+
except urllib.error.HTTPError as error:
|
|
65
|
+
raise InstallError(f"could not download {url}: HTTP {error.code}") from error
|
|
66
|
+
except urllib.error.URLError as error:
|
|
67
|
+
raise InstallError(f"could not download {url}: {error.reason}") from error
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def listed_digest(sums: str, archive: str) -> str:
|
|
71
|
+
"""The digest SHA256SUMS gives `archive`, in hex."""
|
|
72
|
+
for line in sums.splitlines():
|
|
73
|
+
fields = line.split()
|
|
74
|
+
if len(fields) == 2 and fields[1].lstrip("*") == archive:
|
|
75
|
+
return fields[0]
|
|
76
|
+
raise InstallError(f"SHA256SUMS lists no {archive}")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def extract(data: bytes, archive_format: str, into: str) -> None:
|
|
80
|
+
if archive_format == "zip":
|
|
81
|
+
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
|
82
|
+
archive.extractall(into)
|
|
83
|
+
return
|
|
84
|
+
with tarfile.open(fileobj=io.BytesIO(data), mode="r:gz") as archive:
|
|
85
|
+
if hasattr(tarfile, "data_filter"):
|
|
86
|
+
archive.extractall(into, filter="data")
|
|
87
|
+
else:
|
|
88
|
+
archive.extractall(into)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def install(path: str, triple: str, archive_format: str) -> None:
|
|
92
|
+
"""Downloads the release archive for `triple`, checks it, and moves its binary to `path`."""
|
|
93
|
+
base = f"{os.environ.get('CUPEL_DOWNLOAD_URL') or RELEASES}/download/v{__version__}"
|
|
94
|
+
archive = f"cupel-{__version__}-{triple}.{archive_format}"
|
|
95
|
+
listed = listed_digest(download(f"{base}/SHA256SUMS").decode("utf-8"), archive)
|
|
96
|
+
print(f"cupel: downloading {base}/{archive}", file=sys.stderr, flush=True)
|
|
97
|
+
data = download(f"{base}/{archive}")
|
|
98
|
+
actual = hashlib.sha256(data).hexdigest()
|
|
99
|
+
if actual != listed:
|
|
100
|
+
raise InstallError(f"checksum mismatch for {archive}: SHA256SUMS has {listed}, the download is {actual}")
|
|
101
|
+
with tempfile.TemporaryDirectory(prefix=".download-", dir=os.path.dirname(path)) as staging:
|
|
102
|
+
extract(data, archive_format, staging)
|
|
103
|
+
os.replace(os.path.join(staging, f"cupel-{__version__}-{triple}", os.path.basename(path)), path)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def binary() -> str:
|
|
107
|
+
"""The cached release binary, downloaded first if it is not there."""
|
|
108
|
+
triple, archive_format = target()
|
|
109
|
+
name = "cupel.exe" if os.name == "nt" else "cupel"
|
|
110
|
+
path = os.path.join(cache_dir(), __version__, triple, name)
|
|
111
|
+
if not os.path.exists(path):
|
|
112
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
113
|
+
install(path, triple, archive_format)
|
|
114
|
+
return path
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def main() -> None:
|
|
118
|
+
try:
|
|
119
|
+
path = binary()
|
|
120
|
+
except (InstallError, OSError) as error:
|
|
121
|
+
# Exit 3, Cupel's environment code: the binary could not run, so nothing was graded.
|
|
122
|
+
print(f"cupel: {error}", file=sys.stderr)
|
|
123
|
+
sys.exit(3)
|
|
124
|
+
if os.name == "nt":
|
|
125
|
+
sys.exit(subprocess.call([path, *sys.argv[1:]]))
|
|
126
|
+
os.execv(path, [path, *sys.argv[1:]])
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
main()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ABOUTME: Packaging for the `cupel-cli` Python distribution (ADR-125, ADR-146), which pipx installs: one standard-library
|
|
2
|
+
# ABOUTME: module, `cupel`, whose `cupel` console script downloads and runs this platform's release binary.
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = ["flit_core>=3.11,<4"]
|
|
5
|
+
build-backend = "flit_core.buildapi"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "cupel-cli"
|
|
9
|
+
# The version and description come from cupel.py's `__version__` and docstring.
|
|
10
|
+
dynamic = ["version", "description"]
|
|
11
|
+
license = "BSD-3-Clause"
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://github.com/tysont/cupel"
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
cupel = "cupel:main"
|
|
19
|
+
|
|
20
|
+
# The module is `cupel.py`, not `cupel_cli.py`, the name flit would look for by default.
|
|
21
|
+
[tool.flit.module]
|
|
22
|
+
name = "cupel"
|