Skip to content

Commit ab5ca56

Browse files
authored
Dependency Cleanup for WASM environments (#2804)
* Make pymunk optional * Some more dependency cleanup for WASM environment
1 parent f020c83 commit ab5ca56

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

arcade/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ def configure_logging(level: int | None = None):
192192
from .tilemap import load_tilemap
193193
from .tilemap import TileMap
194194

195-
if sys.platform != "emscripten":
195+
try:
196196
from .pymunk_physics_engine import PymunkPhysicsEngine
197197
from .pymunk_physics_engine import PymunkPhysicsObject
198198
from .pymunk_physics_engine import PymunkException
199+
except ImportError:
200+
pass
199201

200202
from .version import VERSION
201203

arcade/hitbox/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from PIL.Image import Image
22

33
from arcade.types import Point2List
4-
from arcade.utils import is_pyodide
54

65
from .base import HitBox, HitBoxAlgorithm, RotatableHitBox
76
from .bounding_box import BoundingHitBoxAlgorithm
@@ -10,12 +9,15 @@
109

1110
#: The simple hit box algorithm.
1211
algo_simple = SimpleHitBoxAlgorithm()
13-
#: The detailed hit box algorithm.
1412

15-
if not is_pyodide():
13+
#: The detailed hit box algorithm. This depends on pymunk and will fallback to the simple algorithm.
14+
try:
1615
from .pymunk import PymunkHitBoxAlgorithm
17-
1816
algo_detailed = PymunkHitBoxAlgorithm()
17+
except ImportError:
18+
print("WARNING: Running without PyMunk. The detailed hitbox algorithm will fallback to simple")
19+
algo_detailed = SimpleHitBoxAlgorithm()
20+
1921

2022
#: The bounding box hit box algorithm.
2123
algo_bounding_box = BoundingHitBoxAlgorithm()

pyproject.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ classifiers = [
2121
]
2222
dependencies = [
2323
"pyglet==3.0.dev1",
24-
"pillow~=12.0.0",
25-
"pymunk~=7.2.0",
24+
"pillow>=11.3.0",
2625
"pytiled-parser~=2.2.9",
2726
]
2827
dynamic = ["version"]
@@ -36,6 +35,9 @@ Source = "https://github.com/pythonarcade/arcade"
3635
Book = "https://learn.arcade.academy"
3736

3837
[dependency-groups]
38+
extras = [
39+
"pymunk~=7.2.0"
40+
]
3941
# Used for dev work
4042
dev = [
4143
"sphinx==8.1.3", # April 2024 | Updated 2024-07-15, 7.4+ is broken with sphinx-autobuild
@@ -62,8 +64,10 @@ dev = [
6264
"click==8.1.7", # Temp fix until we bump typer
6365
"typer==0.12.5", # Needed for make.py
6466
"wheel",
65-
"bottle" # Used for web testing playground
67+
"bottle", # Used for web testing playground
68+
{include-group = "extras"}
6669
]
70+
6771
# Testing only
6872
testing_libraries = ["pytest", "pytest-mock", "pytest-cov", "pyyaml==6.0.1"]
6973

webplayground/example.tpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
% title = name.split(".")[-1]
66
<title>{{title}}</title>
7-
<script src="https://cdn.jsdelivr.net/pyodide/v0.28.1/full/pyodide.js"></script>
7+
<script src="https://cdn.jsdelivr.net/pyodide/v0.29.0/full/pyodide.js"></script>
88
</head>
99

1010
<body>
@@ -13,9 +13,8 @@
1313
let pyodide = await loadPyodide();
1414
await pyodide.loadPackage("micropip");
1515
const micropip = pyodide.pyimport("micropip");
16-
await pyodide.loadPackage("pillow"); // Arcade needs Pillow
17-
await micropip.install("pyglet==3.0.dev1", pre=true)
18-
await micropip.install("http://localhost:8000/static/{{arcade_wheel}}");
16+
await pyodide.loadPackage("pillow");
17+
await micropip.install("http://localhost:8000/static/{{arcade_wheel}}", pre=true);
1918
2019
// We are importing like this because some example files have numbers in the name, and you can't use those in normal import statements
2120
pyodide.runPython(`

webplayground/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def main():
6161

6262
# Go to arcade and build a wheel
6363
os.chdir(path_arcade)
64-
subprocess.run(["python", "-m", "build", "--wheel", "--outdir", "dist"])
64+
subprocess.run(["uv", "build"])
6565
os.chdir(here)
6666
shutil.copy(path_arcade_wheel, f"./{arcade_wheel_filename}")
6767

0 commit comments

Comments
 (0)