quarto2 0.45.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.
quarto2-0.45.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Posit, PBC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.1
2
+ Name: quarto2
3
+ Version: 0.45.0
4
+ Summary: Quarto 2: an open-source scientific and technical publishing system
5
+ Author: Posit Software, PBC
6
+ License: MIT
7
+ Project-URL: Homepage, https://quarto.org
8
+ Project-URL: Source, https://github.com/quarto-dev/q2
9
+ Project-URL: Issues, https://github.com/quarto-dev/q2/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Topic :: Text Processing :: Markup
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+
21
+ # quarto2
22
+
23
+ [Quarto 2](https://github.com/quarto-dev/q2) is an open-source scientific
24
+ and technical publishing system. This package installs its command-line
25
+ tool, `q2`.
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install quarto2
31
+ # or, as an isolated tool
32
+ uv tool install quarto2
33
+ pipx install quarto2
34
+ ```
35
+
36
+ Then:
37
+
38
+ ```bash
39
+ q2 --version
40
+ q2 render document.qmd
41
+ ```
42
+
43
+ For a one-off run without installing: `uvx --from quarto2 q2 render document.qmd`.
44
+
45
+ ## How this package works
46
+
47
+ The `q2` binary is too large to upload to PyPI for every platform, so this
48
+ package is a source distribution that contains no binary. When pip or uv
49
+ installs it, the package downloads the matching `q2` archive for your
50
+ machine from the [GitHub release](https://github.com/quarto-dev/q2/releases)
51
+ of the same version and checks it against a SHA-256 checksum recorded in
52
+ the package. The installed `q2` is the native binary, with no Python
53
+ wrapper.
54
+
55
+ Installing therefore needs access to `github.com`. To install from a
56
+ mirror, set `QUARTO2_DOWNLOAD_BASE` to a URL laid out like
57
+ `<base>/v<version>/<archive>`:
58
+
59
+ ```bash
60
+ QUARTO2_DOWNLOAD_BASE=https://mirror.example.com/q2 pip install quarto2
61
+ ```
62
+
63
+ Supported platforms: Linux (x86-64, ARM64; any libc), macOS (Intel, Apple
64
+ silicon) and Windows (x86-64, ARM64).
65
+
66
+ From Python, `quarto2.binary_path()` returns the path of the installed
67
+ binary, and `python -m quarto2 ...` runs it.
68
+
69
+ Other ways to install Quarto 2, including a standalone installer, are in
70
+ the [Quarto 2 README](https://github.com/quarto-dev/q2#readme).
@@ -0,0 +1,50 @@
1
+ # quarto2
2
+
3
+ [Quarto 2](https://github.com/quarto-dev/q2) is an open-source scientific
4
+ and technical publishing system. This package installs its command-line
5
+ tool, `q2`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install quarto2
11
+ # or, as an isolated tool
12
+ uv tool install quarto2
13
+ pipx install quarto2
14
+ ```
15
+
16
+ Then:
17
+
18
+ ```bash
19
+ q2 --version
20
+ q2 render document.qmd
21
+ ```
22
+
23
+ For a one-off run without installing: `uvx --from quarto2 q2 render document.qmd`.
24
+
25
+ ## How this package works
26
+
27
+ The `q2` binary is too large to upload to PyPI for every platform, so this
28
+ package is a source distribution that contains no binary. When pip or uv
29
+ installs it, the package downloads the matching `q2` archive for your
30
+ machine from the [GitHub release](https://github.com/quarto-dev/q2/releases)
31
+ of the same version and checks it against a SHA-256 checksum recorded in
32
+ the package. The installed `q2` is the native binary, with no Python
33
+ wrapper.
34
+
35
+ Installing therefore needs access to `github.com`. To install from a
36
+ mirror, set `QUARTO2_DOWNLOAD_BASE` to a URL laid out like
37
+ `<base>/v<version>/<archive>`:
38
+
39
+ ```bash
40
+ QUARTO2_DOWNLOAD_BASE=https://mirror.example.com/q2 pip install quarto2
41
+ ```
42
+
43
+ Supported platforms: Linux (x86-64, ARM64; any libc), macOS (Intel, Apple
44
+ silicon) and Windows (x86-64, ARM64).
45
+
46
+ From Python, `quarto2.binary_path()` returns the path of the installed
47
+ binary, and `python -m quarto2 ...` runs it.
48
+
49
+ Other ways to install Quarto 2, including a standalone installer, are in
50
+ the [Quarto 2 README](https://github.com/quarto-dev/q2#readme).
@@ -0,0 +1,216 @@
1
+ """In-tree PEP 517 build backend for the quarto2 PyPI package (bd-2p7dwmqe).
2
+
3
+ Why a custom backend instead of setuptools: the wheel must carry a
4
+ ~190 MB native executable as a *script* (so pip/uv install the real `q2`
5
+ into the environment's bin/ or Scripts\\ with no Python wrapper), tagged
6
+ for the build host only. setuptools' script handling reads scripts as
7
+ text, and its wheel tags would need overriding anyway; writing the wheel
8
+ directly is a few dozen lines and needs no build dependencies.
9
+
10
+ - `build_sdist` packs the sources plus the generated release.json (version
11
+ and per-platform SHA-256 pins). The sdist holds no binary.
12
+ - `build_wheel` runs on the installing machine: it downloads this host's
13
+ archive from the GitHub Release (or $QUARTO2_DOWNLOAD_BASE), verifies it
14
+ against release.json, and writes a `py3-none-<host>` wheel whose
15
+ `.data/scripts/` holds the binary.
16
+ - `prepare_metadata_for_build_wheel` answers metadata queries without
17
+ downloading anything.
18
+ """
19
+
20
+ import base64
21
+ import csv
22
+ import gzip
23
+ import hashlib
24
+ import io
25
+ import json
26
+ import os
27
+ import platform
28
+ import shutil
29
+ import sys
30
+ import tarfile
31
+ import tempfile
32
+ import zipfile
33
+ from pathlib import Path
34
+
35
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
36
+ import q2_pypi_lib as lib # noqa: E402
37
+
38
+ ROOT = Path(__file__).resolve().parent.parent
39
+ NAME = "quarto2"
40
+ SUMMARY = "Quarto 2: an open-source scientific and technical publishing system"
41
+ SOURCE_FILES = ["pyproject.toml", "README.md", "LICENSE", "release.json"]
42
+ SOURCE_DIRS = ["backend", "quarto2"]
43
+ # 1980-01-01, the earliest timestamp a zip entry can hold; keeps builds
44
+ # reproducible.
45
+ EPOCH = (1980, 1, 1, 0, 0, 0)
46
+ EPOCH_SECONDS = 315532800
47
+
48
+
49
+ def _info():
50
+ path = ROOT / "release.json"
51
+ if not path.exists():
52
+ raise RuntimeError(
53
+ "release.json is missing; generate it with "
54
+ "`python -I backend/q2_pypi_lib.py prepare --tag vX.Y.Z "
55
+ "--checksums checksums.sha256 --license ../../LICENSE`"
56
+ )
57
+ return json.loads(path.read_text())
58
+
59
+
60
+ def _metadata(info):
61
+ readme = (ROOT / "README.md").read_text(encoding="utf-8")
62
+ headers = [
63
+ ("Metadata-Version", "2.1"),
64
+ ("Name", NAME),
65
+ ("Version", info["pypi_version"]),
66
+ ("Summary", SUMMARY),
67
+ ("Author", "Posit Software, PBC"),
68
+ ("License", "MIT"),
69
+ ("Project-URL", "Homepage, https://quarto.org"),
70
+ ("Project-URL", "Source, https://github.com/quarto-dev/q2"),
71
+ ("Project-URL", "Issues, https://github.com/quarto-dev/q2/issues"),
72
+ ("Classifier", "Development Status :: 4 - Beta"),
73
+ ("Classifier", "Environment :: Console"),
74
+ ("Classifier", "Intended Audience :: Science/Research"),
75
+ ("Classifier", "License :: OSI Approved :: MIT License"),
76
+ ("Classifier", "Operating System :: MacOS"),
77
+ ("Classifier", "Operating System :: Microsoft :: Windows"),
78
+ ("Classifier", "Operating System :: POSIX :: Linux"),
79
+ ("Classifier", "Topic :: Text Processing :: Markup"),
80
+ ("Requires-Python", ">=3.9"),
81
+ ("Description-Content-Type", "text/markdown"),
82
+ ]
83
+ head = "".join(f"{k}: {v}\n" for k, v in headers)
84
+ return f"{head}\n{readme}"
85
+
86
+
87
+ def _wheel_file(tag):
88
+ return (
89
+ "Wheel-Version: 1.0\n"
90
+ "Generator: quarto2 in-tree backend\n"
91
+ "Root-Is-Purelib: false\n"
92
+ f"Tag: {tag}\n"
93
+ )
94
+
95
+
96
+ def _dist_info(info):
97
+ return f"{NAME}-{info['pypi_version']}.dist-info"
98
+
99
+
100
+ # --- PEP 517 hooks ----------------------------------------------------------
101
+
102
+
103
+ def get_requires_for_build_sdist(config_settings=None):
104
+ return []
105
+
106
+
107
+ def get_requires_for_build_wheel(config_settings=None):
108
+ return []
109
+
110
+
111
+ def build_sdist(sdist_directory, config_settings=None):
112
+ info = _info()
113
+ base = f"{NAME}-{info['pypi_version']}"
114
+ entries = [("PKG-INFO", _metadata(info).encode("utf-8"), 0o644)]
115
+ for name in SOURCE_FILES:
116
+ path = ROOT / name
117
+ if not path.exists():
118
+ raise RuntimeError(f"{name} is missing from {ROOT}; run `prepare` first")
119
+ entries.append((name, path.read_bytes(), 0o644))
120
+ for d in SOURCE_DIRS:
121
+ for path in sorted((ROOT / d).glob("*.py")):
122
+ entries.append((f"{d}/{path.name}", path.read_bytes(), 0o644))
123
+
124
+ filename = f"{base}.tar.gz"
125
+ target = Path(sdist_directory) / filename
126
+ with open(target, "wb") as raw, gzip.GzipFile(
127
+ filename="", fileobj=raw, mode="wb", mtime=EPOCH_SECONDS
128
+ ) as gz, tarfile.open(fileobj=gz, mode="w", format=tarfile.PAX_FORMAT) as tf:
129
+ for name, data, mode in entries:
130
+ ti = tarfile.TarInfo(f"{base}/{name}")
131
+ ti.size = len(data)
132
+ ti.mode = mode
133
+ ti.mtime = EPOCH_SECONDS
134
+ tf.addfile(ti, io.BytesIO(data))
135
+ return filename
136
+
137
+
138
+ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
139
+ info = _info()
140
+ dist_info = Path(metadata_directory) / _dist_info(info)
141
+ dist_info.mkdir(parents=True, exist_ok=True)
142
+ (dist_info / "METADATA").write_text(_metadata(info), encoding="utf-8")
143
+ (dist_info / "WHEEL").write_text(_wheel_file(lib.wheel_tag()))
144
+ shutil.copyfile(ROOT / "LICENSE", dist_info / "LICENSE")
145
+ return dist_info.name
146
+
147
+
148
+ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
149
+ info = _info()
150
+ plat = lib.detect_platform(sys.platform, platform.machine())
151
+ tag = lib.wheel_tag()
152
+ dist_info = _dist_info(info)
153
+ data_scripts = f"{NAME}-{info['pypi_version']}.data/scripts"
154
+ filename = f"{NAME}-{info['pypi_version']}-{tag}.whl"
155
+
156
+ with tempfile.TemporaryDirectory() as tmp:
157
+ binary = lib.fetch_binary(info, plat, Path(tmp) / "bin")
158
+ staged = Path(tmp) / filename
159
+ with _WheelWriter(staged) as whl:
160
+ for path in sorted((ROOT / "quarto2").glob("*.py")):
161
+ whl.add(f"quarto2/{path.name}", path.read_bytes())
162
+ whl.add_file(f"{data_scripts}/{binary.name}", binary, mode=0o755)
163
+ whl.add(f"{dist_info}/METADATA", _metadata(info).encode("utf-8"))
164
+ whl.add(f"{dist_info}/WHEEL", _wheel_file(tag).encode())
165
+ whl.add(f"{dist_info}/LICENSE", (ROOT / "LICENSE").read_bytes())
166
+ whl.finish(f"{dist_info}/RECORD")
167
+ # Move into place only once complete, so a failure leaves nothing.
168
+ shutil.move(str(staged), os.path.join(wheel_directory, filename))
169
+ return filename
170
+
171
+
172
+ class _WheelWriter:
173
+ """A zip writer that keeps the RECORD rows for what it writes."""
174
+
175
+ def __init__(self, path):
176
+ self.zf = zipfile.ZipFile(path, "w", compression=zipfile.ZIP_DEFLATED)
177
+ self.records = []
178
+
179
+ def __enter__(self):
180
+ return self
181
+
182
+ def __exit__(self, *exc):
183
+ self.zf.close()
184
+ return False
185
+
186
+ def _zipinfo(self, name, mode):
187
+ zi = zipfile.ZipInfo(name, date_time=EPOCH)
188
+ zi.external_attr = (0o100000 | mode) << 16
189
+ zi.compress_type = zipfile.ZIP_DEFLATED
190
+ return zi
191
+
192
+ @staticmethod
193
+ def _digest(h):
194
+ return "sha256=" + base64.urlsafe_b64encode(h.digest()).rstrip(b"=").decode()
195
+
196
+ def add(self, name, data, mode=0o644):
197
+ self.zf.writestr(self._zipinfo(name, mode), data)
198
+ self.records.append((name, self._digest(hashlib.sha256(data)), str(len(data))))
199
+
200
+ def add_file(self, name, path, mode=0o644):
201
+ # Stream: the binary is ~190 MB, so avoid holding it in memory.
202
+ h = hashlib.sha256()
203
+ size = 0
204
+ with open(path, "rb") as src, self.zf.open(self._zipinfo(name, mode), "w") as dst:
205
+ for chunk in iter(lambda: src.read(1 << 20), b""):
206
+ h.update(chunk)
207
+ size += len(chunk)
208
+ dst.write(chunk)
209
+ self.records.append((name, self._digest(h), str(size)))
210
+
211
+ def finish(self, record_name):
212
+ buf = io.StringIO()
213
+ writer = csv.writer(buf, lineterminator="\n")
214
+ writer.writerows(self.records)
215
+ writer.writerow((record_name, "", ""))
216
+ self.zf.writestr(self._zipinfo(record_name, 0o644), buf.getvalue())
@@ -0,0 +1,238 @@
1
+ """Helpers for the quarto2 PyPI package (bd-2p7dwmqe).
2
+
3
+ The quarto2 sdist carries no binary. When pip or uv builds it into a
4
+ wheel, the in-tree backend (q2_pypi_backend.py) uses these helpers to
5
+ download this host's q2 archive from the GitHub Release, check it against
6
+ the SHA-256 pinned in the sdist's release.json, and place the binary in
7
+ the wheel's scripts directory.
8
+
9
+ Stdlib only: this runs inside the build frontend's isolated environment,
10
+ which has nothing installed (pyproject.toml declares `requires = []`).
11
+
12
+ Also a small CLI used by .github/workflows/publish-pypi.yml:
13
+
14
+ python -I q2_pypi_lib.py prepare --tag v0.45.0 \\
15
+ --checksums checksums.sha256 --license ../../LICENSE [--post N]
16
+
17
+ writes release.json and LICENSE next to pyproject.toml. Both files are
18
+ generated and gitignored.
19
+ """
20
+
21
+ import argparse
22
+ import hashlib
23
+ import json
24
+ import os
25
+ import re
26
+ import shutil
27
+ import sys
28
+ import sysconfig
29
+ import tarfile
30
+ import tempfile
31
+ import urllib.request
32
+ import zipfile
33
+ from pathlib import Path
34
+
35
+ DEFAULT_DOWNLOAD_BASE = "https://github.com/quarto-dev/q2/releases/download"
36
+ DOWNLOAD_BASE_ENV = "QUARTO2_DOWNLOAD_BASE"
37
+
38
+ PLATFORMS = (
39
+ "darwin_amd64",
40
+ "darwin_arm64",
41
+ "linux_amd64",
42
+ "linux_arm64",
43
+ "windows_amd64",
44
+ "windows_arm64",
45
+ )
46
+
47
+ _OS = {"linux": "linux", "darwin": "darwin", "win32": "windows"}
48
+ _ARCH = {
49
+ "x86_64": "amd64",
50
+ "amd64": "amd64",
51
+ "aarch64": "arm64",
52
+ "arm64": "arm64",
53
+ }
54
+
55
+
56
+ class UnsupportedPlatform(Exception):
57
+ pass
58
+
59
+
60
+ class ChecksumMismatch(Exception):
61
+ pass
62
+
63
+
64
+ def detect_platform(sys_platform, machine):
65
+ """Map `sys.platform` and `platform.machine()` to a release platform name.
66
+
67
+ Linux needs no libc check: the release's linux binaries are static musl.
68
+ """
69
+ os_name = _OS.get(sys_platform)
70
+ arch = _ARCH.get(machine.lower())
71
+ if os_name is None or arch is None:
72
+ raise UnsupportedPlatform(
73
+ f"q2 publishes no binary for this platform "
74
+ f"(sys.platform={sys_platform!r}, machine={machine!r}). "
75
+ f"Build it from source instead: "
76
+ f"https://github.com/quarto-dev/q2#installation (install.sh --from-source)."
77
+ )
78
+ return f"{os_name}_{arch}"
79
+
80
+
81
+ def archive_name(version, platform_name):
82
+ ext = "zip" if platform_name.startswith("windows") else "tar.gz"
83
+ return f"q2-{version}-{platform_name}.{ext}"
84
+
85
+
86
+ def binary_name(platform_name):
87
+ return "q2.exe" if platform_name.startswith("windows") else "q2"
88
+
89
+
90
+ _CARGO_VERSION = re.compile(
91
+ r"^(\d+\.\d+\.\d+)(?:-(alpha|beta|rc)\.?(\d+))?$"
92
+ )
93
+ _PRE = {"alpha": "a", "beta": "b", "rc": "rc"}
94
+
95
+
96
+ def pep440_version(cargo_version):
97
+ """Cargo `X.Y.Z[-rcN]` → PEP 440. Nightlies are never published."""
98
+ m = _CARGO_VERSION.match(cargo_version)
99
+ if not m:
100
+ raise ValueError(f"not a publishable q2 version: {cargo_version!r}")
101
+ base, pre, num = m.groups()
102
+ return base + (f"{_PRE[pre]}{num}" if pre else "")
103
+
104
+
105
+ def release_info_from_checksums(tag, checksums_text, post=0):
106
+ """Build the release.json payload from a release's checksums.sha256."""
107
+ if not tag.startswith("v"):
108
+ raise ValueError(f"release tags start with 'v': {tag!r}")
109
+ version = tag[1:]
110
+ pypi_version = pep440_version(version) + (f".post{post}" if post else "")
111
+ digests = {}
112
+ for line in checksums_text.splitlines():
113
+ if not line.strip():
114
+ continue
115
+ parts = line.split()
116
+ if len(parts) != 2 or not re.fullmatch(r"[0-9a-f]{64}", parts[0]):
117
+ raise ValueError(f"malformed checksums line: {line!r}")
118
+ digests[parts[1].lstrip("*")] = parts[0]
119
+ assets = {}
120
+ missing = []
121
+ for plat in PLATFORMS:
122
+ name = archive_name(version, plat)
123
+ if name in digests:
124
+ assets[plat] = {"name": name, "sha256": digests[name]}
125
+ else:
126
+ missing.append(plat)
127
+ if missing:
128
+ raise ValueError(f"checksums for {tag} lack platforms: {', '.join(missing)}")
129
+ return {
130
+ "tag": tag,
131
+ "version": version,
132
+ "pypi_version": pypi_version,
133
+ "assets": assets,
134
+ }
135
+
136
+
137
+ def prepare(pypi_dir, tag, checksums_text, license_path, post=0):
138
+ """Write release.json and LICENSE into the package directory."""
139
+ pypi_dir = Path(pypi_dir)
140
+ info = release_info_from_checksums(tag, checksums_text, post=post)
141
+ (pypi_dir / "release.json").write_text(json.dumps(info, indent=2) + "\n")
142
+ shutil.copyfile(license_path, pypi_dir / "LICENSE")
143
+ return info
144
+
145
+
146
+ def download_url(tag, name):
147
+ base = os.environ.get(DOWNLOAD_BASE_ENV) or DEFAULT_DOWNLOAD_BASE
148
+ return f"{base.rstrip('/')}/{tag}/{name}"
149
+
150
+
151
+ def download(url, dest):
152
+ with urllib.request.urlopen(url) as resp, open(dest, "wb") as out:
153
+ shutil.copyfileobj(resp, out, length=1 << 20)
154
+
155
+
156
+ def sha256_file(path):
157
+ h = hashlib.sha256()
158
+ with open(path, "rb") as f:
159
+ for chunk in iter(lambda: f.read(1 << 20), b""):
160
+ h.update(chunk)
161
+ return h.hexdigest()
162
+
163
+
164
+ def verify_sha256(path, expected):
165
+ actual = sha256_file(path)
166
+ if actual != expected:
167
+ raise ChecksumMismatch(
168
+ f"{Path(path).name}: expected sha256 {expected}, got {actual}"
169
+ )
170
+
171
+
172
+ def extract_binary(archive, platform_name, dest_dir):
173
+ """Extract the single q2 binary from a release archive.
174
+
175
+ Release archives hold exactly one regular file, the binary. Anything
176
+ else (extra members, links, paths) is refused rather than skipped.
177
+ """
178
+ member = binary_name(platform_name)
179
+ dest_dir = Path(dest_dir)
180
+ dest_dir.mkdir(parents=True, exist_ok=True)
181
+ out = dest_dir / member
182
+ if platform_name.startswith("windows"):
183
+ with zipfile.ZipFile(archive) as zf:
184
+ names = zf.namelist()
185
+ if names != [member]:
186
+ raise ValueError(f"unexpected archive contents: {names}")
187
+ with zf.open(member) as src, open(out, "wb") as dst:
188
+ shutil.copyfileobj(src, dst)
189
+ else:
190
+ with tarfile.open(archive, "r:gz") as tf:
191
+ members = tf.getmembers()
192
+ if [m.name for m in members] != [member] or not members[0].isfile():
193
+ raise ValueError(
194
+ f"unexpected archive contents: {[m.name for m in members]}"
195
+ )
196
+ with tf.extractfile(members[0]) as src, open(out, "wb") as dst:
197
+ shutil.copyfileobj(src, dst)
198
+ return out
199
+
200
+
201
+ def fetch_binary(info, platform_name, dest_dir):
202
+ """Download, verify and extract this platform's binary from a release."""
203
+ asset = info["assets"][platform_name]
204
+ with tempfile.TemporaryDirectory() as tmp:
205
+ archive = Path(tmp) / asset["name"]
206
+ url = download_url(info["tag"], asset["name"])
207
+ print(f"quarto2: downloading {url}", file=sys.stderr)
208
+ download(url, archive)
209
+ verify_sha256(archive, asset["sha256"])
210
+ return extract_binary(archive, platform_name, dest_dir)
211
+
212
+
213
+ def wheel_tag():
214
+ """`py3-none-<platform>` for this host; never `any`.
215
+
216
+ The wheel a frontend builds from our sdist holds this host's binary,
217
+ so its tag must keep a shared wheel cache from reusing it elsewhere.
218
+ """
219
+ plat = sysconfig.get_platform().replace("-", "_").replace(".", "_")
220
+ return f"py3-none-{plat}"
221
+
222
+
223
+ def _main(argv=None):
224
+ parser = argparse.ArgumentParser(prog="q2_pypi_lib")
225
+ sub = parser.add_subparsers(dest="cmd", required=True)
226
+ p = sub.add_parser("prepare", help="write release.json and LICENSE")
227
+ p.add_argument("--tag", required=True)
228
+ p.add_argument("--checksums", required=True, type=Path)
229
+ p.add_argument("--license", required=True, type=Path)
230
+ p.add_argument("--post", type=int, default=0)
231
+ p.add_argument("--dir", type=Path, default=Path(__file__).resolve().parent.parent)
232
+ args = parser.parse_args(argv)
233
+ info = prepare(args.dir, args.tag, args.checksums.read_text(), args.license, args.post)
234
+ print(json.dumps(info, indent=2))
235
+
236
+
237
+ if __name__ == "__main__":
238
+ _main()
@@ -0,0 +1,10 @@
1
+ # The quarto2 PyPI package (bd-2p7dwmqe). See README.dev.md.
2
+ #
3
+ # The build backend is in-tree and stdlib-only, so building needs no
4
+ # dependencies. Package metadata is written by the backend (version from the
5
+ # generated release.json), which is why there is no [project] table.
6
+
7
+ [build-system]
8
+ requires = []
9
+ build-backend = "q2_pypi_backend"
10
+ backend-path = ["backend"]
@@ -0,0 +1,39 @@
1
+ """The quarto2 Python package: installs the native `q2` binary.
2
+
3
+ The binary itself is installed as a script (bin/q2, or Scripts\\q2.exe on
4
+ Windows), not inside this package. This module only helps Python code
5
+ find it.
6
+ """
7
+
8
+ import shutil
9
+ from importlib import metadata
10
+
11
+ __all__ = ["binary_path", "__version__"]
12
+
13
+ try:
14
+ __version__ = metadata.version("quarto2")
15
+ except metadata.PackageNotFoundError: # running from a source checkout
16
+ __version__ = "0+unknown"
17
+
18
+ _BINARY_NAMES = ("q2", "q2.exe")
19
+
20
+
21
+ def binary_path():
22
+ """Absolute path of the `q2` binary this package installed.
23
+
24
+ Reads the package's own RECORD, so it finds the right binary even when
25
+ another `q2` comes first on PATH. Falls back to PATH lookup.
26
+ """
27
+ try:
28
+ files = metadata.files("quarto2") or []
29
+ except metadata.PackageNotFoundError:
30
+ files = []
31
+ for f in files:
32
+ if f.name in _BINARY_NAMES and "quarto2" not in f.parts[:1]:
33
+ path = f.locate()
34
+ if path.exists():
35
+ return str(path.resolve())
36
+ found = shutil.which("q2")
37
+ if found:
38
+ return found
39
+ raise FileNotFoundError("the q2 binary installed by quarto2 was not found")
@@ -0,0 +1,23 @@
1
+ """`python -m quarto2 ...` runs the installed q2 binary."""
2
+
3
+ import os
4
+ import subprocess
5
+ import sys
6
+
7
+ from quarto2 import binary_path
8
+
9
+
10
+ def main():
11
+ path = binary_path()
12
+ if os.name == "posix":
13
+ # Replace this process: signals, exit status and the terminal go
14
+ # straight to q2.
15
+ os.execv(path, [path, *sys.argv[1:]])
16
+ try:
17
+ sys.exit(subprocess.call([path, *sys.argv[1:]]))
18
+ except KeyboardInterrupt:
19
+ sys.exit(130)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ main()
@@ -0,0 +1,31 @@
1
+ {
2
+ "tag": "v0.45.0",
3
+ "version": "0.45.0",
4
+ "pypi_version": "0.45.0",
5
+ "assets": {
6
+ "darwin_amd64": {
7
+ "name": "q2-0.45.0-darwin_amd64.tar.gz",
8
+ "sha256": "b4855ccc0455639af5ec7f53bb51a718569a4130b685434aa29b5a2094719089"
9
+ },
10
+ "darwin_arm64": {
11
+ "name": "q2-0.45.0-darwin_arm64.tar.gz",
12
+ "sha256": "42a625c95815b7442a53184d3f96c40947199815774aee24645ab50dd1cf543b"
13
+ },
14
+ "linux_amd64": {
15
+ "name": "q2-0.45.0-linux_amd64.tar.gz",
16
+ "sha256": "97a93ae8c75179bb3e4a68554288303b0472a71f91b060f18d6151bdca704b3c"
17
+ },
18
+ "linux_arm64": {
19
+ "name": "q2-0.45.0-linux_arm64.tar.gz",
20
+ "sha256": "665ead6468d2f9e33cb9d4f6ca16fb5260b8f8e9e96a5836a094996c1645645c"
21
+ },
22
+ "windows_amd64": {
23
+ "name": "q2-0.45.0-windows_amd64.zip",
24
+ "sha256": "2e2f8f2f6b2b4f91cdebcef8479cc018eb0d074bf97fd2069b8632be5d98ad23"
25
+ },
26
+ "windows_arm64": {
27
+ "name": "q2-0.45.0-windows_arm64.zip",
28
+ "sha256": "b9cd2133bc0903879653ca027368ef7dadb1cbb5fddbe7d86108ed9f7ef9227f"
29
+ }
30
+ }
31
+ }