-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsetup.py
461 lines (417 loc) · 15 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
from distutils.command.build import build as base_build
import glob
import os
import re
import runpy
import subprocess
import sys
from Cython.Distutils import build_ext
import numpy
from setuptools import Extension, find_packages, setup
from setuptools.command.install import install as base_install
MAJOR = 6
MINOR = 1
MICRO = 0
PRERELEASE = ""
IS_RELEASED = False
# Templates for version strings.
RELEASED_VERSION = "{major}.{minor}.{micro}{prerelease}"
UNRELEASED_VERSION = "{major}.{minor}.{micro}{prerelease}.dev{dev}"
# Distutils will collect the `.py` files for the distribution before
# building the Extensions, so `.py` files generated by SWIG will not be
# added, resulting in a broken build.
# See: https://stackoverflow.com/a/21236111
class PatchedBuild(base_build):
def run(self):
self.run_command('build_ext')
base_build.run(self)
class PatchedInstall(base_install):
def run(self):
self.run_command('build_ext')
super().run()
def git_version():
""" Return the git revision as a string
"""
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
cmd, stdout=subprocess.PIPE, env=env,
).communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'describe', '--tags'])
except OSError:
out = ''
git_description = out.strip().decode('ascii')
expr = r'.*?\-(?P<count>\d+)-g(?P<hash>[a-fA-F0-9]+)'
match = re.match(expr, git_description)
if match is None:
git_revision, git_count = 'Unknown', '0'
else:
git_revision, git_count = match.group('hash'), match.group('count')
return git_revision, git_count
def write_version_py(filename):
template = """\
# THIS FILE IS GENERATED FROM ENABLE SETUP.PY
#: The full version of the package, including a development suffix
#: for unreleased versions of the package.
version = "{version}"
#: The full version of the package, same as 'version'
#: Kept for backward compatibility
full_version = version
#: The Git revision from which this release was made.
git_revision = "{git_revision}"
#: Flag whether this is a final release
is_released = {is_released}
"""
# Adding the git rev number needs to be done inside
# write_version_py(), otherwise the import of kiva._version messes
# up the build under Python 3.
version_template = RELEASED_VERSION if IS_RELEASED else UNRELEASED_VERSION
kiva_version_path = os.path.join(os.path.dirname(__file__), 'kiva',
'_version.py')
if os.path.exists(os.path.join(os.path.dirname(__file__), '.git')):
git_revision, dev_num = git_version()
elif os.path.exists(kiva_version_path):
# must be a source distribution, use existing version file
try:
context = runpy.run_path(kiva_version_path)
git_revision, version = context['git_revision'], context['version']
except (SyntaxError, KeyError):
raise RuntimeError("Unable to read git_revision. Try removing "
"kiva/_version.py and the build directory "
"before building.")
match = re.match(r'.*?\.dev(?P<dev_num>\d+)', version)
if match is None:
dev_num = '0'
else:
dev_num = match.group('dev_num')
else:
git_revision = 'Unknown'
dev_num = '0'
with open(filename, "wt") as fp:
fp.write(
template.format(
version=version_template.format(
major=MAJOR,
minor=MINOR,
micro=MICRO,
prerelease=PRERELEASE,
dev=dev_num
),
git_revision=git_revision,
is_released=IS_RELEASED
)
)
def agg_extensions():
kiva_agg_dir = os.path.join('kiva', 'agg')
agg_dir = os.path.join(kiva_agg_dir, 'agg-24')
freetype_dir = os.path.join(kiva_agg_dir, 'freetype2')
freetype2_sources = [
'autofit/autofit.c', 'base/ftbase.c', 'base/ftbbox.c', 'base/ftbdf.c',
'base/ftbitmap.c', 'base/ftdebug.c', 'base/ftglyph.c', 'base/ftinit.c',
'base/ftmm.c', 'base/ftsystem.c', 'base/fttype1.c', 'base/ftxf86.c',
'bdf/bdf.c', 'cff/cff.c', 'cid/type1cid.c', 'gzip/ftgzip.c',
'lzw/ftlzw.c', 'pcf/pcf.c', 'pfr/pfr.c', 'psaux/psaux.c',
'pshinter/pshinter.c', 'psnames/psnames.c', 'raster/raster.c',
'sfnt/sfnt.c', 'smooth/smooth.c', 'truetype/truetype.c',
'type1/type1.c', 'type42/type42.c', 'winfonts/winfnt.c',
]
freetype2_dirs = [
'autofit', 'base', 'bdf', 'cache', 'cff', 'cid', 'gxvalid', 'gzip',
'lzw', 'otvalid', 'pcf', 'pfr', 'psaux', 'pshinter', 'psnames',
'raster', 'sfnt', 'smooth', 'tools', 'truetype', 'type1', 'type42',
'winfonts',
]
define_macros = [
# Numpy defines
('NUMPY', None),
('PY_ARRAY_TYPES_PREFIX', 'NUMPY_CXX'),
('OWN_DIMENSIONS', '0'),
('OWN_STRIDES', '0'),
# Freetype defines
('FT2_BUILD_LIBRARY', None)
]
extra_link_args = []
include_dirs = []
if sys.platform == 'win32':
plat = 'win32'
elif sys.platform == 'darwin':
plat = 'osx'
darwin_frameworks = ['ApplicationServices']
for framework in darwin_frameworks:
extra_link_args.extend(['-framework', framework])
include_dirs += [
'/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x
for x in darwin_frameworks
]
define_macros += [('__DARWIN__', None)]
else:
# This should work for most linux distributions
plat = 'x11'
freetype2_sources = [os.path.join(freetype_dir, 'src', src)
for src in freetype2_sources]
freetype2_dirs = [
os.path.join(freetype_dir, 'src'),
os.path.join(freetype_dir, 'include'),
] + [os.path.join(freetype_dir, 'src', d) for d in freetype2_dirs]
agg_sources = [
*glob.glob(os.path.join(agg_dir, 'src', '*.cpp')),
*glob.glob(os.path.join(agg_dir, 'font_freetype', '*.cpp')),
]
kiva_agg_sources = [
*glob.glob(os.path.join(kiva_agg_dir, 'src', 'kiva_*.cpp')),
] + agg_sources + freetype2_sources
agg_include_dirs = [
os.path.join(agg_dir, 'include'),
os.path.join(agg_dir, 'font_freetype'),
] + freetype2_dirs
include_dirs += [
numpy.get_include(),
os.path.join(kiva_agg_dir, 'src'),
] + agg_include_dirs
swig_opts = [
'-I' + os.path.join(kiva_agg_dir, 'src'),
'-I' + os.path.join(agg_dir, 'include'),
'-c++',
]
# Platform support extension
plat_support_sources = [
os.path.join(kiva_agg_dir, 'src', plat, 'plat_support.i'),
os.path.join(kiva_agg_dir, 'src', plat, 'agg_bmp.cpp'),
]
plat_support_swig_opts = [
'-outdir', kiva_agg_dir, # write plat_support.py to this dir
'-c++',
'-I' + os.path.join(kiva_agg_dir, 'src'),
]
plat_support_libraries = []
if plat != 'osx':
plat_support_sources.append(
os.path.join(kiva_agg_dir, 'src', plat,
'agg_platform_specific.cpp')
)
if plat == 'win32':
plat_support_libraries += ['gdi32', 'user32']
elif plat == 'x11':
plat_support_libraries += ['X11']
return [
Extension(
'kiva.agg._agg',
sources=[
os.path.join(kiva_agg_dir, 'agg.i'),
] + kiva_agg_sources,
swig_opts=swig_opts,
include_dirs=include_dirs,
extra_link_args=extra_link_args,
define_macros=define_macros,
language='c++',
),
Extension(
'kiva.agg._plat_support',
sources=plat_support_sources,
swig_opts=plat_support_swig_opts,
include_dirs=include_dirs,
extra_link_args=extra_link_args,
define_macros=define_macros,
libraries=plat_support_libraries,
language='c++',
),
]
def base_extensions():
return [
Extension(
'kiva._cython_speedups',
sources=[
'kiva/_cython_speedups.pyx',
'kiva/_hit_test.cpp'
],
depends=[
'kiva/_hit_test.h',
'kiva/_hit_test.pxd',
],
include_dirs=['kiva', numpy.get_include()],
language='c++',
),
Extension(
'kiva._marker_renderer',
sources=['kiva/_marker_renderer.pyx'],
depends=[
'kiva/_marker_renderer.pxd',
],
include_dirs=[
os.path.join('kiva', 'markers', 'agg'),
os.path.join('kiva', 'markers'),
numpy.get_include(),
],
define_macros=[
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
],
language='c++',
),
]
def macos_extensions():
extra_link_args = []
frameworks = [
'Cocoa', 'CoreFoundation', 'ApplicationServices', 'Foundation'
]
include_dirs = [
'/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x
for x in frameworks
]
for framework in frameworks:
extra_link_args.extend(['-framework', framework])
return [
Extension(
'kiva.quartz.ABCGI',
sources=[
'kiva/quartz/ABCGI.pyx',
'kiva/quartz/Python.pxi',
'kiva/quartz/numpy.pxi',
'kiva/quartz/CoreFoundation.pxi',
'kiva/quartz/CoreGraphics.pxi',
'kiva/quartz/CoreText.pxi',
],
extra_link_args=extra_link_args,
include_dirs=[numpy.get_include()],
),
Extension(
'kiva.quartz.CTFont',
sources=[
'kiva/quartz/CTFont.pyx',
'kiva/quartz/CoreFoundation.pxi',
'kiva/quartz/CoreGraphics.pxi',
'kiva/quartz/CoreText.pxi',
],
extra_link_args=extra_link_args,
),
Extension(
'kiva.quartz.mac_context',
sources=[
'kiva/quartz/mac_context.c',
'kiva/quartz/mac_context_cocoa.m',
],
depends=[
'kiva/quartz/mac_context.h',
],
extra_link_args=extra_link_args,
include_dirs=include_dirs,
)
]
if __name__ == "__main__":
# Write version modules as needed
enable_version_path = os.path.join('enable', '_version.py')
write_version_py(filename=enable_version_path)
write_version_py(filename=os.path.join('kiva', '_version.py'))
# Read the version
context = runpy.run_path(enable_version_path)
__version__ = context['full_version']
# Read the requirements from enable.__init__
enable_init_path = os.path.join('enable', '__init__.py')
context = runpy.run_path(enable_init_path)
__extras_require__ = context['__extras_require__']
__requires__ = context['__requires__']
with open('README.rst', 'r') as fp:
long_description = fp.read()
# Collect extensions
ext_modules = base_extensions() + agg_extensions()
if sys.platform == 'darwin':
ext_modules += macos_extensions()
setup(
name='enable',
version=__version__,
author='Enthought, Inc',
author_email='[email protected]',
maintainer='ETS Developers',
maintainer_email='[email protected]',
url='https://github.com/enthought/enable/',
# Note that this URL is only valid for tagged releases.
download_url=('https://github.com/enthought/enable/archive/'
'{0}.tar.gz'.format(__version__)),
license='BSD',
classifiers=[c.strip() for c in """\
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Operating System :: MacOS
Operating System :: Microsoft :: Windows
Operating System :: OS Independent
Operating System :: POSIX
Operating System :: Unix
Programming Language :: C
Programming Language :: Python
Topic :: Scientific/Engineering
Topic :: Software Development
Topic :: Software Development :: Libraries
""".splitlines() if len(c.strip()) > 0],
platforms=['Windows', 'Linux', 'macOS', 'Unix', 'Solaris'],
description='low-level drawing and interaction',
long_description=long_description,
long_description_content_type="text/x-rst",
install_requires=__requires__,
extras_require=__extras_require__,
cmdclass={
'build': PatchedBuild,
'install': PatchedInstall,
'build_ext': build_ext,
},
entry_points={
'enable.toolkits': [
'null = enable.null.toolkit:toolkit',
'qt = enable.qt.toolkit:toolkit',
'qt4 = enable.qt.toolkit:toolkit',
'wx = enable.wx.toolkit:toolkit',
],
'etsdemo_data': [
'enable_examples = enable.examples._etsdemo_info:info',
'kiva_examples = kiva.examples._etsdemo_info:info',
]
},
ext_modules=ext_modules,
packages=find_packages(exclude=['ci', 'docs']),
package_data={
'': ['*.zip', '*.svg', 'images/*'],
'enable': ['tests/primitives/data/PngSuite/*.png'],
'enable.examples': [
'demo/*',
'demo/*/*',
'demo/*/*/*',
'demo/*/*/*/*',
'demo/*/*/*/*/*',
],
'enable.savage.trait_defs.ui.wx': ['data/*.svg'],
'kiva': [
'tests/agg/doubleprom_soho_full.jpg',
'fonttools/data/*.ttf',
'fonttools/tests/data/*.afm',
'fonttools/tests/data/*.ttc',
'fonttools/tests/data/*.ttf',
'fonttools/tests/data/*.txt',
],
'kiva.examples': [
'kiva/*',
'kiva/*/*',
],
},
zip_safe=False,
python_requires=">=3.7",
)