browser-py 0.1.0__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.
- browser_compile.py +27 -0
- browser_py-0.1.0.dist-info/METADATA +53 -0
- browser_py-0.1.0.dist-info/RECORD +12 -0
- browser_py-0.1.0.dist-info/WHEEL +5 -0
- browser_py-0.1.0.dist-info/entry_points.txt +2 -0
- browser_py-0.1.0.dist-info/top_level.txt +7 -0
- browser_source.py +598 -0
- compiler_command.py +53 -0
- javascript_output.py +9 -0
- numeric_ir.py +315 -0
- numeric_source.py +266 -0
- webgpu_bindings.py +308 -0
browser_compile.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from shutil import copyfile
|
|
3
|
+
from tempfile import TemporaryDirectory
|
|
4
|
+
|
|
5
|
+
from javascript_output import write_javascript
|
|
6
|
+
from numeric_ir import emit_module, load_ir
|
|
7
|
+
from numeric_source import read_numeric_source
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def compile_modules(source: Path, output: Path, minified: bool) -> Path:
|
|
11
|
+
source = source.resolve()
|
|
12
|
+
if source.suffix == ".py" and source.stem.isidentifier() and not source.stem.startswith("__"):
|
|
13
|
+
admitted = read_numeric_source(source)
|
|
14
|
+
else:
|
|
15
|
+
raise ValueError("Expected a named Python module, not an entry file")
|
|
16
|
+
modules = load_ir(tuple(admitted.trees))
|
|
17
|
+
# Admission supplies checked schemas to emission; the build publishes staged files only after every module succeeds.
|
|
18
|
+
with TemporaryDirectory(prefix="browser-py-output-", dir="/tmp") as temporary:
|
|
19
|
+
staging = Path(temporary)
|
|
20
|
+
for path in admitted.trees:
|
|
21
|
+
compiled = emit_module(modules[path.stem], admitted.schemas[path])
|
|
22
|
+
write_javascript(compiled[0], staging / f"{path.stem}.js", minified)
|
|
23
|
+
(staging / f"{path.stem}.ir").write_text(compiled[1])
|
|
24
|
+
output.mkdir(parents=True, exist_ok=True)
|
|
25
|
+
for artifact in sorted(staging.iterdir()):
|
|
26
|
+
copyfile(artifact, output / artifact.name)
|
|
27
|
+
return output / f"{source.stem}.js"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: browser-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An experimental Python-to-browser compiler and Transcrypt competitor
|
|
5
|
+
Requires-Python: <3.13,>=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: rjsmin==1.2.5
|
|
8
|
+
Requires-Dist: mypy==1.18.2
|
|
9
|
+
Requires-Dist: setuptools>=68
|
|
10
|
+
Provides-Extra: tools
|
|
11
|
+
Requires-Dist: playwright<2,>=1.56; extra == "tools"
|
|
12
|
+
Requires-Dist: pscript<0.9,>=0.8; extra == "tools"
|
|
13
|
+
Requires-Dist: wgpu==0.29.0; extra == "tools"
|
|
14
|
+
Requires-Dist: glfw<3,>=2.9; extra == "tools"
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: browser-py[tools]; extra == "test"
|
|
17
|
+
Requires-Dist: pytest<10,>=9; extra == "test"
|
|
18
|
+
Requires-Dist: ruff<1,>=0.14; extra == "test"
|
|
19
|
+
|
|
20
|
+
# browser-py
|
|
21
|
+
|
|
22
|
+
An experimental Python-to-browser compiler, built as a competitor to Transcrypt.
|
|
23
|
+
Write Python and compile it for the browser.
|
|
24
|
+
|
|
25
|
+
It supports typed numeric code and a small browser-facing subset, not arbitrary
|
|
26
|
+
Python packages. Compilation, browser examples, and checks work without Transcrypt.
|
|
27
|
+
|
|
28
|
+
Install with Python 3.12:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
python -m pip install browser-py
|
|
32
|
+
browser-py compile path/to/your_module.py
|
|
33
|
+
browser-py --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
In a source checkout, the equivalent compiler command is:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
python -B browser_py.py compile source/kernels.py
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Compiled files are saved to temporary storage; the command prints their location.
|
|
43
|
+
Compiler comparisons and the triangle demo are supporting tools, available in the
|
|
44
|
+
source checkout or source distribution (not the compiler wheel). Install the `tools`
|
|
45
|
+
extra to use them:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
python -m pip install 'browser-py[tools]'
|
|
49
|
+
python -B source/__comparison__.py --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For development, install the `test` extra and run `python -B browser_py.py validate`
|
|
53
|
+
from a source checkout.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
browser_compile.py,sha256=hIN7dYpZKWP-jhQZTRvs-krDW04e0EvLsNCd4_Rq9RI,1281
|
|
2
|
+
browser_source.py,sha256=_DSWhBAixRhgmMSoP0iiSQuOfVkflYFnEjgh_24G8DQ,25055
|
|
3
|
+
compiler_command.py,sha256=NvRNkdKueKTdSMfkvF2FaO_uu_uJN0meKlmU5O90zfw,2347
|
|
4
|
+
javascript_output.py,sha256=6YrZFEluD7kH47OMZlAEjAe5e4i3QOuSfanEH19tEqo,216
|
|
5
|
+
numeric_ir.py,sha256=xrwNuicTiLiaX967z1ZQib4QbzzRjBYMWA8qH8XL9Zo,12234
|
|
6
|
+
numeric_source.py,sha256=pSwxRP7k45zOFvAMBBoz8sLQAE6KnbtLZSdbuc36Lcs,10631
|
|
7
|
+
webgpu_bindings.py,sha256=HygHTpUzbzcNtGgRaojnQulKrQg6oxGTlhGDw--zZUU,12420
|
|
8
|
+
browser_py-0.1.0.dist-info/METADATA,sha256=sugmh6G75DB7ksVclVY-qQQ3Of_UVW2n2QINEcHHVGc,1701
|
|
9
|
+
browser_py-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
browser_py-0.1.0.dist-info/entry_points.txt,sha256=39C6ZOQHCkpCRWuqm5aElJw24tz_ACf8ZY8sWKgST-0,53
|
|
11
|
+
browser_py-0.1.0.dist-info/top_level.txt,sha256=NnxXBf2ODGK3hITzPj40Z3Z-KcCNFA9mrwfVMxbySYc,108
|
|
12
|
+
browser_py-0.1.0.dist-info/RECORD,,
|