-
Notifications
You must be signed in to change notification settings - Fork 42
/
setup.py
126 lines (99 loc) · 4.89 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""Mission Pinball Framework Media Controller (mpf-mc) setup.py.
Notes:
See pyproject.toml for the rest of the setup config.
"""
# TODO: this setup has only been tested with the .c files already generated by cython. No idea if it works with the .pyx files yet.
import sys
if sys.platform != 'win32':
import pkgconfig as pc
from collections import defaultdict
from os.path import abspath, exists, join, isdir
from setuptools import Extension, setup
sound_file_source = 'mpfmc/core/audio/sound_file.pyx',
track_source = 'mpfmc/core/audio/track.pyx',
track_standard_source = 'mpfmc/core/audio/track_standard.pyx',
track_sound_loop_source = 'mpfmc/core/audio/track_sound_loop.pyx',
audio_interface_source = 'mpfmc/core/audio/audio_interface.pyx',
playlist_controller_source = 'mpfmc/core/audio/playlist_controller.pyx',
bitmap_font_source = 'mpfmc/uix/bitmap_font/bitmap_font.pyx',
def members_appended(*ds): # shoutout to the borg backup project
result = defaultdict(list)
for d in ds:
for k, v in d.items():
assert isinstance(v, list)
result[k].extend(v)
return result
def get_isolated_env_paths(): # shoutout to the kivy project
try:
# sdl2_dev is installed before setup.py is run, when installing from
# source due to pyproject.toml. However, it is installed to a
# pip isolated env, which we need to add to compiler
import kivy_deps.sdl2_dev as sdl2_dev
except ImportError:
return [], []
root = abspath(join(sdl2_dev.__path__[0], '../../../..'))
includes = [join(root, 'Include')] if isdir(join(root, 'Include')) else []
libs = [join(root, 'libs')] if isdir(join(root, 'libs')) else []
return includes, libs
def determine_sdl2(): # shoutout to the kivy project
flags = {}
includes, _ = get_isolated_env_paths()
flags['libraries'] = ['SDL2', 'SDL2_mixer', 'SDL2_image']
sdl2_paths = []
for include in includes + [join(sys.prefix, 'include')]:
sdl_inc = join(include, 'SDL2')
if isdir(sdl_inc):
sdl2_paths.append(sdl_inc)
flags['include_dirs'] = sdl2_paths
flags['extra_link_args'] = []
flags['extra_compile_args'] = []
flags['library_dirs'] = sdl2_paths
# ensure headers for all the SDL2 and sub libraries are available
libs_to_check = ['SDL2', 'SDL2_mixer', 'SDL2_image']
for lib in libs_to_check:
found = False
for d in flags['include_dirs']:
fn = join(d, '{}.h'.format(lib))
if exists(fn):
found = True
print('SDL2: found {} header at {}'.format(lib, fn))
break
if not found:
print('SDL2: missing sub library {}'.format(lib))
return flags
if sys.platform == 'win32':
# Since Windows doesn't have pkgconfig, we have to manually find the SDL2 include location. :(
sdl2_include_path = determine_sdl2()['include_dirs'][0]
print("Setting SDL2 include path:", sdl2_include_path)
general_include_path = sdl2_include_path.strip('\SDL2') # strip the SDL2 folder
print("Setting general include path:", general_include_path)
libs_include_path = general_include_path[:-8] # strip the \include
libs_include_path = join(libs_include_path, 'libs')
print("Setting libs include path:", libs_include_path)
audio_kws = {'define_macros': [('_THREAD_SAFE', None)],
'include_dirs': [sdl2_include_path, general_include_path],
'libraries': ['SDL2_mixer', 'SDL2', 'gstreamer-1.0', 'glib-2.0', 'gobject-2.0'],
'library_dirs': [libs_include_path]}
bitmap_font_kws = {'define_macros': [('_THREAD_SAFE', None)],
'include_dirs': [sdl2_include_path, general_include_path],
'libraries': ['SDL2', 'SDL2_image'],
'library_dirs': [libs_include_path]}
else:
audio_kws = members_appended(pc.parse('SDL2_mixer'), pc.parse('gstreamer-1.0'))
try:
bitmap_font_kws = members_appended(pc.parse('sdl2'), pc.parse('SDL2_image'))
except pc.pkgconfig.PackageNotFoundError:
# SDL2_image is not found sometimes on MacOS, not sure why, but it works with the mixer paths too
bitmap_font_kws = members_appended(pc.parse('sdl2'), pc.parse('SDL2_mixer'))
ext_modules = [
Extension('mpfmc.core.audio.sound_file', [*sound_file_source], **audio_kws),
Extension('mpfmc.core.audio.track', [*track_source], **audio_kws),
Extension('mpfmc.core.audio.track_standard', [*track_standard_source], **audio_kws),
Extension('mpfmc.core.audio.track_sound_loop', [*track_sound_loop_source], **audio_kws),
Extension('mpfmc.core.audio.audio_interface', [*audio_interface_source], **audio_kws),
Extension('mpfmc.core.audio.playlist_controller', [*playlist_controller_source], **audio_kws),
Extension('mpfmc.uix.bitmap_font.bitmap_font', [*bitmap_font_source], **bitmap_font_kws,)
]
setup(
ext_modules=ext_modules,
)