-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
182 lines (154 loc) · 6.67 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from setuptools import setup, Extension
from distutils.cmd import Command
from distutils import log
from sys import platform
import os
from multiprocessing import cpu_count
from glaze import __version__
setupPath = os.path.abspath(os.path.dirname(__file__))
GLAZEPATH = './glaze/'
glazeAbsPath = os.path.abspath(os.path.join(setupPath, GLAZEPATH))
SPECSPATH = './specs'
specsAbsPath = os.path.abspath(os.path.join(setupPath, SPECSPATH))
gladAbsPath = os.path.abspath(os.path.join(glazeAbsPath, 'glad'))
apiList = ['GL', 'EGL', 'GLX', 'WGL']
included_dirs = [glazeAbsPath, gladAbsPath]
if platform == 'win32':
libraries = ['openGL32']
# rldirs = []
extraArgs = ['/EHsc']
elif 'linux' in platform:
libraries = ['GL', "dl"]
# rldirs = ["$ORIGIN"]
extraArgs = ["-w", "-O0", '-DGL_GLEXT_PROTOTYPES',
'-fno-var-tracking', '-fno-var-tracking-assignments',
# "-std=c++11"
]
else:
libraries = ['OpenGL']
# rldirs = []
extraArgs = []
class regen(Command):
user_options = [('apis=', None, 'List of apis to generate(gl, egl, wgl, glx)'
'separated by \',\''),
('maxver=', None, 'Dictionary of api version to generate for each api as '
'api=major.minor (Defaults to latest if omitted)'),
('loader=', None, 'Library to use as loader. Example: SDL (not implemented)'),
('extensions=', None, 'List of extensions to include,'
'separated by \',\'. If empty, all extensions will be'
'added to definition'),
('profile=', None, 'OpenGL profile {core,compatibility} (defaults to compatibility)'),
('jobs=', None, 'Number of parallel jobs to run. (Default = number of cpu\'s)'),
('force-spec-dl', None, 'Force the re-download of the api specs. Usefull to get the most'
'up-to-date definitions')
]
def __init__(self, dist):
Command.__init__(self, dist)
self.versions = {}
def initialize_options(self):
self.apis = None
self.maxver = None
self.loader = None
self.extensions = None
self.profile = None
self.jobs = None
self.force_spec_dl = None
def finalize_options(self):
assert self.apis is not None, 'Api must be one or more of [gl, egl, wgl, glx]'
if self.apis is not None:
self.apis = self.apis.split(',')
if self.maxver is not None:
self.maxver = self.maxver.split(',')
for api in self.maxver:
a, v = api.split('=')
sv = v.split('.')
self.versions[a] = (int(sv[0]), int(sv[1]))
if self.extensions is not None:
self.extensions = str(self.extensions).split(',')
if platform == 'win32':
self.jobs = 0
self.announce('Jobs limited to 1 in Windows (unresolved bug).', log.WARN)
elif self.jobs is None:
self.jobs = cpu_count()
else:
self.jobs = int(self.jobs)
def run(self):
from Cython.Build import cythonize
from _ExtMaker.GlobalMaker import Maker
def regenApi(api, version):
stuff = Maker(glazeAbsPath, specsAbsPath, gladAbsPath, api, {api: version},
self.announce, self.extensions, self.profile, self.force_spec_dl)
stuff.create()
for api in self.apis:
regenApi(api, self.versions.get(api))
cythonizables = []
for file in os.listdir(glazeAbsPath):
file = os.path.join(glazeAbsPath, file)
if os.path.splitext(file)[1] == '.pyx':
cythonizables.append(file)
if not os.path.isfile(file) and os.path.basename(file) != 'glad':
for file2 in os.listdir(file):
file2 = os.path.join(file, file2)
if os.path.isfile(file2):
if os.path.splitext(file2)[1] == '.pyx':
cythonizables.append(file2)
cythonize(cythonizables,
language='c++',
# compile_time_env={'LIBRARY': b'default'},
nthreads=self.jobs,
)
self.announce('Done. Now you can build_ext / install / develop', log.INFO)
def getPackages(packages):
baseName = packages[0]
for api in apiList:
extPath = os.path.join(glazeAbsPath, api.upper())
if not os.path.exists(extPath):
continue
else:
packages.append(baseName + '.' + api)
return packages
def getExtensions():
extensions = [Extension('glaze.utils', # name
[os.path.join(glazeAbsPath, 'utils.cpp')], # sources list
libraries=libraries, include_dirs=included_dirs,
# runtime_library_dirs=rldirs,
extra_compile_args=extraArgs, language="c++")]
for api in apiList:
extPath = os.path.join(glazeAbsPath, api.upper())
if not os.path.exists(extPath):
continue
gladFilePath = os.path.join(gladAbsPath, ('glad' + ('' if api == 'GL' else '_' + api)) + '.c')
for file in os.listdir(extPath):
sources = [gladFilePath]
file = os.path.join(extPath, file)
if os.path.isfile(file):
if os.path.splitext(file)[1] == '.cpp':
sources.append(file)
ext = Extension('glaze.' + api + '.' + os.path.splitext(os.path.basename(file))[0], # name
sources, # sources list
libraries=libraries,
include_dirs=included_dirs,
# runtime_library_dirs=rldirs,
extra_compile_args=extraArgs,
language="c++")
extensions.append(ext)
return extensions
def getData():
data = []
for file in os.listdir(glazeAbsPath):
file = os.path.join(glazeAbsPath, file)
if os.path.isfile(file):
if os.path.splitext(file)[1] == '.pxd':
data.append(file)
return data
setup(
name="glaze",
packages=getPackages(["glaze"]),
ext_modules=getExtensions(),
cmdclass={'regen': regen},
# requires=['requests', 'Cython', 'glad'],
package_data={'glaze': getData()},
version=__version__,
author='Javier R. García',
description='Autogenerated Python bindings for OpenGL.'
)