echidnae-python 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ella Inng
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,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: echidnae-python
3
+ Version: 0.3.0
4
+ Summary: Verified offline Python application assembly and runtime interfaces
5
+ Author: ellainng
6
+ Author-email: ellainng <299958882+ellainng@users.noreply.github.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3.14
11
+ Requires-Python: >=3.14
12
+ Project-URL: Repository, https://github.com/wispsy/echidnae
13
+ Project-URL: Issues, https://github.com/wispsy/echidnae/issues
14
+ Description-Content-Type: text/markdown
15
+
16
+ # echidnae-python
17
+
18
+ Python 3.14+ tooling for assembling verified offline applications from explicit source and runtime assets. This is the Python interface; the independent JavaScript Python interpreter is distributed as `@echidnae/python` on npm.
19
+
20
+ ```sh
21
+ python -m pip install echidnae-python==0.3.0
22
+ echidnae-python --help
23
+ ```
24
+
25
+ ```python
26
+ from echidnae.python.interpreter import build_interpreter, read_interpreter
27
+ from echidnae.python.compiled import build_compiled, read_client
28
+ ```
29
+
30
+ Runtime assets are supplied explicitly. Compiled applications require `echidnae-javascript==0.3.0` as build tooling. No compiler, interpreter binary or network download is installed implicitly. Existing versioned artifact identifiers are retained for compatibility. See the [application guides](https://github.com/wispsy/echidnae/tree/main/docs) and [migration guide](https://github.com/wispsy/echidnae/blob/main/docs/migration.md).
31
+
32
+ The interpreter remains an alpha implementation with explicit language and library profiles; installation does not certify unrestricted Python or third-party package compatibility. MIT license.
@@ -0,0 +1,17 @@
1
+ # echidnae-python
2
+
3
+ Python 3.14+ tooling for assembling verified offline applications from explicit source and runtime assets. This is the Python interface; the independent JavaScript Python interpreter is distributed as `@echidnae/python` on npm.
4
+
5
+ ```sh
6
+ python -m pip install echidnae-python==0.3.0
7
+ echidnae-python --help
8
+ ```
9
+
10
+ ```python
11
+ from echidnae.python.interpreter import build_interpreter, read_interpreter
12
+ from echidnae.python.compiled import build_compiled, read_client
13
+ ```
14
+
15
+ Runtime assets are supplied explicitly. Compiled applications require `echidnae-javascript==0.3.0` as build tooling. No compiler, interpreter binary or network download is installed implicitly. Existing versioned artifact identifiers are retained for compatibility. See the [application guides](https://github.com/wispsy/echidnae/tree/main/docs) and [migration guide](https://github.com/wispsy/echidnae/blob/main/docs/migration.md).
16
+
17
+ The interpreter remains an alpha implementation with explicit language and library profiles; installation does not certify unrestricted Python or third-party package compatibility. MIT license.
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "echidnae-python"
3
+ version = "0.3.0"
4
+ description = "Verified offline Python application assembly and runtime interfaces"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ dependencies = []
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Programming Language :: Python :: 3.14",
13
+ ]
14
+
15
+ [[project.authors]]
16
+ name = "ellainng"
17
+ email = "299958882+ellainng@users.noreply.github.com"
18
+
19
+ [project.urls]
20
+ Repository = "https://github.com/wispsy/echidnae"
21
+ Issues = "https://github.com/wispsy/echidnae/issues"
22
+
23
+ [project.scripts]
24
+ echidnae-python = "echidnae.python.cli:main"
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.12.19,<0.13.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [tool.uv.build-backend]
31
+ module-name = "echidnae.python"
@@ -0,0 +1,25 @@
1
+ [project]
2
+ name = "echidnae-python"
3
+ version = "0.3.0"
4
+ description = "Verified offline Python application assembly and runtime interfaces"
5
+ readme = "README.md"
6
+ authors = [{ name = "ellainng", email = "299958882+ellainng@users.noreply.github.com" }]
7
+ requires-python = ">=3.14"
8
+ license = "MIT"
9
+ license-files = ["LICENSE"]
10
+ dependencies = []
11
+ classifiers = ["Development Status :: 3 - Alpha", "Programming Language :: Python :: 3.14"]
12
+
13
+ [project.urls]
14
+ Repository = "https://github.com/wispsy/echidnae"
15
+ Issues = "https://github.com/wispsy/echidnae/issues"
16
+
17
+ [project.scripts]
18
+ echidnae-python = "echidnae.python.cli:main"
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.12.19,<0.13.0"]
22
+ build-backend = "uv_build"
23
+
24
+ [tool.uv.build-backend]
25
+ module-name = "echidnae.python"
@@ -0,0 +1,3 @@
1
+ """Auditable runtime assets and offline Python applications."""
2
+
3
+ __version__ = "0.3.0"
@@ -0,0 +1,3 @@
1
+ from echidnae.python.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,23 @@
1
+ """Build-only compiler source identity adopted for compiled-javascript/1."""
2
+
3
+ COMPILER_REVISION = "echidnae-javascript/0.3.0"
4
+ COMPILER_VERSION = "0.3.0"
5
+ COMPILER_FINGERPRINT = 'd5a97426fea9d7620933b44661288a10c50248337ec7861295a342457f63f312'
6
+ COMPILER_FILES = (
7
+ '__init__.py',
8
+ '_array.py',
9
+ '_browser/browser-host.mjs',
10
+ '_browser/browser-protocol.mjs',
11
+ '_browser/browser-worker.mjs',
12
+ '_compiler_runtime.py',
13
+ '_json.py',
14
+ '_math.py',
15
+ '_number.py',
16
+ '_object.py',
17
+ '_string.py',
18
+ '_values.py',
19
+ 'browser.py',
20
+ 'compiler.py',
21
+ 'emitter.py',
22
+ 'modules.py',
23
+ )
@@ -0,0 +1,130 @@
1
+ """Known source-console assets, canonical LF bytes; refresh with scripts/lock_interpreter.py."""
2
+
3
+ ENGINE_FINGERPRINT = 'eee9dce1cd65d4f25d4e0b61f3b265a7223b8bae24802ccb6b2fb7ba7c5c5f0d'
4
+ ENGINE_FILES = (
5
+ ('browser-protocol.mjs', 10966, '85f50d640eaa5324cf62e75f5dc6050186bf167201208d26e84a49efd74bf499'),
6
+ ('bytecode.mjs', 6836, 'e76fabeea879bc1da8016283f7e74df5974479666b100199c2d3c31a53b8ecf4'),
7
+ ('class-policy.mjs', 5575, '9bda2a49af3af82ba0942900855dac785b4b590622af2c926fdc38cc491061c7'),
8
+ ('class-values.mjs', 163846, 'f5729d707129561247d0f542b45654aa95c5c7046693f569368e267c99e85c88'),
9
+ ('dynamic-evaluation.mjs', 6820, '44ad82dae7fa185c524e163440a96db953e800e96baa372249dd5e9d613b9eca'),
10
+ ('dynamic-imports.mjs', 9307, '9996c3f3f7e82cd440cf16244176d37e9456c8dd9bbac2e5ac675cf22497c951'),
11
+ ('dynamic-source.mjs', 7550, 'aed9367c9b981e547ce78dd461de1cc30ffeb39648eb24f51a5b19ab2a4b457d'),
12
+ ('function-bytecode.mjs', 25289, '557fee04912f31df536b2a450d7bc2a1148d64721f7fb45d6e9179476eb0a6a8'),
13
+ ('function-objects.mjs', 14144, 'f3ad2921885613e69444fc9accc9174b7944d1aca0994e15e387eda0eeb2de93'),
14
+ ('functions.mjs', 104200, '19b1133d293877575a7155bfa4d7a7fa332b8810d7e27953a7f31fe996c29871'),
15
+ ('interpreter-host.mjs', 7318, '4afadfd987000afa6221ee73dcd64e9c00a2d13c4324718248d396302a39296d'),
16
+ ('interpreter-worker.mjs', 8855, '324cc23100eb40ef04f2909b805d7abc0c8651b4608b3a61a95470ec7e74e19e'),
17
+ ('lazy-iteration.mjs', 6946, 'd418ea65c1f0ac8a171b560f18b5d341fc2a4c16c410cdd91ada6699d3e5d748'),
18
+ ('library-catalog.mjs', 907, '0adcaae0f6f07b4e1acb22e46493ec99f7247a5828b426c703530d8b2736032c'),
19
+ ('library-selection.mjs', 3661, 'b1e2c756afef5a45a1a71fb09fa284290c8f999a1dfb854f2f536fe183119a8a'),
20
+ ('licenses/CPYTHON.txt', 13804, 'b0e25a78cffb43f4d92de8b61ccfa1f1f98ecbc22330b54b5251e7b6ba010231'),
21
+ ('licenses/POCKET-PYTHON.txt', 1066, '30989a02b7e73aa97c349440d9323d2486033a88a2b37461f3142bbb30515e85'),
22
+ ('licenses/UNICODE.txt', 1995, 'e7a93b009565cfce55919a381437ac4db883e9da2126fa28b91d12732bc53d96'),
23
+ ('memory.mjs', 9742, 'e934db7a46b9c7dd52ad2d848f7bc9d24eb124150ee7dd1fe8d96cdb4227b249'),
24
+ ('module-context.mjs', 9603, 'ca068688e932a6f88d063e3e120223b8ef18925191cdb2e190aecf64c99cb654'),
25
+ ('module-registry.mjs', 10574, '41704e8c0a53c2bd604509b09f640f9c152d9cc00be0d73c58ebe8288c1a92df'),
26
+ ('module-session.mjs', 12883, 'b7b7859d18ecfee53cc79fbb3eb92820eabe0ad67ea97f5d317d5c59bd0619f1'),
27
+ ('native-namespaces.mjs', 222970, '82fe51b162840bae67e65c61de875d6379b3fc15bd8f04f3a0cecf7b0ded42c9'),
28
+ ('numeric.mjs', 16962, 'c6c05590f995d4cd8fbd77eae4cacc85e4604f42de7cfdbfacd66d61939c645a'),
29
+ ('operation-runtime.mjs', 338104, '1d44b17dbb39725d0ffaf4f5030f04d0ce2645a8c2445f1d0905ed790479f900'),
30
+ ('operations.mjs', 62364, '1dd2e6484261fbb44cf2b38a24772cabf83841b8fab2475ab61c2282eb934d4a'),
31
+ ('sorting.mjs', 4000, '31a667c0d866cb2aedb53c91b9ec628b905ebcc60692bb8639868faf36b55cfb'),
32
+ ('source-compiler.mjs', 53702, 'a6ae1dda3acf925555615fe450cb5bfa24be3f8ef61bd21778abe1cbf029c22d'),
33
+ ('source-identifiers.mjs', 25949, '1e4e6a90728a2d9393eb4b2055d4bd759542f4768d1870b508d629c6888e8914'),
34
+ ('source-modules.mjs', 5115, '3f824a8cf79a9ab78c1b817ed1597d114d851748a6b0894a4ac6b4bdbe01cfef'),
35
+ ('source-parser.mjs', 85951, '41d1db4bf4f71f349897b18ecc286f4e6fdb610bbe50b1d2f5444dbea2589d2c'),
36
+ ('source-tokens.mjs', 18604, '6f8b43b5e4466ea0f48dd24c1a50587550ef9ba208c08ead8dd9e92a04bed79f'),
37
+ ('string-printability.mjs', 13287, '355a086a142e06822eff821dd0ac6a2ca70c4e06f4ec659236dc3cea1ddd639f'),
38
+ ('values.mjs', 115730, '1a912e2177aa68952dbbf329c26edee2f8a8c3bb3f52fba756740679f1ffaefa'),
39
+ ('vm.mjs', 6080, '796eaac2848ee7aa2d740797eb2afbdb3e577918866a88a9f25e5adbc55e985d'),
40
+ )
41
+ ENGINE_IMPORTS = (
42
+ ('browser-protocol.mjs', 'library-selection.mjs'),
43
+ ('bytecode.mjs', 'values.mjs'),
44
+ ('class-values.mjs', 'class-policy.mjs'),
45
+ ('class-values.mjs', 'function-bytecode.mjs'),
46
+ ('class-values.mjs', 'function-objects.mjs'),
47
+ ('class-values.mjs', 'native-namespaces.mjs'),
48
+ ('class-values.mjs', 'source-identifiers.mjs'),
49
+ ('class-values.mjs', 'values.mjs'),
50
+ ('dynamic-evaluation.mjs', 'function-bytecode.mjs'),
51
+ ('dynamic-evaluation.mjs', 'function-objects.mjs'),
52
+ ('dynamic-evaluation.mjs', 'operations.mjs'),
53
+ ('dynamic-imports.mjs', 'function-objects.mjs'),
54
+ ('dynamic-imports.mjs', 'operations.mjs'),
55
+ ('dynamic-source.mjs', 'function-bytecode.mjs'),
56
+ ('dynamic-source.mjs', 'function-objects.mjs'),
57
+ ('dynamic-source.mjs', 'operations.mjs'),
58
+ ('dynamic-source.mjs', 'source-compiler.mjs'),
59
+ ('dynamic-source.mjs', 'source-parser.mjs'),
60
+ ('dynamic-source.mjs', 'source-tokens.mjs'),
61
+ ('function-bytecode.mjs', 'bytecode.mjs'),
62
+ ('function-bytecode.mjs', 'function-objects.mjs'),
63
+ ('function-bytecode.mjs', 'source-identifiers.mjs'),
64
+ ('function-bytecode.mjs', 'values.mjs'),
65
+ ('function-objects.mjs', 'class-policy.mjs'),
66
+ ('function-objects.mjs', 'operations.mjs'),
67
+ ('functions.mjs', 'class-policy.mjs'),
68
+ ('functions.mjs', 'class-values.mjs'),
69
+ ('functions.mjs', 'function-bytecode.mjs'),
70
+ ('functions.mjs', 'function-objects.mjs'),
71
+ ('functions.mjs', 'memory.mjs'),
72
+ ('functions.mjs', 'module-context.mjs'),
73
+ ('functions.mjs', 'module-registry.mjs'),
74
+ ('functions.mjs', 'operation-runtime.mjs'),
75
+ ('functions.mjs', 'operations.mjs'),
76
+ ('functions.mjs', 'values.mjs'),
77
+ ('functions.mjs', 'vm.mjs'),
78
+ ('interpreter-host.mjs', 'browser-protocol.mjs'),
79
+ ('interpreter-host.mjs', 'interpreter-worker.mjs'),
80
+ ('interpreter-host.mjs', 'library-selection.mjs'),
81
+ ('interpreter-worker.mjs', 'browser-protocol.mjs'),
82
+ ('interpreter-worker.mjs', 'library-selection.mjs'),
83
+ ('interpreter-worker.mjs', 'module-session.mjs'),
84
+ ('interpreter-worker.mjs', 'source-modules.mjs'),
85
+ ('lazy-iteration.mjs', 'function-objects.mjs'),
86
+ ('lazy-iteration.mjs', 'operations.mjs'),
87
+ ('library-selection.mjs', 'library-catalog.mjs'),
88
+ ('memory.mjs', 'function-objects.mjs'),
89
+ ('memory.mjs', 'values.mjs'),
90
+ ('module-context.mjs', 'function-objects.mjs'),
91
+ ('module-context.mjs', 'memory.mjs'),
92
+ ('module-context.mjs', 'module-registry.mjs'),
93
+ ('module-context.mjs', 'values.mjs'),
94
+ ('module-registry.mjs', 'function-bytecode.mjs'),
95
+ ('module-session.mjs', 'function-objects.mjs'),
96
+ ('module-session.mjs', 'functions.mjs'),
97
+ ('module-session.mjs', 'memory.mjs'),
98
+ ('module-session.mjs', 'module-context.mjs'),
99
+ ('module-session.mjs', 'values.mjs'),
100
+ ('operation-runtime.mjs', 'class-policy.mjs'),
101
+ ('operation-runtime.mjs', 'class-values.mjs'),
102
+ ('operation-runtime.mjs', 'dynamic-evaluation.mjs'),
103
+ ('operation-runtime.mjs', 'dynamic-imports.mjs'),
104
+ ('operation-runtime.mjs', 'dynamic-source.mjs'),
105
+ ('operation-runtime.mjs', 'function-objects.mjs'),
106
+ ('operation-runtime.mjs', 'lazy-iteration.mjs'),
107
+ ('operation-runtime.mjs', 'module-registry.mjs'),
108
+ ('operation-runtime.mjs', 'numeric.mjs'),
109
+ ('operation-runtime.mjs', 'operations.mjs'),
110
+ ('operation-runtime.mjs', 'sorting.mjs'),
111
+ ('operation-runtime.mjs', 'values.mjs'),
112
+ ('operations.mjs', 'class-policy.mjs'),
113
+ ('sorting.mjs', 'operations.mjs'),
114
+ ('source-compiler.mjs', 'class-policy.mjs'),
115
+ ('source-compiler.mjs', 'function-bytecode.mjs'),
116
+ ('source-compiler.mjs', 'source-identifiers.mjs'),
117
+ ('source-compiler.mjs', 'source-parser.mjs'),
118
+ ('source-compiler.mjs', 'source-tokens.mjs'),
119
+ ('source-modules.mjs', 'module-registry.mjs'),
120
+ ('source-modules.mjs', 'source-compiler.mjs'),
121
+ ('source-modules.mjs', 'source-tokens.mjs'),
122
+ ('source-parser.mjs', 'source-tokens.mjs'),
123
+ ('source-tokens.mjs', 'source-identifiers.mjs'),
124
+ ('values.mjs', 'function-objects.mjs'),
125
+ ('values.mjs', 'numeric.mjs'),
126
+ ('values.mjs', 'string-printability.mjs'),
127
+ ('vm.mjs', 'bytecode.mjs'),
128
+ ('vm.mjs', 'memory.mjs'),
129
+ ('vm.mjs', 'values.mjs'),
130
+ )
@@ -0,0 +1,3 @@
1
+ """Reviewed optional library identities; generated without executing library code."""
2
+
3
+ LIBRARY_PROFILES = {'core-only/1': {'id': 'core-only/1', 'modules': [], 'fingerprint': '0658bf184744e21e6a2eb0901a55c5f71e640eb5dbd4f5b5297c83ffd57782c9'}, 'operator/1': {'id': 'operator/1', 'modules': [{'name': 'operator', 'package': False, 'imports': [], 'source': {'path': 'library/operator.py', 'size_bytes': 457, 'sha256': '2a4fea9196b5b9b17a86ce6ac16848bdba765b27671dae3483ae7897ef49f0d7'}, 'notice': {'path': 'licenses/POCKET-PYTHON.txt', 'size_bytes': 1066, 'sha256': '30989a02b7e73aa97c349440d9323d2486033a88a2b37461f3142bbb30515e85'}}], 'fingerprint': '8fae1499faa7ae0fe071de23902082c4a7c979cdc71990d877ca537e941cae40'}}
@@ -0,0 +1,149 @@
1
+ """Read explicit, hashed runtime assets without loading executable code."""
2
+
3
+ from dataclasses import dataclass
4
+ import hashlib
5
+ import json
6
+ from pathlib import Path, PurePosixPath
7
+ import re
8
+ from urllib.parse import urlparse
9
+
10
+
11
+ class ArtifactError(ValueError):
12
+ """An unsupported, changed, or unsafe artifact input."""
13
+
14
+
15
+ def relative_path(value: str) -> str:
16
+ if not isinstance(value, str):
17
+ raise ArtifactError("Artifact paths must be strings.")
18
+ path = PurePosixPath(value)
19
+ reserved = {"CON", "PRN", "AUX", "NUL", *(f"COM{i}" for i in range(1, 10)), *(f"LPT{i}" for i in range(1, 10))}
20
+ if not path.parts or path.is_absolute() or ".." in path.parts or str(path) != value:
21
+ raise ArtifactError(f"Unsafe artifact path: {value!r}")
22
+ for part in path.parts:
23
+ if part.split(".")[0].upper() in reserved or part.endswith((".", " ")) or any(ord(c) < 32 or c in '\\:*?"<>|#%' for c in part):
24
+ raise ArtifactError(f"Nonportable artifact path: {value!r}")
25
+ return value
26
+
27
+
28
+ def read_asset(root: Path, name: str, *, max_bytes: int | None = None) -> bytes:
29
+ relative_path(name)
30
+ current = root
31
+ if root.is_symlink() or not root.is_dir():
32
+ raise ArtifactError("Asset root must be an ordinary directory.")
33
+ for part in PurePosixPath(name).parts:
34
+ current = current / part
35
+ if current.is_symlink():
36
+ raise ArtifactError(f"Symlink asset is unsupported: {name}")
37
+ if not current.is_file() or not current.resolve().is_relative_to(root.resolve()):
38
+ raise ArtifactError(f"Asset is missing or escapes its root: {name}")
39
+ if max_bytes is None:
40
+ return current.read_bytes()
41
+ if type(max_bytes) is not int or max_bytes < 0:
42
+ raise ArtifactError("Asset read limit must be a nonnegative integer.")
43
+ with current.open("rb") as stream:
44
+ data = stream.read(max_bytes + 1)
45
+ if len(data) > max_bytes:
46
+ raise ArtifactError(f"Asset exceeds its read limit: {name}")
47
+ return data
48
+
49
+
50
+ def file_record(name: str, content: bytes) -> dict:
51
+ return {"path": name, "sha256": hashlib.sha256(content).hexdigest(), "size_bytes": len(content)}
52
+
53
+
54
+ def check_names(names):
55
+ seen = set()
56
+ for name in names:
57
+ key = relative_path(name).casefold()
58
+ if key in seen or any(key.startswith(other + "/") or other.startswith(key + "/") for other in seen):
59
+ raise ArtifactError(f"Artifact path collision: {name}")
60
+ seen.add(key)
61
+
62
+
63
+ def verified_files(root: Path, records: list) -> dict[str, bytes]:
64
+ if not isinstance(records, list) or not records:
65
+ raise ArtifactError("Expected a nonempty file record list.")
66
+ if any(not isinstance(record, dict) or not isinstance(record.get("path"), str) for record in records):
67
+ raise ArtifactError("Invalid file record.")
68
+ check_names(record["path"] for record in records)
69
+ files = {}
70
+ for record in records:
71
+ digest, size = record.get("sha256"), record.get("size_bytes")
72
+ if not isinstance(digest, str) or not re.fullmatch(r"[0-9a-f]{64}", digest) or type(size) is not int or size < 0:
73
+ raise ArtifactError("Invalid file hash/size record.")
74
+ content = read_asset(root, record["path"])
75
+ if file_record(record["path"], content) != {key: record[key] for key in ["path", "sha256", "size_bytes"]}:
76
+ raise ArtifactError(f"Asset hash or size mismatch: {record['path']}")
77
+ files[record["path"]] = content
78
+ return files
79
+
80
+
81
+ def json_object(content: bytes) -> dict:
82
+ try:
83
+ value = json.loads(content)
84
+ except (ValueError, UnicodeError) as error:
85
+ raise ArtifactError(f"Invalid JSON: {error}") from error
86
+ if not isinstance(value, dict):
87
+ raise ArtifactError("Expected a JSON object.")
88
+ return value
89
+
90
+
91
+ def json_bytes(value: dict) -> bytes:
92
+ return (json.dumps(value, indent=2, sort_keys=True) + "\n").encode()
93
+
94
+
95
+ def runtime_lock(root: str | Path, *, version: str, source_url: str, files: list[str], license_files: list[str]) -> dict:
96
+ if not isinstance(version, str) or not version.strip():
97
+ raise ArtifactError("Runtime version must be nonempty.")
98
+ if not isinstance(source_url, str):
99
+ raise ArtifactError("Runtime source must be an HTTPS URL.")
100
+ source = urlparse(source_url)
101
+ if source.scheme != "https" or not source.netloc or source.username or source.password:
102
+ raise ArtifactError("Runtime source must be an HTTPS URL without credentials.")
103
+ if not license_files:
104
+ raise ArtifactError("At least one runtime license file is required.")
105
+ names = sorted(set(files) | set(license_files))
106
+ check_names(names)
107
+ content = {name: read_asset(Path(root), name) for name in names}
108
+ for name in license_files:
109
+ if not content[name].strip():
110
+ raise ArtifactError(f"Empty runtime license file: {name}")
111
+ if not {"micropython.mjs", "micropython.wasm"} <= content.keys():
112
+ raise ArtifactError("MicroPython requires micropython.mjs and micropython.wasm.")
113
+ return {
114
+ "schema_version": 1,
115
+ "kind": "pocket-python-runtime",
116
+ "implementation": "micropython",
117
+ "version": version,
118
+ "source_url": source_url,
119
+ "entrypoint": "micropython.mjs",
120
+ "license_files": sorted(set(license_files)),
121
+ "files": [file_record(name, data) for name, data in sorted(content.items())],
122
+ }
123
+
124
+
125
+ @dataclass
126
+ class RuntimeAssets:
127
+ root: Path
128
+ lock: dict
129
+ files: dict[str, bytes]
130
+
131
+
132
+ def read_runtime(root: str | Path, lock_path: str | Path) -> RuntimeAssets:
133
+ path = Path(lock_path)
134
+ if path.is_symlink():
135
+ raise ArtifactError("Runtime lock must not be a symlink.")
136
+ lock = json_object(path.read_bytes())
137
+ if type(lock.get("schema_version")) is not int or lock["schema_version"] != 1 or lock.get("kind") != "pocket-python-runtime":
138
+ raise ArtifactError("Unsupported runtime lock schema.")
139
+ if lock.get("implementation") != "micropython" or lock.get("entrypoint") != "micropython.mjs":
140
+ raise ArtifactError("Only the MicroPython WebAssembly profile is supported.")
141
+ root = Path(root).absolute()
142
+ files = verified_files(root, lock.get("files"))
143
+ licenses = lock.get("license_files")
144
+ if not isinstance(licenses, list) or not licenses or any(not isinstance(name, str) or name not in files or not files[name].strip() for name in licenses):
145
+ raise ArtifactError("Missing or empty locked runtime license files.")
146
+ expected = runtime_lock(root, version=lock.get("version"), source_url=lock.get("source_url", ""), files=list(files), license_files=licenses)
147
+ if lock != expected:
148
+ raise ArtifactError("Runtime lock differs from the supported schema.")
149
+ return RuntimeAssets(root, lock, files)
@@ -0,0 +1,81 @@
1
+ """Validate Shimify source-bundle snapshots without executing them."""
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+
6
+ from echidnae.python.assets import ArtifactError, file_record, json_object, read_asset, verified_files
7
+
8
+
9
+ @dataclass
10
+ class SourceBundle:
11
+ root: Path
12
+ manifest: dict
13
+ files: dict[str, bytes]
14
+
15
+ def report(self) -> dict:
16
+ return {
17
+ "schema_version": 1,
18
+ "kind": "pocket-python-source-inspection",
19
+ "entrypoint": self.manifest["entrypoint"],
20
+ "source_modules": len(self.manifest["sources"]),
21
+ "source_size_bytes": sum(item["size_bytes"] for item in self.manifest["sources"]),
22
+ "bundle_size_bytes": sum(map(len, self.files.values())),
23
+ "direct_stdlib_modules": self.manifest["stdlib_modules"],
24
+ "runtime_closure_complete": False,
25
+ "browser_compatibility": "unverified; test against the selected runtime",
26
+ }
27
+
28
+
29
+ def read_bundle(directory: str | Path) -> SourceBundle:
30
+ root = Path(directory).absolute()
31
+ raw = read_asset(root, "SHIMIFY-MANIFEST.json")
32
+ manifest = json_object(raw)
33
+ if type(manifest.get("schema_version")) is not int or manifest["schema_version"] != 1 or manifest.get("mode") != "modules":
34
+ raise ArtifactError("Expected a Shimify schema-1 modules bundle.")
35
+ files = verified_files(root, manifest.get("files"))
36
+ if any(name != "run.py" and not name.startswith(("_sources/", "LICENSES/")) for name in files):
37
+ raise ArtifactError("Bundle contains files outside the supported source/notices layout.")
38
+ entry = manifest.get("entrypoint")
39
+ if not isinstance(entry, str) or not entry.startswith("_sources/") or not entry.endswith(".py") or entry.count("/") != 1 or entry not in files or manifest.get("launcher") != "run.py" or "run.py" not in files:
40
+ raise ArtifactError("Invalid bundle entrypoint or launcher.")
41
+ sources = manifest.get("sources")
42
+ if not isinstance(sources, list) or not sources or any(not isinstance(item, dict) for item in sources):
43
+ raise ArtifactError("Expected source records.")
44
+ names, outputs = set(), set()
45
+ for item in sources:
46
+ name, output = item.get("module"), item.get("output")
47
+ if not isinstance(name, str) or not name or not all(part.isidentifier() for part in name.split(".")) or name in names or not isinstance(output, str) or output in outputs or output not in files:
48
+ raise ArtifactError("Invalid or duplicate source mapping.")
49
+ expected = {entry} if name == "__main__" else {"_sources/" + name.replace(".", "/") + suffix for suffix in [".py", "/__init__.py"]}
50
+ if output not in expected:
51
+ raise ArtifactError("Source mapping differs from the module layout.")
52
+ record = file_record(output, files[output])
53
+ if item.get("sha256") != record["sha256"] or type(item.get("size_bytes")) is not int or item["size_bytes"] != record["size_bytes"]:
54
+ raise ArtifactError("Source hash/size differs from the file record.")
55
+ names.add(name)
56
+ outputs.add(output)
57
+ if "__main__" not in names or outputs != {name for name in files if name.startswith("_sources/")}:
58
+ raise ArtifactError("Bundle has missing or unrecorded source files.")
59
+ stdlib = manifest.get("stdlib_modules")
60
+ if not isinstance(stdlib, list) or any(not isinstance(name, str) or not all(part.isidentifier() for part in name.split(".")) for name in stdlib):
61
+ raise ArtifactError("Invalid standard-library requirements.")
62
+ # Validate attribution references before copying. Hash verification covers the
63
+ # bytes, and required paths must also be explicitly listed in the manifest.
64
+ distributions = manifest.get("distributions")
65
+ if not isinstance(distributions, list):
66
+ raise ArtifactError("Invalid distribution provenance.")
67
+ identities = set()
68
+ for distribution in distributions:
69
+ if not isinstance(distribution, dict) or not isinstance(distribution.get("id"), str) or distribution["id"] in identities:
70
+ raise ArtifactError("Invalid distribution identity.")
71
+ identities.add(distribution["id"])
72
+ licenses = distribution.get("license_files")
73
+ metadata = distribution.get("metadata")
74
+ if not isinstance(licenses, list) or not licenses or any(not isinstance(path, str) or not path.startswith("LICENSES/") or path not in files or not files[path].strip() for path in licenses):
75
+ raise ArtifactError("Distribution license material is missing.")
76
+ if not isinstance(metadata, str) or not metadata.startswith("LICENSES/") or metadata not in files:
77
+ raise ArtifactError("Distribution metadata is missing.")
78
+ if any(item.get("distribution") is not None and (not isinstance(item["distribution"], str) or item["distribution"] not in identities) for item in sources):
79
+ raise ArtifactError("Source refers to missing distribution provenance.")
80
+ files["SHIMIFY-MANIFEST.json"] = raw
81
+ return SourceBundle(root, manifest, files)
@@ -0,0 +1,79 @@
1
+ """Command-line interface for explicit runtime assets and source inspection."""
2
+
3
+ import argparse
4
+ import json
5
+ from pathlib import Path
6
+ import sys
7
+
8
+ from echidnae.python import __version__
9
+ from echidnae.python.assets import ArtifactError, json_bytes, read_runtime, runtime_lock
10
+ from echidnae.python.bundles import read_bundle
11
+ from echidnae.python.web import build_web
12
+
13
+
14
+ def main(argv: list[str] | None = None) -> int:
15
+ parser = argparse.ArgumentParser(prog="echidnae-python", description="Audit runtime assets and assemble offline Python applications.")
16
+ parser.add_argument("--version", action="version", version=f"echidnae-python {__version__}")
17
+ commands = parser.add_subparsers(dest="command", required=True)
18
+ lock = commands.add_parser("lock-runtime", help="Hash an explicit MicroPython runtime asset allowlist.")
19
+ lock.add_argument("root", type=Path)
20
+ lock.add_argument("--runtime-version", required=True)
21
+ lock.add_argument("--source-url", required=True)
22
+ lock.add_argument("--file", action="append", required=True, default=[])
23
+ lock.add_argument("--license-file", action="append", required=True, default=[])
24
+ lock.add_argument("--output", type=Path, required=True)
25
+ inspect = commands.add_parser("inspect", help="Validate and describe a Shimify source bundle.")
26
+ inspect.add_argument("bundle", type=Path)
27
+ web = commands.add_parser("web", help="Build a local-asset MicroPython PWA in a new directory.")
28
+ web.add_argument("bundle", type=Path)
29
+ web.add_argument("--runtime", type=Path, required=True)
30
+ web.add_argument("--runtime-lock", type=Path, required=True)
31
+ web.add_argument("--output", type=Path, required=True)
32
+ web.add_argument("--title", default="Echidnae Python")
33
+ compiled = commands.add_parser("compiled-web", help="Build a verified compiler-produced PWA from an explicit client allowlist.")
34
+ compiled.add_argument("client", type=Path, help="Client-source JSON manifest.")
35
+ compiled.add_argument("--compiled", type=Path, help="Optional existing compiler output to verify against recompilation.")
36
+ compiled.add_argument("--output", type=Path, required=True)
37
+ compiled.add_argument("--title", default="Echidnae Python")
38
+ compiled.add_argument("--omit-source-maps", action="store_true")
39
+ interpreter = commands.add_parser("interpreter-web", help="Build a source console using the explicitly supplied pinned independent engine.")
40
+ interpreter.add_argument("client", type=Path, help="Console-source JSON manifest.")
41
+ interpreter.add_argument("--engine", type=Path, required=True, help="Directory containing the known source-console engine assets.")
42
+ interpreter.add_argument("--output", type=Path, required=True)
43
+ interpreter.add_argument("--title", default="Echidnae Python Console")
44
+ interpreter.add_argument("--library-profile", choices=["core-only/1", "operator/1"], default="core-only/1")
45
+ interpreter.add_argument("--host-profile", choices=["output-only/1"], default="output-only/1")
46
+ interpreter.add_argument("--language-profile", choices=["core-source/1", "classes-source/1"], default="core-source/1")
47
+ args = parser.parse_args(argv)
48
+ try:
49
+ if args.command == "lock-runtime":
50
+ result = runtime_lock(args.root, version=args.runtime_version, source_url=args.source_url, files=args.file, license_files=args.license_file)
51
+ args.output.parent.mkdir(parents=True, exist_ok=True)
52
+ with args.output.open("xb") as stream:
53
+ stream.write(json_bytes(result))
54
+ print(f"Created {args.output.resolve()}")
55
+ elif args.command == "interpreter-web":
56
+ from echidnae.python.interpreter import build_interpreter, read_console_source, read_interpreter
57
+ receipt = build_interpreter(read_console_source(args.client), read_interpreter(args.engine, library_profile=args.library_profile), args.output,
58
+ title=args.title, host_profile=args.host_profile, language_profile=args.language_profile)
59
+ print(f"Created {args.output.resolve()} ({receipt['size']['artifact_bytes']} bytes)")
60
+ elif args.command == "compiled-web":
61
+ from echidnae.python.compiled import build_compiled, read_client, read_compiled
62
+ client = read_client(args.client)
63
+ compiled = read_compiled(args.compiled, client) if args.compiled else None
64
+ receipt = build_compiled(client, args.output, compiled=compiled, title=args.title, omit_source_maps=args.omit_source_maps)
65
+ print(f"Created {args.output.resolve()} ({receipt['size']['artifact_bytes']} bytes)")
66
+ print("Serve over HTTPS or localhost; offline use follows the first successful installation.")
67
+ elif args.command == "web":
68
+ manifest = build_web(read_bundle(args.bundle), read_runtime(args.runtime, args.runtime_lock), args.output, title=args.title)
69
+ print(f"Created {args.output.resolve()} ({manifest['size']['artifact_bytes']} bytes)")
70
+ print("Serve over HTTPS or localhost; test this application against MicroPython.")
71
+ else:
72
+ print(json.dumps(read_bundle(args.bundle).report(), indent=2, sort_keys=True))
73
+ except ArtifactError as error:
74
+ print(f"echidnae-python: {error}", file=sys.stderr)
75
+ return 1
76
+ except (OSError, ValueError) as error:
77
+ print(f"echidnae-python: {error}", file=sys.stderr)
78
+ return 2
79
+ return 0