webcompy-cli 0.0.14__py3-none-any.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.
- webcompy_cli/__init__.py +20 -0
- webcompy_cli/_argparser.py +232 -0
- webcompy_cli/_browser_probes.py +648 -0
- webcompy_cli/_browser_test_harness.py +554 -0
- webcompy_cli/_build.py +425 -0
- webcompy_cli/_console_types.py +15 -0
- webcompy_cli/_dependency_resolver.py +301 -0
- webcompy_cli/_dualrun_pytest_plugin.py +130 -0
- webcompy_cli/_exception.py +9 -0
- webcompy_cli/_generate.py +224 -0
- webcompy_cli/_init_project.py +54 -0
- webcompy_cli/_inspect.py +741 -0
- webcompy_cli/_inspect_pyexec.py +244 -0
- webcompy_cli/_lock.py +82 -0
- webcompy_cli/_lockfile.py +396 -0
- webcompy_cli/_lockfile_sync.py +343 -0
- webcompy_cli/_output.py +150 -0
- webcompy_cli/_prebuild.py +661 -0
- webcompy_cli/_pwa.py +474 -0
- webcompy_cli/_pyodide_downloader.py +113 -0
- webcompy_cli/_pyodide_lock.py +74 -0
- webcompy_cli/_runtime_downloader.py +222 -0
- webcompy_cli/_server.py +568 -0
- webcompy_cli/_static_files.py +27 -0
- webcompy_cli/_utils.py +72 -0
- webcompy_cli/_version_sweep.py +213 -0
- webcompy_cli/_wheel_builder.py +509 -0
- webcompy_cli/config/__init__.py +23 -0
- webcompy_cli/config/_build_config.py +168 -0
- webcompy_cli/config/_pwa_config.py +203 -0
- webcompy_cli/config/_server_config.py +53 -0
- webcompy_cli/py.typed +0 -0
- webcompy_cli/template_data/app/__init__.py +0 -0
- webcompy_cli/template_data/app/app.py +22 -0
- webcompy_cli/template_data/app/components/__init__.py +0 -0
- webcompy_cli/template_data/app/components/fizzbuzz.py +117 -0
- webcompy_cli/template_data/app/components/home.py +15 -0
- webcompy_cli/template_data/app/components/input.py +34 -0
- webcompy_cli/template_data/app/components/navigation.py +36 -0
- webcompy_cli/template_data/app/components/not_found.py +22 -0
- webcompy_cli/template_data/app/components/root.py +16 -0
- webcompy_cli/template_data/app/router.py +17 -0
- webcompy_cli/template_data/webcompy_config.py +12 -0
- webcompy_cli-0.0.14.dist-info/METADATA +53 -0
- webcompy_cli-0.0.14.dist-info/RECORD +47 -0
- webcompy_cli-0.0.14.dist-info/WHEEL +4 -0
- webcompy_cli-0.0.14.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"""Deterministic wheel building for ``webcompy`` and application packages."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import hashlib
|
|
7
|
+
import os
|
|
8
|
+
import pathlib
|
|
9
|
+
import re
|
|
10
|
+
import zipfile
|
|
11
|
+
from collections.abc import Iterable, Sequence
|
|
12
|
+
|
|
13
|
+
_DETERMINISTIC_DATE_TIME = (1980, 1, 1, 0, 0, 0)
|
|
14
|
+
_DETERMINISTIC_CREATE_SYSTEM = 3
|
|
15
|
+
_DETERMINISTIC_EXTERNAL_ATTR = 0o100644 << 16
|
|
16
|
+
_ALWAYS_PRUNED_DIRS: frozenset[str] = frozenset(
|
|
17
|
+
{"__pycache__", ".git", ".venv", "venv", ".webcompy_modules", ".webcompy-build"}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _is_excluded_dir(
|
|
22
|
+
dir_path: pathlib.Path,
|
|
23
|
+
package_dir: pathlib.Path,
|
|
24
|
+
extra_rel_prefixes: frozenset[str] = frozenset(),
|
|
25
|
+
) -> bool:
|
|
26
|
+
name = dir_path.name
|
|
27
|
+
if name in _ALWAYS_PRUNED_DIRS:
|
|
28
|
+
return True
|
|
29
|
+
if name.startswith(".staging-") or (name.startswith(".") and ".staging-" in name):
|
|
30
|
+
return True
|
|
31
|
+
if extra_rel_prefixes:
|
|
32
|
+
try:
|
|
33
|
+
rel_posix = dir_path.relative_to(package_dir).as_posix()
|
|
34
|
+
except ValueError:
|
|
35
|
+
return False
|
|
36
|
+
return any(rel_posix == prefix or rel_posix.startswith(prefix + "/") for prefix in extra_rel_prefixes)
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _is_inside_excluded_dir(
|
|
41
|
+
filepath: pathlib.Path,
|
|
42
|
+
package_dir: pathlib.Path,
|
|
43
|
+
extra_rel_prefixes: frozenset[str] = frozenset(),
|
|
44
|
+
) -> bool:
|
|
45
|
+
"""Return whether a file resides beneath an excluded directory inside ``package_dir``.
|
|
46
|
+
|
|
47
|
+
Walks ancestor directories within ``package_dir`` so glob-discovered
|
|
48
|
+
``package_data`` files that bypass ``os.walk`` pruning are filtered
|
|
49
|
+
identically to walked package files.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
filepath: Candidate file path to evaluate.
|
|
53
|
+
package_dir: Root directory of the package being scanned.
|
|
54
|
+
extra_rel_prefixes: Optional POSIX directory prefixes relative to
|
|
55
|
+
``package_dir`` that should also be excluded.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
``True`` if any ancestor directory of ``filepath`` inside
|
|
59
|
+
``package_dir`` matches ``_is_excluded_dir()``, otherwise ``False``.
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
try:
|
|
63
|
+
rel = filepath.relative_to(package_dir)
|
|
64
|
+
except ValueError:
|
|
65
|
+
return False
|
|
66
|
+
current = package_dir
|
|
67
|
+
for part in rel.parts[:-1]:
|
|
68
|
+
current = current / part
|
|
69
|
+
if _is_excluded_dir(current, package_dir, extra_rel_prefixes):
|
|
70
|
+
return True
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _write_zip_entry(zf: zipfile.ZipFile, arc_path: str, data: bytes | str) -> None:
|
|
75
|
+
info = zipfile.ZipInfo(arc_path, date_time=_DETERMINISTIC_DATE_TIME)
|
|
76
|
+
info.compress_type = zipfile.ZIP_DEFLATED
|
|
77
|
+
info.create_system = _DETERMINISTIC_CREATE_SYSTEM
|
|
78
|
+
info.external_attr = _DETERMINISTIC_EXTERNAL_ATTR
|
|
79
|
+
zf.writestr(info, data)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _discover_packages(
|
|
83
|
+
package_dir: pathlib.Path,
|
|
84
|
+
exclude_rel_prefixes: Iterable[str] | None = None,
|
|
85
|
+
) -> list[str]:
|
|
86
|
+
packages: set[str] = set()
|
|
87
|
+
if not package_dir.is_dir():
|
|
88
|
+
return []
|
|
89
|
+
extra = frozenset(p.strip("/") for p in (exclude_rel_prefixes or ()) if p.strip("/"))
|
|
90
|
+
for root, dirs, files in os.walk(package_dir):
|
|
91
|
+
root_path = pathlib.Path(root)
|
|
92
|
+
if root_path != package_dir and _is_excluded_dir(root_path, package_dir, extra):
|
|
93
|
+
dirs[:] = []
|
|
94
|
+
continue
|
|
95
|
+
dirs[:] = sorted(d for d in dirs if not _is_excluded_dir(root_path / d, package_dir, extra))
|
|
96
|
+
sorted_files = sorted(files)
|
|
97
|
+
if "__init__.py" in sorted_files:
|
|
98
|
+
rel = root_path.relative_to(package_dir.parent)
|
|
99
|
+
packages.add(str(rel).replace(os.sep, "."))
|
|
100
|
+
elif root_path == package_dir:
|
|
101
|
+
for filename in sorted_files:
|
|
102
|
+
if filename.endswith(".py") and filename != "__init__.py":
|
|
103
|
+
packages.add(filename[:-3])
|
|
104
|
+
return sorted(packages)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _collect_package_files(
|
|
108
|
+
package_dir: pathlib.Path,
|
|
109
|
+
packages: list[str],
|
|
110
|
+
package_data: dict[str, list[str]] | None = None,
|
|
111
|
+
exclude_rel_prefixes: Iterable[str] | None = None,
|
|
112
|
+
) -> list[tuple[pathlib.Path, str]]:
|
|
113
|
+
files: list[tuple[pathlib.Path, str]] = []
|
|
114
|
+
parent = package_dir.parent
|
|
115
|
+
seen: set[str] = set()
|
|
116
|
+
extra = frozenset(p.strip("/") for p in (exclude_rel_prefixes or ()) if p.strip("/"))
|
|
117
|
+
for pkg in packages:
|
|
118
|
+
pkg_rel = pkg.replace(".", os.sep)
|
|
119
|
+
pkg_path = parent / pkg_rel
|
|
120
|
+
single_module_py = pkg_path / f"{pkg}.py"
|
|
121
|
+
if pkg_path.is_dir() and not (pkg_path / "__init__.py").exists():
|
|
122
|
+
if single_module_py.is_file():
|
|
123
|
+
arc_path = f"{pkg}.py"
|
|
124
|
+
if arc_path not in seen:
|
|
125
|
+
seen.add(arc_path)
|
|
126
|
+
files.append((single_module_py, arc_path))
|
|
127
|
+
continue
|
|
128
|
+
if not pkg_path.is_dir():
|
|
129
|
+
continue
|
|
130
|
+
for root, dirs, filenames in os.walk(pkg_path):
|
|
131
|
+
root_path = pathlib.Path(root)
|
|
132
|
+
if root_path != package_dir and _is_excluded_dir(root_path, package_dir, extra):
|
|
133
|
+
dirs[:] = []
|
|
134
|
+
continue
|
|
135
|
+
dirs[:] = sorted(d for d in dirs if not _is_excluded_dir(root_path / d, package_dir, extra))
|
|
136
|
+
for filename in sorted(filenames):
|
|
137
|
+
filepath = root_path / filename
|
|
138
|
+
arc_path = str(filepath.relative_to(parent)).replace(os.sep, "/")
|
|
139
|
+
if arc_path in seen:
|
|
140
|
+
continue
|
|
141
|
+
if filename.endswith((".py", ".pyi", ".css")) or filename == "py.typed":
|
|
142
|
+
seen.add(arc_path)
|
|
143
|
+
files.append((filepath, arc_path))
|
|
144
|
+
if package_data and pkg in package_data:
|
|
145
|
+
for pattern in package_data[pkg]:
|
|
146
|
+
data_pkg_rel = pkg.replace(".", os.sep)
|
|
147
|
+
for filepath in sorted(pathlib.Path(parent / data_pkg_rel).glob(pattern)):
|
|
148
|
+
if filepath.is_file() and not _is_inside_excluded_dir(filepath, package_dir, extra):
|
|
149
|
+
arc_path = str(filepath.relative_to(parent)).replace(os.sep, "/")
|
|
150
|
+
if arc_path not in seen:
|
|
151
|
+
seen.add(arc_path)
|
|
152
|
+
files.append((filepath, arc_path))
|
|
153
|
+
return sorted(files, key=lambda item: item[1])
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _sha256_b64(data: bytes) -> str:
|
|
157
|
+
digest = hashlib.sha256(data).digest()
|
|
158
|
+
return "sha256=" + base64.urlsafe_b64encode(digest).rstrip(b"=").decode("ascii")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _normalize_name(name: str) -> str:
|
|
162
|
+
return re.sub(r"[-_.]+", "_", name).lower()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def get_wheel_filename(name: str, version: str) -> str:
|
|
166
|
+
"""Return the PEP 427 wheel filename for a pure-Python distribution.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
name: Distribution name before PEP 427 normalization.
|
|
170
|
+
version: Distribution version string.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
Normalized wheel filename ending in ``-py3-none-any.whl``.
|
|
174
|
+
|
|
175
|
+
"""
|
|
176
|
+
return f"{_normalize_name(name)}-{version}-py3-none-any.whl"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _write_metadata(name: str, version: str) -> str:
|
|
180
|
+
return f"Metadata-Version: 2.4\nName: {name}\nVersion: {version}\n"
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _write_wheel() -> str:
|
|
184
|
+
return "Wheel-Version: 1.0\nGenerator: webcompy\nRoot-Is-Purelib: true\nTag: py3-none-any\n"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _write_record(
|
|
188
|
+
entries: list[tuple[str, str, int]],
|
|
189
|
+
dist_info: str,
|
|
190
|
+
) -> str:
|
|
191
|
+
lines: list[str] = []
|
|
192
|
+
for arc_path, hash_val, size in entries:
|
|
193
|
+
lines.append(f"{arc_path},{hash_val},{size}")
|
|
194
|
+
record_path = f"{dist_info}/RECORD"
|
|
195
|
+
lines.append(f"{record_path},,")
|
|
196
|
+
return "\n".join(lines) + "\n"
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _compute_canonical_wheel_hash(
|
|
200
|
+
dist_name: str,
|
|
201
|
+
payload_entries: Sequence[tuple[str, bytes]],
|
|
202
|
+
top_levels: Iterable[str],
|
|
203
|
+
wheel_content: bytes,
|
|
204
|
+
) -> str:
|
|
205
|
+
"""Compute an 8-character content digest from canonical wheel inputs.
|
|
206
|
+
|
|
207
|
+
The hash inputs, field order, and uniform length-prefixed framing
|
|
208
|
+
(``tag || NUL || 8-byte big-endian length || data``) are frozen;
|
|
209
|
+
changing them rotates all ``0+sha.<hash8>`` wheel filenames. Inputs
|
|
210
|
+
are normalized by deduplicating and sorting ``top_levels`` and
|
|
211
|
+
lexicographically sorting ``payload_entries`` by archive path.
|
|
212
|
+
``METADATA`` (which embeds the derived version) and ``RECORD`` are
|
|
213
|
+
intentionally excluded to avoid hash circularity.
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
dist_name: Normalized PEP 427 distribution name.
|
|
217
|
+
payload_entries: Sequence of ``(arc_path, raw_bytes)`` payload entries.
|
|
218
|
+
top_levels: Discovered top-level package/module names.
|
|
219
|
+
wheel_content: Raw UTF-8 bytes of the ``.dist-info/WHEEL`` file.
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
First 8 lowercase hexadecimal characters of the SHA-256 digest.
|
|
223
|
+
|
|
224
|
+
"""
|
|
225
|
+
sorted_entries = sorted(payload_entries, key=lambda item: item[0])
|
|
226
|
+
top_level_bytes = ("\n".join(sorted(set(top_levels))) + "\n").encode("utf-8")
|
|
227
|
+
|
|
228
|
+
digest = hashlib.sha256()
|
|
229
|
+
|
|
230
|
+
def _feed(tag: bytes, data: bytes) -> None:
|
|
231
|
+
digest.update(tag)
|
|
232
|
+
digest.update(b"\x00")
|
|
233
|
+
digest.update(len(data).to_bytes(8, "big"))
|
|
234
|
+
digest.update(data)
|
|
235
|
+
|
|
236
|
+
_feed(b"dist_name", dist_name.encode("utf-8"))
|
|
237
|
+
_feed(b"wheel", wheel_content)
|
|
238
|
+
_feed(b"top_level", top_level_bytes)
|
|
239
|
+
_feed(b"entry_count", len(sorted_entries).to_bytes(8, "big"))
|
|
240
|
+
for arc_path, content in sorted_entries:
|
|
241
|
+
_feed(b"arc_path", arc_path.encode("utf-8"))
|
|
242
|
+
_feed(b"content", content)
|
|
243
|
+
return digest.hexdigest()[:8]
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _write_wheel_archive(
|
|
247
|
+
wheel_path: pathlib.Path,
|
|
248
|
+
name: str,
|
|
249
|
+
version: str,
|
|
250
|
+
payload_entries: Sequence[tuple[str, bytes]],
|
|
251
|
+
top_levels: Iterable[str],
|
|
252
|
+
) -> pathlib.Path:
|
|
253
|
+
"""Write a PEP 427 pure-Python wheel archive in a single deterministic pass.
|
|
254
|
+
|
|
255
|
+
Payload entries are sorted lexicographically by archive path and written
|
|
256
|
+
before ``{dist_info}/METADATA``, ``{dist_info}/WHEEL``,
|
|
257
|
+
``{dist_info}/top_level.txt``, and ``{dist_info}/RECORD``, with normalized
|
|
258
|
+
``ZipInfo`` metadata (``date_time``, ``create_system``, ``external_attr``).
|
|
259
|
+
|
|
260
|
+
Args:
|
|
261
|
+
wheel_path: Destination path for the generated ``.whl`` archive.
|
|
262
|
+
name: Distribution name written into metadata and ``.dist-info`` paths.
|
|
263
|
+
version: Distribution version written into metadata and ``.dist-info``.
|
|
264
|
+
payload_entries: Sequence of ``(arc_path, raw_bytes)`` payload entries.
|
|
265
|
+
top_levels: Discovered top-level package/module names written sorted and
|
|
266
|
+
deduplicated into ``top_level.txt``.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
Path to the written ``.whl`` archive.
|
|
270
|
+
|
|
271
|
+
"""
|
|
272
|
+
dist_name = _normalize_name(name)
|
|
273
|
+
dist_info = f"{dist_name}-{version}.dist-info"
|
|
274
|
+
sorted_entries = sorted(payload_entries, key=lambda item: item[0])
|
|
275
|
+
|
|
276
|
+
if wheel_path.exists():
|
|
277
|
+
os.remove(wheel_path)
|
|
278
|
+
|
|
279
|
+
metadata_bytes = _write_metadata(name, version).encode("utf-8")
|
|
280
|
+
wheel_bytes = _write_wheel().encode("utf-8")
|
|
281
|
+
top_level_bytes = ("\n".join(sorted(set(top_levels))) + "\n").encode("utf-8")
|
|
282
|
+
|
|
283
|
+
metadata_path = f"{dist_info}/METADATA"
|
|
284
|
+
wheel_meta_path = f"{dist_info}/WHEEL"
|
|
285
|
+
top_level_path = f"{dist_info}/top_level.txt"
|
|
286
|
+
|
|
287
|
+
record_entries: list[tuple[str, str, int]] = []
|
|
288
|
+
with zipfile.ZipFile(wheel_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
289
|
+
for arc_path, data in sorted_entries:
|
|
290
|
+
_write_zip_entry(zf, arc_path, data)
|
|
291
|
+
record_entries.append((arc_path, _sha256_b64(data), len(data)))
|
|
292
|
+
|
|
293
|
+
for arc_path, data in (
|
|
294
|
+
(metadata_path, metadata_bytes),
|
|
295
|
+
(wheel_meta_path, wheel_bytes),
|
|
296
|
+
(top_level_path, top_level_bytes),
|
|
297
|
+
):
|
|
298
|
+
_write_zip_entry(zf, arc_path, data)
|
|
299
|
+
record_entries.append((arc_path, _sha256_b64(data), len(data)))
|
|
300
|
+
|
|
301
|
+
record_content = _write_record(record_entries, dist_info)
|
|
302
|
+
_write_zip_entry(zf, f"{dist_info}/RECORD", record_content)
|
|
303
|
+
|
|
304
|
+
return wheel_path
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _collect_multi_package_payload(
|
|
308
|
+
package_dirs: Sequence[tuple[str, pathlib.Path]],
|
|
309
|
+
package_data: dict[str, list[str]] | None = None,
|
|
310
|
+
extra_files: Sequence[tuple[str, bytes]] | None = None,
|
|
311
|
+
exclude_target_name: str | None = None,
|
|
312
|
+
exclude_rel_prefixes: Iterable[str] | None = None,
|
|
313
|
+
) -> tuple[list[tuple[str, bytes]], set[str]]:
|
|
314
|
+
"""Collect deduplicated payload bytes and top-level names across multiple packages.
|
|
315
|
+
|
|
316
|
+
Traverses ``package_dirs`` in caller order followed by ``extra_files`` with
|
|
317
|
+
first-wins deduplication by archive path, scopes ``exclude_rel_prefixes``
|
|
318
|
+
only to the package matching ``exclude_target_name``, and returns payload
|
|
319
|
+
entries sorted lexicographically by POSIX archive path.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
package_dirs: Sequence of ``(package_name, package_dir)`` pairs.
|
|
323
|
+
package_data: Optional mapping of dotted package names to data file glob
|
|
324
|
+
patterns.
|
|
325
|
+
extra_files: Optional ``(archive_path, raw_bytes)`` entries to include.
|
|
326
|
+
exclude_target_name: Package name to which ``exclude_rel_prefixes`` is
|
|
327
|
+
scoped; when ``None``, no prefix exclusion is applied.
|
|
328
|
+
exclude_rel_prefixes: Optional package-relative directory prefixes to
|
|
329
|
+
exclude when traversing ``exclude_target_name``.
|
|
330
|
+
|
|
331
|
+
Returns:
|
|
332
|
+
Tuple of ``(payload_entries, top_levels)`` where ``payload_entries`` is
|
|
333
|
+
a sorted list of ``(arc_path, raw_bytes)`` pairs and ``top_levels`` is
|
|
334
|
+
the set of discovered top-level package names.
|
|
335
|
+
|
|
336
|
+
"""
|
|
337
|
+
top_levels: set[str] = set()
|
|
338
|
+
payload_entries: list[tuple[str, bytes]] = []
|
|
339
|
+
seen: set[str] = set()
|
|
340
|
+
for pkg_name, pkg_dir in package_dirs:
|
|
341
|
+
rel_excludes = (
|
|
342
|
+
exclude_rel_prefixes if exclude_target_name is not None and pkg_name == exclude_target_name else None
|
|
343
|
+
)
|
|
344
|
+
packages = _discover_packages(pkg_dir, exclude_rel_prefixes=rel_excludes)
|
|
345
|
+
files = _collect_package_files(pkg_dir, packages, package_data, exclude_rel_prefixes=rel_excludes)
|
|
346
|
+
for filepath, arc_path in files:
|
|
347
|
+
if arc_path not in seen:
|
|
348
|
+
seen.add(arc_path)
|
|
349
|
+
payload_entries.append((arc_path, filepath.read_bytes()))
|
|
350
|
+
for pkg in packages:
|
|
351
|
+
top_levels.add(pkg.split(".")[0])
|
|
352
|
+
|
|
353
|
+
if extra_files:
|
|
354
|
+
for arc_path, content in extra_files:
|
|
355
|
+
if arc_path not in seen:
|
|
356
|
+
seen.add(arc_path)
|
|
357
|
+
payload_entries.append((arc_path, content))
|
|
358
|
+
|
|
359
|
+
payload_entries.sort(key=lambda item: item[0])
|
|
360
|
+
return payload_entries, top_levels
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def make_browser_webcompy_wheel(
|
|
364
|
+
webcompy_package_dir: pathlib.Path,
|
|
365
|
+
dest: pathlib.Path,
|
|
366
|
+
version: str,
|
|
367
|
+
) -> pathlib.Path:
|
|
368
|
+
"""Build a content-hashed browser wheel for the core ``webcompy`` package.
|
|
369
|
+
|
|
370
|
+
Args:
|
|
371
|
+
webcompy_package_dir: Root directory of the ``webcompy`` package.
|
|
372
|
+
dest: Output directory where the wheel archive will be written.
|
|
373
|
+
version: Caller version parameter kept for signature compatibility;
|
|
374
|
+
unused because the emitted version is derived canonically from
|
|
375
|
+
wheel contents.
|
|
376
|
+
|
|
377
|
+
Returns:
|
|
378
|
+
Path to the created ``webcompy-0+sha.<hash8>-py3-none-any.whl`` file.
|
|
379
|
+
|
|
380
|
+
"""
|
|
381
|
+
_ = version
|
|
382
|
+
packages = _discover_packages(webcompy_package_dir)
|
|
383
|
+
files = _collect_package_files(webcompy_package_dir, packages)
|
|
384
|
+
payload_entries = sorted(
|
|
385
|
+
((arc_path, filepath.read_bytes()) for filepath, arc_path in files), key=lambda item: item[0]
|
|
386
|
+
)
|
|
387
|
+
top_levels = {pkg.split(".")[0] for pkg in packages}
|
|
388
|
+
digest = _compute_canonical_wheel_hash(
|
|
389
|
+
_normalize_name("webcompy"),
|
|
390
|
+
payload_entries,
|
|
391
|
+
top_levels,
|
|
392
|
+
_write_wheel().encode("utf-8"),
|
|
393
|
+
)
|
|
394
|
+
hash_version = f"0+sha.{digest}"
|
|
395
|
+
wheel_path = dest / get_wheel_filename("webcompy", hash_version)
|
|
396
|
+
return _write_wheel_archive(wheel_path, "webcompy", hash_version, payload_entries, top_levels)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def make_wheel(
|
|
400
|
+
name: str,
|
|
401
|
+
package_dir: pathlib.Path,
|
|
402
|
+
dest: pathlib.Path,
|
|
403
|
+
version: str,
|
|
404
|
+
package_data: dict[str, list[str]] | None = None,
|
|
405
|
+
) -> pathlib.Path:
|
|
406
|
+
"""Build a PEP 427 wheel for a single package with an explicit version.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
name: Distribution name for the generated wheel.
|
|
410
|
+
package_dir: Root directory of the Python package.
|
|
411
|
+
dest: Output directory where the wheel archive will be written.
|
|
412
|
+
version: Distribution version string embedded in metadata and filename.
|
|
413
|
+
package_data: Optional mapping of dotted package names to glob patterns
|
|
414
|
+
of additional data files to include.
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
Path to the created ``.whl`` file.
|
|
418
|
+
|
|
419
|
+
"""
|
|
420
|
+
packages = _discover_packages(package_dir)
|
|
421
|
+
files = _collect_package_files(package_dir, packages, package_data)
|
|
422
|
+
payload_entries = [(arc_path, filepath.read_bytes()) for filepath, arc_path in files]
|
|
423
|
+
top_levels = {pkg.split(".")[0] for pkg in packages}
|
|
424
|
+
wheel_path = dest / get_wheel_filename(name, version)
|
|
425
|
+
return _write_wheel_archive(wheel_path, name, version, payload_entries, top_levels)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def make_bundled_wheel(
|
|
429
|
+
name: str,
|
|
430
|
+
package_dirs: list[tuple[str, pathlib.Path]],
|
|
431
|
+
dest: pathlib.Path,
|
|
432
|
+
version: str,
|
|
433
|
+
package_data: dict[str, list[str]] | None = None,
|
|
434
|
+
extra_files: list[tuple[str, bytes]] | None = None,
|
|
435
|
+
) -> pathlib.Path:
|
|
436
|
+
"""Build a PEP 427 wheel bundling multiple packages and extra files.
|
|
437
|
+
|
|
438
|
+
Args:
|
|
439
|
+
name: Distribution name for the bundled wheel.
|
|
440
|
+
package_dirs: Sequence of ``(package_name, package_dir)`` pairs.
|
|
441
|
+
dest: Output directory where the wheel archive will be written.
|
|
442
|
+
version: Distribution version string embedded in metadata and filename.
|
|
443
|
+
package_data: Optional mapping of dotted package names to data globs.
|
|
444
|
+
extra_files: Optional ``(archive_path, raw_bytes)`` entries to bundle.
|
|
445
|
+
|
|
446
|
+
Returns:
|
|
447
|
+
Path to the created ``.whl`` file.
|
|
448
|
+
|
|
449
|
+
"""
|
|
450
|
+
payload_entries, top_levels = _collect_multi_package_payload(
|
|
451
|
+
package_dirs,
|
|
452
|
+
package_data=package_data,
|
|
453
|
+
extra_files=extra_files,
|
|
454
|
+
)
|
|
455
|
+
wheel_path = dest / get_wheel_filename(name, version)
|
|
456
|
+
return _write_wheel_archive(wheel_path, name, version, payload_entries, top_levels)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def make_webcompy_app_package(
|
|
460
|
+
dest: pathlib.Path,
|
|
461
|
+
webcompy_package_dir: pathlib.Path,
|
|
462
|
+
package_dir: pathlib.Path,
|
|
463
|
+
app_version: str,
|
|
464
|
+
bundled_deps: list[tuple[str, pathlib.Path]] | None = None,
|
|
465
|
+
skip_webcompy: bool = False,
|
|
466
|
+
exclude_rel_prefixes: Iterable[str] | None = None,
|
|
467
|
+
) -> pathlib.Path:
|
|
468
|
+
"""Build a content-hashed application wheel for browser deployment.
|
|
469
|
+
|
|
470
|
+
Args:
|
|
471
|
+
dest: Output directory where the wheel archive will be written.
|
|
472
|
+
webcompy_package_dir: Root directory of the core ``webcompy`` package.
|
|
473
|
+
package_dir: Root directory of the user application package.
|
|
474
|
+
app_version: Caller version parameter kept for signature compatibility;
|
|
475
|
+
unused because the emitted version is derived canonically from
|
|
476
|
+
wheel contents.
|
|
477
|
+
bundled_deps: Optional pure-Python dependencies as ``(name, path)`` pairs.
|
|
478
|
+
skip_webcompy: When ``True``, omit the core ``webcompy`` package (split mode).
|
|
479
|
+
exclude_rel_prefixes: Optional app-package-relative directory prefixes to
|
|
480
|
+
exclude from package discovery and file collection.
|
|
481
|
+
|
|
482
|
+
Returns:
|
|
483
|
+
Path to the created ``{app}-0+sha.<hash8>-py3-none-any.whl`` file.
|
|
484
|
+
|
|
485
|
+
"""
|
|
486
|
+
_ = app_version
|
|
487
|
+
app_name = package_dir.name
|
|
488
|
+
|
|
489
|
+
package_dirs: list[tuple[str, pathlib.Path]] = []
|
|
490
|
+
if not skip_webcompy:
|
|
491
|
+
package_dirs.append(("webcompy", webcompy_package_dir))
|
|
492
|
+
package_dirs.append((app_name, package_dir))
|
|
493
|
+
if bundled_deps:
|
|
494
|
+
package_dirs.extend(bundled_deps)
|
|
495
|
+
|
|
496
|
+
payload_entries, top_levels = _collect_multi_package_payload(
|
|
497
|
+
package_dirs,
|
|
498
|
+
exclude_target_name=app_name,
|
|
499
|
+
exclude_rel_prefixes=exclude_rel_prefixes,
|
|
500
|
+
)
|
|
501
|
+
digest = _compute_canonical_wheel_hash(
|
|
502
|
+
_normalize_name(app_name),
|
|
503
|
+
payload_entries,
|
|
504
|
+
top_levels,
|
|
505
|
+
_write_wheel().encode("utf-8"),
|
|
506
|
+
)
|
|
507
|
+
hash_version = f"0+sha.{digest}"
|
|
508
|
+
wheel_path = dest / get_wheel_filename(app_name, hash_version)
|
|
509
|
+
return _write_wheel_archive(wheel_path, app_name, hash_version, payload_entries, top_levels)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Configuration dataclasses for build and server settings."""
|
|
2
|
+
|
|
3
|
+
from webcompy_cli.config._build_config import StaticRoute, WebComPyBuildConfig
|
|
4
|
+
from webcompy_cli.config._pwa_config import (
|
|
5
|
+
ManifestConfig,
|
|
6
|
+
ManifestIcon,
|
|
7
|
+
PWAConfig,
|
|
8
|
+
RuntimeCachingRule,
|
|
9
|
+
RuntimeCachingStrategy,
|
|
10
|
+
)
|
|
11
|
+
from webcompy_cli.config._server_config import LockfileSyncConfig, WebComPyServerConfig
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"LockfileSyncConfig",
|
|
15
|
+
"ManifestConfig",
|
|
16
|
+
"ManifestIcon",
|
|
17
|
+
"PWAConfig",
|
|
18
|
+
"RuntimeCachingRule",
|
|
19
|
+
"RuntimeCachingStrategy",
|
|
20
|
+
"StaticRoute",
|
|
21
|
+
"WebComPyBuildConfig",
|
|
22
|
+
"WebComPyServerConfig",
|
|
23
|
+
]
|