ts-pack-cli 1.27.1__py3-none-win_amd64.whl
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.
- ts_pack_cli/__init__.py +5 -0
- ts_pack_cli/bin/x86_64-pc-windows-msvc/ts-pack.exe +4 -0
- ts_pack_cli/cli.py +44 -0
- ts_pack_cli/downloader.py +251 -0
- ts_pack_cli-1.27.1.dist-info/METADATA +30 -0
- ts_pack_cli-1.27.1.dist-info/RECORD +8 -0
- ts_pack_cli-1.27.1.dist-info/WHEEL +4 -0
- ts_pack_cli-1.27.1.dist-info/entry_points.txt +2 -0
ts_pack_cli/__init__.py
ADDED
ts_pack_cli/cli.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""CLI entry point for the ts-pack proxy.
|
|
2
|
+
|
|
3
|
+
A platform-specific wheel bundles the native binary under ``ts_pack_cli/bin/<target>/``;
|
|
4
|
+
the sdist (and unknown platforms) ship no binary and fall back to the runtime downloader.
|
|
5
|
+
Each wheel contains exactly one ``bin/<target>`` directory, so the binary is located by
|
|
6
|
+
globbing rather than recomputing the target triple.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import platform
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from .downloader import run
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _find_bundled_binary() -> str | None:
|
|
21
|
+
"""Return the path to the bundled native binary if this wheel shipped one."""
|
|
22
|
+
bin_root = Path(__file__).parent / "bin"
|
|
23
|
+
if not bin_root.is_dir():
|
|
24
|
+
return None
|
|
25
|
+
|
|
26
|
+
binary_name = "ts-pack.exe" if platform.system().lower() == "windows" else "ts-pack"
|
|
27
|
+
for candidate in bin_root.glob(f"*/{binary_name}"):
|
|
28
|
+
if candidate.is_file() and os.access(candidate, os.X_OK):
|
|
29
|
+
return str(candidate)
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main() -> None:
|
|
34
|
+
"""Resolve the native binary (bundled or downloaded) and exec it with forwarded argv."""
|
|
35
|
+
bundled = _find_bundled_binary()
|
|
36
|
+
if bundled:
|
|
37
|
+
completed = subprocess.run([bundled, *sys.argv[1:]], check=False) # noqa: S603
|
|
38
|
+
sys.exit(completed.returncode)
|
|
39
|
+
|
|
40
|
+
sys.exit(run(sys.argv[1:]))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""Download, verify, and run the native ts-pack binary.
|
|
2
|
+
|
|
3
|
+
The package version is the release version: the archive is fetched from the
|
|
4
|
+
``v<version>`` release of this exact package, never from ``latest``, and checked
|
|
5
|
+
against that release's SHA256SUMS. All diagnostics go to stderr.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import os
|
|
12
|
+
import platform
|
|
13
|
+
import shutil
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tarfile
|
|
17
|
+
import tempfile
|
|
18
|
+
import zipfile
|
|
19
|
+
from pathlib import Path, PurePosixPath
|
|
20
|
+
from typing import cast
|
|
21
|
+
from urllib.error import HTTPError, URLError
|
|
22
|
+
from urllib.parse import quote, urlsplit
|
|
23
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
|
24
|
+
|
|
25
|
+
from . import __version__
|
|
26
|
+
|
|
27
|
+
REPO = "xberg-io/tree-sitter-language-pack"
|
|
28
|
+
BIN_NAME = "ts-pack"
|
|
29
|
+
PKG_NAME = "ts-pack-cli"
|
|
30
|
+
ALLOW_UNVERIFIED_ENV = "TS_PACK_CLI_ALLOW_UNVERIFIED"
|
|
31
|
+
SUMS_NAME = "SHA256SUMS"
|
|
32
|
+
_USER_AGENT = "ts-pack-cli-python-proxy"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _target_triple() -> str:
|
|
36
|
+
system = platform.system().lower()
|
|
37
|
+
machine = platform.machine().lower()
|
|
38
|
+
|
|
39
|
+
if system == "windows":
|
|
40
|
+
if machine in {"amd64", "x86_64"}:
|
|
41
|
+
return "x86_64-pc-windows-msvc"
|
|
42
|
+
raise RuntimeError(f"unsupported Windows arch: {machine}")
|
|
43
|
+
if system == "linux":
|
|
44
|
+
if machine in {"amd64", "x86_64"}:
|
|
45
|
+
return "x86_64-unknown-linux-gnu"
|
|
46
|
+
if machine in {"aarch64", "arm64"}:
|
|
47
|
+
return "aarch64-unknown-linux-gnu"
|
|
48
|
+
raise RuntimeError(f"unsupported Linux arch: {machine}")
|
|
49
|
+
if system == "darwin":
|
|
50
|
+
if machine in {"aarch64", "arm64"}:
|
|
51
|
+
return "aarch64-apple-darwin"
|
|
52
|
+
if machine in {"amd64", "x86_64"}:
|
|
53
|
+
return "x86_64-apple-darwin"
|
|
54
|
+
raise RuntimeError(f"unsupported macOS arch: {machine}")
|
|
55
|
+
raise RuntimeError(f"unsupported platform: {system} {machine}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _binary_name() -> str:
|
|
59
|
+
return f"{BIN_NAME}.exe" if platform.system().lower() == "windows" else BIN_NAME
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _HttpsOnlyRedirectHandler(HTTPRedirectHandler):
|
|
63
|
+
"""Reject any redirect whose target is not https (downgrade/SSRF guard)."""
|
|
64
|
+
|
|
65
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202, PLR0913
|
|
66
|
+
if urlsplit(newurl).scheme.lower() != "https":
|
|
67
|
+
raise URLError(f"refusing non-https redirect to: {newurl}")
|
|
68
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
_opener = build_opener(_HttpsOnlyRedirectHandler())
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _http_get(url: str) -> bytes:
|
|
75
|
+
if urlsplit(url).scheme.lower() != "https":
|
|
76
|
+
raise RuntimeError(f"refusing non-https URL: {url}")
|
|
77
|
+
request = Request(url, headers={"User-Agent": _USER_AGENT}) # noqa: S310 - scheme validated https-only above
|
|
78
|
+
try:
|
|
79
|
+
with _opener.open(request, timeout=60) as response:
|
|
80
|
+
if response.status != 200:
|
|
81
|
+
raise RuntimeError(f"HTTP {response.status} for {url}")
|
|
82
|
+
return cast("bytes", response.read())
|
|
83
|
+
except HTTPError as exc:
|
|
84
|
+
raise RuntimeError(f"HTTP {exc.code} for {url}") from exc
|
|
85
|
+
except URLError as exc:
|
|
86
|
+
raise RuntimeError(f"failed to fetch {url}: {exc}") from exc
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _archive_name(triple: str) -> str:
|
|
90
|
+
return f"{BIN_NAME}-{triple}.{'zip' if 'windows' in triple else 'tar.gz'}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _asset_url(version: str, name: str) -> str:
|
|
94
|
+
return f"https://github.com/{REPO}/releases/download/v{quote(version, safe='')}/{name}"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _expected_digest(text: str, asset_name: str) -> str | None:
|
|
98
|
+
for line in text.splitlines():
|
|
99
|
+
stripped = line.strip()
|
|
100
|
+
if not stripped:
|
|
101
|
+
continue
|
|
102
|
+
parts = stripped.split()
|
|
103
|
+
if len(parts) < 2:
|
|
104
|
+
continue
|
|
105
|
+
name = parts[-1].lstrip("*")
|
|
106
|
+
if name == asset_name:
|
|
107
|
+
return parts[0].lower()
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _verify_archive(data: bytes, asset_name: str, sums_text: str | None, *, allow_unverified: bool = False) -> None:
|
|
112
|
+
"""Check ``data`` against the release's SHA256SUMS; fail closed when it is missing."""
|
|
113
|
+
if sums_text is None:
|
|
114
|
+
if allow_unverified:
|
|
115
|
+
print(
|
|
116
|
+
f"WARNING: no {SUMS_NAME} asset found for {asset_name}; installing unverified "
|
|
117
|
+
f"because {ALLOW_UNVERIFIED_ENV}=1 is set.",
|
|
118
|
+
file=sys.stderr,
|
|
119
|
+
)
|
|
120
|
+
return
|
|
121
|
+
raise RuntimeError(
|
|
122
|
+
f"no {SUMS_NAME} asset found in the release for {asset_name} - refusing to install an "
|
|
123
|
+
f"unverified binary. Set {ALLOW_UNVERIFIED_ENV}=1 to override."
|
|
124
|
+
)
|
|
125
|
+
expected = _expected_digest(sums_text, asset_name)
|
|
126
|
+
if not expected:
|
|
127
|
+
raise RuntimeError(f"no checksum entry for {asset_name} in {SUMS_NAME} - refusing to install unverified binary")
|
|
128
|
+
digest = hashlib.sha256(data).hexdigest().lower()
|
|
129
|
+
if digest != expected:
|
|
130
|
+
raise RuntimeError(f"checksum mismatch for {asset_name} (expected {expected}, got {digest})")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _fetch_sums(version: str) -> str | None:
|
|
134
|
+
try:
|
|
135
|
+
return _http_get(_asset_url(version, SUMS_NAME)).decode("utf-8")
|
|
136
|
+
except RuntimeError as exc:
|
|
137
|
+
if "HTTP 404" in str(exc):
|
|
138
|
+
return None
|
|
139
|
+
raise
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _is_within(base: Path, target: Path) -> bool:
|
|
143
|
+
"""True if `target`'s resolved path stays inside `base`."""
|
|
144
|
+
base_resolved = base.resolve()
|
|
145
|
+
try:
|
|
146
|
+
target.resolve().relative_to(base_resolved)
|
|
147
|
+
except ValueError:
|
|
148
|
+
return False
|
|
149
|
+
return True
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _reject_unsafe_member(name: str) -> None:
|
|
153
|
+
"""Reject absolute paths and any `..` component (zip-slip / tar-slip)."""
|
|
154
|
+
normalized = name.replace("\\", "/")
|
|
155
|
+
pure = PurePosixPath(normalized)
|
|
156
|
+
if pure.is_absolute() or normalized.startswith("/"):
|
|
157
|
+
raise RuntimeError(f"refusing absolute path in archive: {name}")
|
|
158
|
+
if len(normalized) >= 2 and normalized[1] == ":":
|
|
159
|
+
raise RuntimeError(f"refusing absolute path in archive: {name}")
|
|
160
|
+
if any(part == ".." for part in pure.parts):
|
|
161
|
+
raise RuntimeError(f"refusing parent-directory escape in archive: {name}")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _safe_extract(archive_path: Path, asset_name: str, dest: Path) -> None:
|
|
165
|
+
"""Extract a tar/zip, validating every member stays within `dest`.
|
|
166
|
+
|
|
167
|
+
Does not rely on extractall() defaults or the 3.12-only ``filter='data'``:
|
|
168
|
+
each member name is rejected up front if it is absolute or contains ``..``,
|
|
169
|
+
and the resolved destination path is re-checked against ``dest``.
|
|
170
|
+
"""
|
|
171
|
+
dest = dest.resolve()
|
|
172
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
173
|
+
|
|
174
|
+
if asset_name.lower().endswith(".zip"):
|
|
175
|
+
with zipfile.ZipFile(archive_path) as zf:
|
|
176
|
+
for entry in zf.namelist():
|
|
177
|
+
_reject_unsafe_member(entry)
|
|
178
|
+
if not _is_within(dest, dest / entry):
|
|
179
|
+
raise RuntimeError(f"refusing archive entry escaping dest: {entry}")
|
|
180
|
+
for entry in zf.namelist():
|
|
181
|
+
zf.extract(entry, dest)
|
|
182
|
+
else:
|
|
183
|
+
with tarfile.open(archive_path, "r:gz") as tf:
|
|
184
|
+
for member in tf.getmembers():
|
|
185
|
+
_reject_unsafe_member(member.name)
|
|
186
|
+
if not _is_within(dest, dest / member.name):
|
|
187
|
+
raise RuntimeError(f"refusing archive entry escaping dest: {member.name}")
|
|
188
|
+
if member.islnk() or member.issym():
|
|
189
|
+
link_target = dest / member.name
|
|
190
|
+
if not _is_within(dest, link_target.parent / member.linkname):
|
|
191
|
+
raise RuntimeError(f"refusing link escaping dest: {member.name}")
|
|
192
|
+
tf.extractall(dest) # noqa: S202 (members validated above)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _find_binary(root: Path, name: str) -> Path | None:
|
|
196
|
+
for candidate in root.rglob(name):
|
|
197
|
+
if candidate.is_file():
|
|
198
|
+
return candidate
|
|
199
|
+
return None
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _cache_dir(tag: str) -> Path:
|
|
203
|
+
cache = Path.home() / ".cache" / PKG_NAME / tag
|
|
204
|
+
cache.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
205
|
+
return cache
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def ensure_binary() -> str:
|
|
209
|
+
"""Ensure the native binary for this package version exists locally, downloading if necessary."""
|
|
210
|
+
override = os.getenv("TS_PACK_BINARY")
|
|
211
|
+
if override:
|
|
212
|
+
return override
|
|
213
|
+
|
|
214
|
+
version = __version__
|
|
215
|
+
cache = _cache_dir(f"v{version}")
|
|
216
|
+
binary_path = cache / _binary_name()
|
|
217
|
+
if binary_path.exists() and os.access(binary_path, os.X_OK):
|
|
218
|
+
return str(binary_path)
|
|
219
|
+
|
|
220
|
+
name = _archive_name(_target_triple())
|
|
221
|
+
print(f"Downloading {BIN_NAME} {version} asset {name}...", file=sys.stderr)
|
|
222
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
223
|
+
tmp = Path(tmpdir)
|
|
224
|
+
data = _http_get(_asset_url(version, name))
|
|
225
|
+
_verify_archive(
|
|
226
|
+
data,
|
|
227
|
+
name,
|
|
228
|
+
_fetch_sums(version),
|
|
229
|
+
allow_unverified=os.getenv(ALLOW_UNVERIFIED_ENV) == "1",
|
|
230
|
+
)
|
|
231
|
+
archive_path = tmp / name
|
|
232
|
+
archive_path.write_bytes(data)
|
|
233
|
+
extract_dir = tmp / "extract"
|
|
234
|
+
extract_dir.mkdir()
|
|
235
|
+
_safe_extract(archive_path, name, extract_dir)
|
|
236
|
+
found = _find_binary(extract_dir, _binary_name())
|
|
237
|
+
if not found:
|
|
238
|
+
raise RuntimeError(f"binary {_binary_name()} not found after extracting {name}")
|
|
239
|
+
shutil.move(str(found), str(binary_path))
|
|
240
|
+
|
|
241
|
+
if platform.system().lower() != "windows":
|
|
242
|
+
binary_path.chmod(0o755)
|
|
243
|
+
print(f"{BIN_NAME} installed.", file=sys.stderr)
|
|
244
|
+
return str(binary_path)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def run(args: list[str]) -> int:
|
|
248
|
+
"""Run the native binary with the given args, returning its exit code."""
|
|
249
|
+
binary_path = ensure_binary()
|
|
250
|
+
completed = subprocess.run([binary_path, *args], check=False) # noqa: S603
|
|
251
|
+
return completed.returncode
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ts-pack-cli
|
|
3
|
+
Version: 1.27.1
|
|
4
|
+
Summary: CLI proxy for ts-pack — downloads and runs the native ts-pack binary from GitHub releases.
|
|
5
|
+
Project-URL: Homepage, https://github.com/xberg-io/tree-sitter-language-pack
|
|
6
|
+
Project-URL: Issues, https://github.com/xberg-io/tree-sitter-language-pack/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/xberg-io/tree-sitter-language-pack.git
|
|
8
|
+
Author-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
|
|
9
|
+
Maintainer-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
|
|
10
|
+
License: MIT
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# ts-pack-cli
|
|
23
|
+
|
|
24
|
+
CLI proxy for [`ts-pack`](https://github.com/xberg-io/tree-sitter-language-pack). Installing
|
|
25
|
+
this package provides a `ts-pack` command. Platform wheels bundle the native binary; the
|
|
26
|
+
source distribution downloads the binary of the same release version from GitHub releases
|
|
27
|
+
and verifies it against that release's `SHA256SUMS` before running it.
|
|
28
|
+
|
|
29
|
+
The package version is the `ts-pack` release version, so `ts-pack-cli==X.Y.Z` always runs
|
|
30
|
+
`ts-pack` `X.Y.Z`.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ts_pack_cli/__init__.py,sha256=qtayVZKIoo0-Hb20wfxSSIQsPl-iAWfYJjUyVTsu7Cg,257
|
|
2
|
+
ts_pack_cli/cli.py,sha256=in33mxZUvW7Kk897OPaod5GVkkMdRoiLp_nFUCVlp7E,1363
|
|
3
|
+
ts_pack_cli/downloader.py,sha256=sv5wHpbpthFdh0pP5Btpt-mUeb5VTUzpmBfko6bM344,9516
|
|
4
|
+
ts_pack_cli/bin/x86_64-pc-windows-msvc/ts-pack.exe,sha256=Dvq1T3ctO2KOsQStMDyJhkkADItB-3jTaQxGPrT8KtM,467122176
|
|
5
|
+
ts_pack_cli-1.27.1.dist-info/METADATA,sha256=xXlLJeitswk3JOhGDHKooP95EXe7C--BAstelWICy4A,1506
|
|
6
|
+
ts_pack_cli-1.27.1.dist-info/WHEEL,sha256=lpoBGaIUIidvvdZ4qRAP61bBKYJdt4FI3WXFL50Gzyo,94
|
|
7
|
+
ts_pack_cli-1.27.1.dist-info/entry_points.txt,sha256=IN9wTGMNcJ3hZP2h_QxoAAH6ARCQbi_f7R5mm-HR9bA,49
|
|
8
|
+
ts_pack_cli-1.27.1.dist-info/RECORD,,
|