|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import glob |
| 4 | +import platform |
4 | 5 | from pathlib import Path |
5 | 6 | from setuptools import Extension, setup |
6 | 7 |
|
7 | | -import numpy |
| 8 | +# No ZIP support for windows, building with zlib is a pain |
| 9 | +ZIP_SUPPORT = platform.system() != "Windows" |
8 | 10 |
|
9 | | -# Read the contents of the README file |
10 | | -LONG_DESCRIPTION = (Path(__file__).parent / "README.md").read_text() |
11 | 11 |
|
12 | | -# List libgambatte sources, excluding `file_zip.cpp` |
13 | | -libgambatte_sources = [ |
14 | | - path |
15 | | - for path in glob.glob("libgambatte/**/*.cpp", recursive=True) |
16 | | - if not path.endswith("file_zip.cpp") |
17 | | -] |
| 12 | +def get_extensions() -> list[Extension]: |
| 13 | + import numpy # Lazy import; numpy provided via build-system requires |
18 | 14 |
|
19 | | -# List all directories containing `.h` files |
20 | | -libgambatte_include_dirs: list[str] = list( |
21 | | - set( |
22 | | - str(Path(path).parent) |
23 | | - for path in glob.glob("libgambatte/**/*.h", recursive=True) |
24 | | - ) |
25 | | -) |
| 15 | + # Gather all C++ sources (including file_zip.cpp for ZIP support) |
| 16 | + # Exclude file.cpp since file_zip.cpp provides the full implementation |
| 17 | + libgambatte_sources = [ |
| 18 | + p |
| 19 | + for p in glob.glob("libgambatte/**/*.cpp", recursive=True) |
| 20 | + if (ZIP_SUPPORT and not p.endswith("file.cpp")) |
| 21 | + or (not ZIP_SUPPORT and not p.endswith("file_zip.cpp")) |
| 22 | + ] |
26 | 23 |
|
27 | | -# The gambatte extension, including libgambatte with the Cython wrapper |
28 | | -gambatte_extension = Extension( |
29 | | - "gambaterm.libgambatte", |
30 | | - language="c++", |
31 | | - include_dirs=[ |
32 | | - *libgambatte_include_dirs, |
33 | | - "libgambatte_ext", |
34 | | - numpy.get_include(), |
35 | | - ], |
36 | | - extra_compile_args=["-DHAVE_STDINT_H"], |
37 | | - sources=[ |
38 | | - *libgambatte_sources, |
39 | | - "libgambatte_ext/libgambatte.pyx", |
40 | | - ], |
41 | | -) |
| 24 | + # Add unzip C sources for ZIP support |
| 25 | + if ZIP_SUPPORT: |
| 26 | + libgambatte_sources += glob.glob( |
| 27 | + "libgambatte/src/file/unzip/*.c", recursive=True |
| 28 | + ) |
42 | 29 |
|
| 30 | + # Add zlib library for ZIP support |
| 31 | + libraries = [] |
| 32 | + if ZIP_SUPPORT: |
| 33 | + libraries += ["z"] |
43 | 34 |
|
44 | | -# The termblit extension |
45 | | -termblit_extension = Extension( |
46 | | - "gambaterm.termblit", |
47 | | - language="c", |
48 | | - include_dirs=[numpy.get_include()], |
49 | | - sources=["termblit_ext/termblit.pyx"], |
50 | | -) |
| 35 | + # Include dirs: parents of all headers |
| 36 | + libgambatte_include_dirs = list( |
| 37 | + {str(Path(h).parent) for h in glob.glob("libgambatte/**/*.h", recursive=True)} |
| 38 | + ) |
51 | 39 |
|
52 | | -setup( |
53 | | - name="gambaterm", |
54 | | - version="0.12.7", |
55 | | - packages=["gambaterm"], |
56 | | - ext_modules=[gambatte_extension, termblit_extension], |
57 | | - install_requires=[ |
58 | | - "numpy~=1.20", |
59 | | - "asyncssh~=2.9", |
60 | | - "prompt_toolkit~=3.0.29", |
61 | | - "sounddevice~=0.4", |
62 | | - "samplerate~=0.1.0", # See https://github.com/tuxu/python-samplerate/issues/19 |
63 | | - "python-xlib; sys_platform == 'linux'", |
64 | | - "pynput; sys_platform != 'linux'", |
65 | | - ], |
66 | | - extras_require={ |
67 | | - "controller-support": ["pygame~=1.9.5"], |
68 | | - }, |
69 | | - python_requires=">=3.7", |
70 | | - entry_points={ |
71 | | - "console_scripts": [ |
72 | | - "gambaterm = gambaterm:main", |
73 | | - "gambaterm-ssh = gambaterm.ssh:main", |
| 40 | + gambatte_extension = Extension( |
| 41 | + "gambaterm.libgambatte", |
| 42 | + language="c++", |
| 43 | + include_dirs=[ |
| 44 | + *libgambatte_include_dirs, |
| 45 | + "libgambatte_ext", |
| 46 | + numpy.get_include(), |
| 47 | + ], |
| 48 | + extra_compile_args=["-DHAVE_STDINT_H"], |
| 49 | + libraries=libraries, |
| 50 | + sources=[ |
| 51 | + *libgambatte_sources, |
| 52 | + "libgambatte_ext/libgambatte.pyx", |
74 | 53 | ], |
75 | | - }, |
76 | | - package_data={"gambaterm": ["py.typed"]}, |
77 | | - description="A terminal frontend for gambatte game boy color emulator ", |
78 | | - long_description=LONG_DESCRIPTION, |
79 | | - long_description_content_type="text/markdown", |
80 | | - url="https://github.com/vxgmichel/gambatte-terminal", |
81 | | - license="GPLv3", |
82 | | - classifiers=[ |
83 | | - "Programming Language :: Python", |
84 | | - "Programming Language :: Python :: 3", |
85 | | - "Programming Language :: Python :: 3.8", |
86 | | - "Programming Language :: Python :: 3.9", |
87 | | - "Programming Language :: Python :: 3.10", |
88 | | - "Programming Language :: Python :: 3.11", |
89 | | - "Programming Language :: Python :: 3.12", |
90 | | - "Programming Language :: Python :: 3.13", |
91 | | - "Programming Language :: Python :: 3.14", |
92 | | - ], |
93 | | - author="Vincent Michel", |
94 | | - author_email="vxgmichel@gmail.com", |
95 | | -) |
| 54 | + ) |
| 55 | + |
| 56 | + termblit_extension = Extension( |
| 57 | + "gambaterm.termblit", |
| 58 | + language="c", |
| 59 | + include_dirs=[numpy.get_include()], |
| 60 | + sources=["termblit_ext/termblit.pyx"], |
| 61 | + ) |
| 62 | + |
| 63 | + return [gambatte_extension, termblit_extension] |
| 64 | + |
| 65 | + |
| 66 | +setup(ext_modules=get_extensions()) |
0 commit comments