diff --git a/arcade/__pyinstaller/hook-arcade.py b/arcade/__pyinstaller/hook-arcade.py index 70c4f8dcea..9035f95b7c 100644 --- a/arcade/__pyinstaller/hook-arcade.py +++ b/arcade/__pyinstaller/hook-arcade.py @@ -12,42 +12,53 @@ from __future__ import annotations +from importlib.util import find_spec from pathlib import Path -import pymunk from PyInstaller.compat import is_darwin, is_unix, is_win -import arcade - -pymunk_path = Path(pymunk.__file__).parent -arcade_path = Path(arcade.__file__).parent - -datas = [ - ( - arcade_path / "resources" / "system", - "./arcade/resources/system", - ), - ( - arcade_path / "VERSION", - "./arcade/VERSION", - ), -] - -if is_win: - binaries = [ - (pymunk_path / "_chipmunk.pyd", "."), - ] -elif is_darwin: - binaries = [ - (pymunk_path / "_chipmunk.abi3.so", "."), - (arcade_path / "lib", "./arcade/lib"), - ] -elif is_unix: - binaries = [ - (pymunk_path / "_chipmunk.abi3.so", "."), - ] -else: +# check for supported operating systems +if not is_win and not is_darwin and not is_unix: raise NotImplementedError( "You are running on an unsupported operating system. " "Only Linux, Mac, and Windows are supported." ) + +datas = [] +binaries = [] + +# Add Arcade resources +arcade_spec = find_spec("arcade") +if arcade_spec is None or arcade_spec.origin is None: + raise ImportError("Arcade is not installed. Cannot continue.") + +arcade_path = Path(arcade_spec.origin).parent +datas.extend( + [ + ( + arcade_path / "resources" / "system", + "./arcade/resources/system", + ), + ( + arcade_path / "VERSION", + "./arcade/VERSION", + ), + ] +) + +if is_darwin: + binaries.append((arcade_path / "lib", "./arcade/lib")) + +# Add Pymunk resources +pymunk_spec = find_spec("pymunk") +if pymunk_spec is not None and pymunk_spec.origin is not None: + pymunk_path = Path(pymunk_spec.origin).parent + + if is_win: + binaries.append((pymunk_path / "_chipmunk.pyd", ".")) + elif is_darwin: + binaries.append((pymunk_path / "_chipmunk.abi3.so", ".")) + elif is_unix: + binaries.append((pymunk_path / "_chipmunk.abi3.so", ".")) +else: + print("Pymunk is not available. Skipping Pymunk resources.")