wasi-python 0.1.0a3__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.
@@ -0,0 +1,91 @@
1
+ """wasi_python: a static CPython for WebAssembly hosts, with numpy and pandas compiled in.
2
+
3
+ The wheel carries the runtime's artifacts and this module tells an embedder where they are::
4
+
5
+ from wasi_python import artifacts
6
+
7
+ paths = artifacts()
8
+ paths.snapshot # python.wasm with the stack pre-imported; starts in a few milliseconds
9
+ paths.plain # the same reactor without the snapshot, for debugging
10
+ paths.stdlib_zip # the stdlib plus numpy, pandas and their pure-Python dependencies
11
+ paths.manifest # every pinned source and recipe hash the build used
12
+
13
+ `artifacts()` looks, in order, at `$WASI_PYTHON_ARTIFACTS` (when set and not empty), in a source
14
+ checkout at `build/artifacts/` (what `scripts/build.sh` writes), and at the wheel's own
15
+ `artifacts/`: the harness's order. `run()` runs one
16
+ program in one call (the `run` extra; see `wasi_python.run`), and README.md documents the contract
17
+ any other embedder implements.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import os
23
+ from dataclasses import dataclass
24
+ from pathlib import Path
25
+
26
+ __version__ = "0.1.0a3"
27
+
28
+ ARTIFACT_DIR = Path(__file__).resolve().parent / "artifacts"
29
+ ARTIFACTS_ENV = "WASI_PYTHON_ARTIFACTS"
30
+ # A source checkout: <repo>/src/wasi_python/ beside <repo>/build/artifacts/ (and pyproject.toml).
31
+ _REPO = Path(__file__).resolve().parents[2]
32
+ CHECKOUT_ARTIFACT_DIR = (
33
+ _REPO / "build" / "artifacts" if (_REPO / "pyproject.toml").is_file() else None
34
+ )
35
+
36
+
37
+ class ArtifactsMissing(RuntimeError):
38
+ """Raised when the runtime's artifacts are not beside this module."""
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class Artifacts:
43
+ """Absolute paths to the runtime's files inside an installed wheel."""
44
+
45
+ snapshot: Path
46
+ plain: Path
47
+ stdlib_zip: Path
48
+ manifest: Path
49
+
50
+
51
+ def artifact_dir() -> Path:
52
+ """The directory holding the artifact set (spec 001, Decision 3)."""
53
+ env = os.environ.get(ARTIFACTS_ENV)
54
+ if env: # set and not empty
55
+ return Path(env).resolve()
56
+ for d in (CHECKOUT_ARTIFACT_DIR, ARTIFACT_DIR): # the harness's order (spec 003, Decision 10)
57
+ if d is not None and (d / "MANIFEST").is_file():
58
+ return d
59
+ raise ArtifactsMissing(
60
+ f"no runtime artifacts: ${ARTIFACTS_ENV} is unset, and neither {CHECKOUT_ARTIFACT_DIR} nor "
61
+ f"{ARTIFACT_DIR} has a MANIFEST. Install the released wheel, or build with "
62
+ "scripts/build.sh (see README.md)."
63
+ )
64
+
65
+
66
+ def artifacts() -> Artifacts:
67
+ """Locate the artifact set, or explain how to produce it."""
68
+ d = artifact_dir()
69
+ manifest = d / "MANIFEST"
70
+ if not manifest.is_file():
71
+ raise ArtifactsMissing(f"{d} has no MANIFEST (from ${ARTIFACTS_ENV})")
72
+ return Artifacts(
73
+ snapshot=d / "python-snapshot.wasm",
74
+ plain=d / "python.wasm",
75
+ stdlib_zip=d / "python-stdlib.zip",
76
+ manifest=manifest,
77
+ )
78
+
79
+
80
+ from .runner import Completed, Grant, run, run_async # noqa: E402 (runner.py imports Artifacts from here)
81
+
82
+ __all__ = [
83
+ "Artifacts",
84
+ "ArtifactsMissing",
85
+ "Completed",
86
+ "Grant",
87
+ "artifact_dir",
88
+ "artifacts",
89
+ "run",
90
+ "run_async",
91
+ ]
@@ -0,0 +1,5 @@
1
+ """`python -m wasi_python run …` is `wasi-python run …` (spec 019)."""
2
+
3
+ from .cli import main
4
+
5
+ raise SystemExit(main())
@@ -0,0 +1,44 @@
1
+ ==== bzip2 LICENSE ====
2
+
3
+ --------------------------------------------------------------------------
4
+
5
+ This program, "bzip2", the associated library "libbzip2", and all
6
+ documentation, are copyright (C) 1996-2019 Julian R Seward. All
7
+ rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions
11
+ are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ 2. The origin of this software must not be misrepresented; you must
17
+ not claim that you wrote the original software. If you use this
18
+ software in a product, an acknowledgment in the product
19
+ documentation would be appreciated but is not required.
20
+
21
+ 3. Altered source versions must be plainly marked as such, and must
22
+ not be misrepresented as being the original software.
23
+
24
+ 4. The name of the author may not be used to endorse or promote
25
+ products derived from this software without specific prior written
26
+ permission.
27
+
28
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
29
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
32
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
34
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
+
40
+ Julian Seward, jseward@acm.org
41
+ bzip2/libbzip2 version 1.0.8 of 13 July 2019
42
+
43
+ --------------------------------------------------------------------------
44
+