Skip to content

Commit b8843aa

Browse files
committed
Make pymunk optional
1 parent 9102087 commit b8843aa

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ classifiers = [
2222
dependencies = [
2323
"pyglet==3.0.dev1",
2424
"pillow~=12.0.0",
25-
"pymunk~=7.2.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

0 commit comments

Comments
 (0)