|
3 | 3 |
|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
| 6 | +import os |
6 | 7 | import platform |
| 8 | +import subprocess |
7 | 9 | import sys |
8 | 10 | from pathlib import Path |
9 | 11 |
|
@@ -35,11 +37,45 @@ def get_package_data() -> list[str]: |
35 | 37 | return files |
36 | 38 |
|
37 | 39 |
|
| 40 | +def check_sdl_version() -> None: |
| 41 | + """Check the local SDL version on Linux distributions.""" |
| 42 | + if not sys.platform.startswith("linux"): |
| 43 | + return |
| 44 | + if "PYODIDE" in os.environ: |
| 45 | + return |
| 46 | + needed_version = "{}.{}.{}".format(*SDL_VERSION_NEEDED) |
| 47 | + try: |
| 48 | + sdl_version_str = subprocess.check_output( |
| 49 | + ["pkg-config", "sdl3", "--modversion"], # noqa: S607 |
| 50 | + universal_newlines=True, |
| 51 | + ).strip() |
| 52 | + except FileNotFoundError: |
| 53 | + try: |
| 54 | + sdl_version_str = subprocess.check_output(["sdl3-config", "--version"], universal_newlines=True).strip() # noqa: S607 |
| 55 | + except FileNotFoundError as exc: |
| 56 | + msg = ( |
| 57 | + f"libsdl3-dev or equivalent must be installed on your system and must be at least version {needed_version}." |
| 58 | + "\nsdl3-config must be on PATH." |
| 59 | + ) |
| 60 | + raise RuntimeError(msg) from exc |
| 61 | + except subprocess.CalledProcessError as exc: |
| 62 | + if sys.version_info >= (3, 11): |
| 63 | + exc.add_note(f"Note: {os.environ.get('PKG_CONFIG_PATH')=}") |
| 64 | + raise |
| 65 | + print(f"Found SDL {sdl_version_str}.") |
| 66 | + sdl_version = tuple(int(s) for s in sdl_version_str.split(".")) |
| 67 | + if sdl_version < SDL_VERSION_NEEDED: |
| 68 | + msg = f"SDL version must be at least {needed_version}, (found {sdl_version_str})" |
| 69 | + raise RuntimeError(msg) |
| 70 | + |
| 71 | + |
38 | 72 | if not (SETUP_DIR / "libtcod/src").exists(): |
39 | 73 | print("Libtcod submodule is uninitialized.") |
40 | 74 | print("Did you forget to run 'git submodule update --init'?") |
41 | 75 | sys.exit(1) |
42 | 76 |
|
| 77 | +check_sdl_version() |
| 78 | + |
43 | 79 | setup( |
44 | 80 | py_modules=["libtcodpy"], |
45 | 81 | packages=["tcod", "tcod.sdl", "tcod.__pyinstaller"], |
|
0 commit comments