pygodide 0.1.0b1__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,94 @@
1
+ const status = document.getElementById({{ status_element_id | tojson }});
2
+ const canvas = document.getElementById({{ canvas_element_id | tojson }});
3
+
4
+ const pyodidePackages = {{ pyodide_packages | tojson }};
5
+ const pythonFiles = {{ python_files | tojson }};
6
+ const assetBasePath = {{ asset_base_path | tojson }};
7
+ const virtualFsRoot = {{ virtual_fs_root | tojson }};
8
+ const startupPythonCode = {{ startup_python_code | tojson }};
9
+ const statusText = {
10
+ startingPyodide: {{ starting_pyodide_status_text | tojson }},
11
+ loadingPackages: {{ loading_packages_status_text | tojson }},
12
+ stagingFiles: {{ staging_files_status_text | tojson }},
13
+ loadingApp: {{ loading_app_status_text | tojson }},
14
+ running: {{ running_status_text | tojson }},
15
+ };
16
+
17
+ function requireElement(element, id) {
18
+ if (!element) {
19
+ throw new Error(`Missing required element: #${id}`);
20
+ }
21
+ return element;
22
+ }
23
+
24
+ function setStatus(message) {
25
+ if (status) {
26
+ status.textContent = message;
27
+ }
28
+ }
29
+
30
+ function joinVirtualPath(root, relativePath) {
31
+ const normalizedRoot = root.startsWith("/") ? root : `/${root}`;
32
+ const trimmedRoot = normalizedRoot.replace(/\/+$/, "");
33
+ const trimmedPath = relativePath.replace(/^\/+/, "");
34
+ return `${trimmedRoot}/${trimmedPath}`;
35
+ }
36
+
37
+ function ensureParentDir(runtime, filePath) {
38
+ const lastSlash = filePath.lastIndexOf("/");
39
+ if (lastSlash <= 0) {
40
+ return;
41
+ }
42
+ runtime.FS.mkdirTree(filePath.slice(0, lastSlash));
43
+ }
44
+
45
+ function resolveAssetUrl(filename) {
46
+ return new URL(filename, new URL(assetBasePath, import.meta.url)).toString();
47
+ }
48
+
49
+ async function fetchTextFile(filename) {
50
+ const response = await fetch(resolveAssetUrl(filename));
51
+ if (!response.ok) {
52
+ throw new Error(`Failed to fetch ${filename}: ${response.status} ${response.statusText}`);
53
+ }
54
+ return await response.text();
55
+ }
56
+
57
+ async function stagePythonFiles(runtime) {
58
+ for (const filename of pythonFiles) {
59
+ const source = await fetchTextFile(filename);
60
+ const targetPath = joinVirtualPath(virtualFsRoot, filename);
61
+ ensureParentDir(runtime, targetPath);
62
+ runtime.FS.writeFile(targetPath, source, { encoding: "utf8" });
63
+ }
64
+ }
65
+
66
+ async function boot() {
67
+ const requiredCanvas = requireElement(canvas, {{ canvas_element_id | tojson }});
68
+ requireElement(status, {{ status_element_id | tojson }});
69
+
70
+ setStatus(statusText.startingPyodide);
71
+
72
+ const runtime = await loadPyodide();
73
+ runtime._api._skip_unwind_fatal_error = true;
74
+
75
+ runtime.canvas.setCanvas2D(requiredCanvas);
76
+
77
+ if (pyodidePackages.length > 0) {
78
+ setStatus(statusText.loadingPackages);
79
+ await runtime.loadPackage(pyodidePackages);
80
+ }
81
+
82
+ setStatus(statusText.stagingFiles);
83
+ await stagePythonFiles(runtime);
84
+
85
+ setStatus(statusText.loadingApp);
86
+ await runtime.runPythonAsync(startupPythonCode);
87
+
88
+ setStatus(statusText.running);
89
+ }
90
+
91
+ boot().catch((error) => {
92
+ console.error(error);
93
+ setStatus(`Error: ${error}`);
94
+ });
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html lang="{{ lang }}">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>{{ title }}</title>
7
+ </head>
8
+ <body>
9
+ <div id="{{ status_element_id }}">{{ status_text }}</div>
10
+ <canvas
11
+ id="{{ canvas_element_id }}"
12
+ width="{{ canvas_width }}"
13
+ height="{{ canvas_height }}"
14
+ tabindex="0"
15
+ ></canvas>
16
+ <script src="{{ pyodide_url }}"></script>
17
+ <script type="module" src="{{ boot_script_path }}"></script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: pygodide
3
+ Version: 0.1.0b1
4
+ Summary: Modern replacement for pygbag that leverages pyodide for running pygame in the web
5
+ Project-URL: Homepage, https://github.com/Elan456/pygodide
6
+ Project-URL: Repository, https://github.com/Elan456/pygodide.git
7
+ Author-email: Ethan Anderson <telan4892@gmail.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.11
11
+ Requires-Dist: jinja2>=3.1.6
12
+ Requires-Dist: pygame-ce
13
+ Requires-Dist: typer>=0.26.7
14
+ Description-Content-Type: text/markdown
15
+
16
+ # pygodide
17
+
18
+ **BETA (Everything is subject to change)**
19
+
20
+ Pronounced "pie-go-died",
21
+ pygodide is a tool for converting pygame projects into web applications using Pyodide.
22
+ It provides a simple command line interface and works by analyzing your code and
23
+ asset files and then building them together with some web-specific glue code to make everything work in the browser.
24
+
25
+ Thanks to Pyodide, pygodide supports far more Python packages than just pygame.
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install pygodide
31
+ ```
32
+
33
+ ```bash
34
+ git clone https://github.com/Elan456/pygodide.git
35
+ cd pygodide
36
+ uv sync --dev
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```bash
42
+ pygodide build /path/to/your/pygame/project --serve
43
+ ```
44
+
45
+ That's it! Open http://localhost:8000 in a web browser to see your app running.
46
+ Currently only supports flat projects. The vision is to support any arbitrary
47
+ pygame project.
48
+
49
+ ## Development
50
+
51
+ Install the local hooks once after cloning:
52
+
53
+ ```bash
54
+ uv run pre-commit install --hook-type pre-commit --hook-type pre-push
55
+ ```
56
+
57
+ Run the same checks as CI locally:
58
+
59
+ ```bash
60
+ uv run ruff format --check .
61
+ uv run ruff check .
62
+ uv run pytest
63
+ ```
64
+
65
+ ## Proof of Concept
66
+
67
+ `test_targets/ball_bouncing` contains a small Pygame app.
68
+
69
+ Using the following command, you can build and serve the app in a web browser:
70
+
71
+ ```bash
72
+ pygodide build test_targets/ball_bouncing/src --serve
73
+ ```
74
+
75
+ You'll get the output of:
76
+
77
+ ```bash
78
+ Serving /home/ethan/Projects/pygodide/test_targets/ball_bouncing/build at http://localhost:8000
79
+ ```
80
+
81
+ Open http://localhost:8000 in a web browser to see the app running. You should see a bouncing ball!
82
+ Press the arrow keys to accelerate the ball in different directions.
@@ -0,0 +1,7 @@
1
+ pygodide/templates/boot.js,sha256=qaImG8w0YI6YtiwMgcALQZoUdEEtL6Uilvrt4d9m6u0,2878
2
+ pygodide/templates/index.html,sha256=UW9JnWzn9HiJQWn7UCp6gsLvLHAjPBJk2Okqu8ZUKaQ,544
3
+ pygodide-0.1.0b1.dist-info/METADATA,sha256=JpA59YwGoLtpR17g4Jb8p_QC5d29PcSub2iZt_WSu9M,2136
4
+ pygodide-0.1.0b1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
5
+ pygodide-0.1.0b1.dist-info/entry_points.txt,sha256=APWkKbB9x_-oYVgzCzA7cARiZA8ZD5llCtdq4CDSLqA,51
6
+ pygodide-0.1.0b1.dist-info/licenses/LICENSE,sha256=OPl-2Dwa2bvUXOIW2DGX-B1SKypCMYoeJ-7KAyj5fp8,1071
7
+ pygodide-0.1.0b1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pygodide = pygodide.cli.main:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ethan Anderson
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.