-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathsetup.py
More file actions
881 lines (735 loc) · 29.8 KB
/
setup.py
File metadata and controls
881 lines (735 loc) · 29.8 KB
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
"""
Installation script for the snappy module.
Depends heavily on setuptools.
"""
no_setuptools_message = """
You need to have setuptools installed to build the snappy module. See:
https://packaging.python.org/installing/
"""
required_cython_version = '0.28'
no_cython_message = """
You need to have Cython (>= %s) installed to build the snappy
module since you're missing the autogenerated C/C++ files, e.g.
sudo python -m pip install "cython>=%s"
""" % (required_cython_version, required_cython_version)
no_sphinx_message = """
You need to have Sphinx installed to rebuild the
documentation for snappy module, e.g.
sudo python -m pip install sphinx
"""
no_sphinx_theme_message = """
You need to have Spinx's rtd theme installed to rebuild the
documentation for snappy module, e.g.
sudo python -m pip install sphinx_rtd_theme
"""
no_wheel_message = """
You need to have wheel installed to install snappy, e.g.,
sudo python -m pip install "wheel"
"""
try:
import setuptools
except ImportError:
raise ImportError(no_setuptools_message)
try:
import wheel
except ImportError:
raise ImportError(no_wheel_message)
import os, platform, shutil, site, subprocess, sys, sysconfig, re
from os.path import getmtime, exists
from glob import glob
import importlib.metadata
# Remove '.' from the path so that Sphinx doesn't try to load the SnapPy module directly
try:
sys.path.remove(os.path.realpath(os.curdir))
except ValueError:
pass
from setuptools.extension import Extension
from setuptools import setup, Command
from setuptools import Distribution
from setuptools.command.build_clib import build_clib
from setuptools.command.sdist import sdist
try:
from Cython.Build import cythonize
from Cython import __version__ as cython_version
have_cython = True
except ImportError as e:
have_cython = False
cython_import_error = e
def get_build_temp_dir():
dist = Distribution()
dummy_cmd = build_clib(dist)
dummy_cmd.ensure_finalized()
return dummy_cmd.build_temp
build_temp_dir = get_build_temp_dir()
def distutils_dir_name(dname):
"""Returns the name of a distutils build subdirectory"""
name = "build/{prefix}.{plat}-{ver[0]}{ver[1]}".format(
prefix=dname, plat=sysconfig.get_platform(), ver=sys.version_info)
if dname == 'temp' and sys.platform == 'win32':
name += os.sep + 'Release'
return name
def build_lib_dir():
return os.path.abspath(distutils_dir_name('lib'))
def check_call(args):
try:
subprocess.check_call(args)
except subprocess.CalledProcessError:
executable = args[0]
command = [a for a in args if not a.startswith('-')][-1]
raise RuntimeError(command + ' failed for ' + executable)
cythoned_dir = 'cythoned'
###############################################################################
# Custom SnapPy commands
# A real clean
class SnapPyClean(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
junkdirs = (glob('build/lib*') +
glob('build/bdist*') +
glob('build/temp*') +
glob('snappy*.egg-info') +
glob(cythoned_dir) +
['__pycache__', os.path.join('src', 'snappy', 'doc')]
)
for dir in junkdirs:
try:
shutil.rmtree(dir)
except OSError:
pass
junkfiles = glob('src/*.so*') + glob('src/*.pyc')
for file in junkfiles:
try:
os.remove(file)
except OSError:
pass
class SnapPyBuildDocs(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if not os.path.exists('doc_src'):
return # Are in an sdist and may not have sphinx
try:
import sphinx
except ImportError:
raise ImportError(no_sphinx_message)
try:
import sphinx_rtd_theme
except ImportError:
raise ImportError(no_sphinx_theme_message)
sphinx_dist = importlib.metadata.Distribution.from_name('sphinx')
sphinx_cmd = sphinx_dist.entry_points['sphinx-build'].load()
sphinx_args = ['-a', '-E', '-d', 'doc_src/_build/doctrees',
'doc_src', 'src/snappy/doc']
sys.path.insert(0, build_lib_dir())
status = sphinx_cmd(sphinx_args)
if status != 0:
sys.exit(status)
class SnapPyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sys.path.insert(0, build_lib_dir())
from snappy.test import runtests
print('Running tests ...')
sys.exit(runtests())
class SnapPyApp(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sys.path.insert(0, build_lib_dir())
import snappy.app
snappy.app.main()
class SnapPySdist(sdist):
def run(self):
python = sys.executable
check_call([python, 'setup.py', 'build_docs'])
sdist.run(self)
class SnapPyPipInstall(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
python = sys.executable
check_call([python, 'setup.py', 'bdist_wheel'])
egginfo = 'snappy.egg-info'
if os.path.exists(egginfo):
shutil.rmtree(egginfo)
wheels = glob('dist' + os.sep + '*.whl')
new_wheel = max(wheels, key=os.path.getmtime)
check_call([python, '-m', 'pip', 'uninstall', '-y', 'snappy'])
check_call([python, '-m', 'pip', 'install', '--upgrade',
'--upgrade-strategy', 'only-if-needed',
new_wheel])
###############################################################################
# System specific compiler and environment setup
if sys.platform == 'darwin':
macos_arch = sysconfig.get_platform().split('-')[-1]
macos_targets = {'x86_64':'10.9', 'arm64': '11', 'universal2': '10.9'}
# On some python distributions for Mac OS X, one needs to set this
# environment variable to 10.14.
os.environ['MACOSX_DEPLOYMENT_TARGET'] = macos_targets[macos_arch]
if sys.platform == 'win32':
# For Windows, check the compiler we will be using.
win_cc = 'msvc'
for arg in sys.argv:
if arg.startswith('--compiler='):
win_cc = arg.split('=')[1]
def split_version(s : str):
return [int(x) for x in s.split('.')]
def replace_ext(file, new_ext):
if new_ext is None:
return file
root, ext = os.path.splitext(file)
return root + '.' + new_ext
# We check manually which object files need to be rebuilt; distutils
# is overly cautious and always rebuilds everything, which makes
# development painful.
def modtime(file):
if os.path.exists(file):
return os.path.getmtime(file)
else:
return 0.0
class SourceAndObjectFiles():
def __init__(self):
self.sources_to_build, self.up_to_date_objects = [], []
self.obj_ext = 'obj' if sys.platform.startswith('win') else 'o'
self.cython_file = None
self.mod_time_dependencies = None
def set_headers(self, files):
"""
Call before anything else.
If set_headers is called, an object file older than any header is forced to
be rebuild.
"""
if files:
self.mod_time_dependencies = max(modtime(file) for file in files)
def set_cython_file_language_and_dependencies(
self, cython_file, language, dependencies = []):
"""
Sets the cython file. Populates cythoned_file. Forces the object file
to be rebuild if cython_file or any file in dependencies is newer.
language is the file extension of the cythoned file.
"""
self.cython_file = cython_file
self.cythoned_file = replace_ext(cythoned_dir + '/' + cython_file, language)
all_dependencies = [cython_file] + dependencies
self.add(self.cythoned_file, all_dependencies)
t = modtime(self.cythoned_file)
self.needs_cythonize = any(t < modtime(d) for d in all_dependencies)
def add(self, source_file, dependencies = []):
"""
Add source file. Forces object file to be rebuild if source file or any
file in dependencies is newer.
"""
object_file = build_temp_dir + os.sep + replace_ext(source_file, self.obj_ext)
t = modtime(object_file)
if (t < modtime(source_file) or
any(t < modtime(file) for file in dependencies) or
(self.mod_time_dependencies is not None and t < self.mod_time_dependencies)):
self.sources_to_build.append(source_file)
else:
self.up_to_date_objects.append(object_file)
def cythonize(self):
if self.cython_file is None:
return
if not self.needs_cythonize:
return
if any( (non_build in sys.argv)
for non_build in [ 'clean', 'egg_info', 'dist_info' ]):
return
if not have_cython:
if not exists(self.cythoned_file):
raise ImportError(
no_cython_message +
'Missing Cythoned file: ' + self.cythoned_file +
'\n[Cython import error: %r]' % cython_import_error +
'\n[Command line arguments: %r]' % sys.argv)
return
if split_version(cython_version) < split_version(required_cython_version):
raise ImportError(
'Wrong cython version installed. '
'Required version: %s. Installed version: %s.' % (
required_cython_version, cython_version))
cythonize([self.cython_file],
compiler_directives={'embedsignature': True},
build_dir=cythoned_dir)
def make_extension(spec) -> Extension:
"""
Uses members of spec to create an Extension, mostly just
forwarding the members as arguments to the Extension call.
Supports cython.
Unlike the bare Extension, it supports a slightly more
fine-grained dependency tracking:
1. The cython file (specified by spec.cython_file) is
re-cythoned and the resulting file recompiled
if the cython file itself or any .pyx or .pxi file in a
directory in cython_paths has changed.
2. All source files are re-compiled if any .h file
in any directory in spec.include_dirs has changed.
3. A source file is re-compiled if the file itself or any file in
self.additional_dependencies[SRC_FILE_NAME]
has changed.
Note that it does not recurse into the subdirectories of a given
directory.
Mandatory members of spec:
- name
- language
- sources
- include_dirs
- extra_compile_args
- extra_link_args
Optional members of spec:
- cython_file
- extra_objects
- libraries
- cython_paths (required if there is a cython_file): Not
forwarded to Extension, only used for dependency
tracking.
- additional_dependencies: Not forwarded to Extension, only used
for dependency tracking.
"""
ext_files = SourceAndObjectFiles()
ext_files.set_headers(
[ header
for include_path in spec.include_dirs
for header in glob(os.path.join(include_path, '*.h')) ])
additional_dependencies = getattr(spec, 'additional_dependencies', {})
for src_file in spec.sources:
ext_files.add(src_file, additional_dependencies.get(src_file, []))
if hasattr(spec, 'cython_file'):
ext_files.set_cython_file_language_and_dependencies(
spec.cython_file,
'cpp' if spec.language == 'c++' else 'c',
[ cython_file
for cython_path in spec.cython_paths
for cython_file in (
glob(os.path.join(cython_path, '*.pyx')) +
glob(os.path.join(cython_path, '*.pxi'))) ])
ext_files.cythonize()
return Extension(
name = spec.name,
sources = ext_files.sources_to_build,
include_dirs = spec.include_dirs,
language = spec.language,
libraries = getattr(spec, 'libraries', None),
extra_compile_args = spec.extra_compile_args,
extra_link_args = spec.extra_link_args,
extra_objects = ext_files.up_to_date_objects + getattr(spec, 'extra_objects', []))
def remove_files(a, b):
return [ file
for file in a
if os.path.basename(file) not in b ]
def compute_dependencies(
sources,
src,
dst,
dst_extension = None):
return {
replace_ext(source.replace(src, dst), dst_extension) : [ source ]
for source in sources }
###############################################################################
# The Extensions
ext_modules = []
class SharedExtensionSpec:
"""
Not a full spec that can be passed to make_extension.
Used by other Extension specifications which use the shared code
in extensions/shared or use the same compiler flags.
"""
base_path = os.path.join('src', 'snappy', 'extensions', 'shared')
cython_path = os.path.join(base_path, 'cython_src')
extra_compile_args = []
extra_link_args = []
if sys.platform == 'darwin':
# On macOS, the C and C++ code generated by Cython produces lots of these.
# Since we cannot do anything about them, the warnings are just noise.
# The kernel code does not generate any of them.
extra_compile_args += [ '-Wno-unreachable-code' ]
elif sys.platform == 'win32':
if win_cc == 'msvc':
extra_compile_args += ['/EHsc']
include_debugging_symbols = False
if include_debugging_symbols:
extra_compile_args += [
'/DDEBUG', '/Zi', '/FdSnapPy.cp37-win_amd64.pdb' ]
elif sys.version_info == (3, 4):
extra_link_args += ['-lmsvcr100' ]
class SnapPyExtensionSpec:
"""
The SnapPy extension. See make_extension for the meaning of the fields.
"""
base_path = os.path.join('src', 'snappy', 'extensions', 'SnapPy')
kernel_path = os.path.join(base_path, 'kernel')
cython_path = os.path.join(base_path, 'cython_src')
# Simply Passed to Extension.
name = 'snappy.extensions.SnapPy'
# Simply Passed to Extension.
language = 'c'
# File to cythonize.
cython_file = os.path.join(cython_path, 'SnapPy.pyx')
# Sources to compile.
sources = (
glob(os.path.join(kernel_path, 'kernel_code', '*.c')) +
remove_files(
glob(os.path.join(kernel_path, 'unix_kit', '*.c')),
['unix_UI.c', 'decode_new_DT.c']) +
glob(os.path.join(kernel_path, 'addl_code', '*.c')))
# Passed to Extension.
#
# Also for dependency tracking: Any change to a .h file in these
# directories also forces a recompilation of all sources.
include_dirs = [
os.path.join(kernel_path, 'headers'),
os.path.join(kernel_path, 'headers', 'precision', 'double'),
os.path.join(kernel_path, 'addl_code'),
os.path.join(kernel_path, 'unix_kit')
]
# Purely for dependency tracking:
# Any changes to a .pyx or .pxi file in any of these directories
# or subdirectories triggers re-cythonizing.
cython_paths = [
cython_path,
os.path.join(cython_path, 'core'),
SharedExtensionSpec.cython_path,
os.path.join(SharedExtensionSpec.cython_path, 'precision', 'double') ]
extra_compile_args = SharedExtensionSpec.extra_compile_args
extra_link_args = SharedExtensionSpec.extra_link_args
ext_modules.append(make_extension(SnapPyExtensionSpec))
class SnapPyHPExtensionSpec:
"""
The SnapPyHP extension. See make_extension for the meaning of the fields.
"""
base_path = os.path.join('src', 'snappy', 'extensions', 'SnapPyHP')
kernel_path = os.path.join(base_path, 'kernel')
cython_path = os.path.join(base_path, 'cython_src')
name = 'snappy.extensions.SnapPyHP'
language = 'c++'
cython_file = os.path.join(cython_path, 'SnapPyHP.pyx')
# Each .c file in SnapPy has a corresponding .cpp file which
# simply includes the .c file. We record this dependency here.
snappy_dependencies = compute_dependencies(
sources=SnapPyExtensionSpec.sources,
src=SnapPyExtensionSpec.base_path,
dst=base_path,
dst_extension='cpp')
for src_file in snappy_dependencies.keys():
assert os.path.exists(src_file), src_file
sources = (
list(snappy_dependencies.keys()) +
glob(os.path.join(base_path, 'qd', 'src', '*.cpp')))
include_dirs = [
os.path.join(SnapPyExtensionSpec.kernel_path, 'headers'),
os.path.join(SnapPyExtensionSpec.kernel_path, 'headers', 'precision', 'qd'),
os.path.join(SnapPyExtensionSpec.kernel_path, 'kernel_code'),
os.path.join(SnapPyExtensionSpec.kernel_path, 'addl_code'),
os.path.join(SnapPyExtensionSpec.kernel_path, 'unix_kit'),
os.path.join(base_path, 'qd', 'include')
]
cython_paths = [
cython_path,
os.path.join(SnapPyExtensionSpec.cython_path, 'core'),
SharedExtensionSpec.cython_path,
os.path.join(SharedExtensionSpec.cython_path, 'precision', 'qd') ]
additional_dependencies = snappy_dependencies
extra_compile_args = SharedExtensionSpec.extra_compile_args
x86_64_compile_args = ['-mfpmath=sse', '-msse2', '-mieee-fp']
if sys.platform == 'darwin':
if macos_arch == 'x86_64':
extra_compile_args += x86_64_compile_args
elif sys.platform == 'win32' and win_cc == 'mcvc':
if platform.architecture()[0] == '32bit':
extra_compile_args += ['/arch:SSE2']
extra_compile_args += ['/MT']
elif platform.machine() == 'x86_64':
x86_64_compile_args = ['-mfpmath=sse', '-msse2', '-mieee-fp']
if have_cython:
if [int(x) for x in cython_version.split('.')[:2]] < [3, 0]:
if sys.platform == 'win32':
extra_compile_args += ['/DFORCE_C_LINKAGE']
else:
extra_compile_args += ['-DFORCE_C_LINKAGE']
extra_link_args = SharedExtensionSpec.extra_link_args
ext_modules.append(make_extension(SnapPyHPExtensionSpec))
class OrbExtensionSpec:
"""
The Orb extension. See make_extension for the meaning of the fields.
"""
base_path = os.path.join('src', 'snappy', 'extensions', 'Orb')
kernel_path = os.path.join(base_path, 'kernel')
cython_path = os.path.join(base_path, 'cython_src')
name = 'snappy.extensions.Orb'
language = 'c'
cython_file = os.path.join(cython_path, 'Orb.pyx')
sources = (
remove_files(
glob(os.path.join(kernel_path, 'code', '*.c')),
['unix_UI.c']) +
glob(os.path.join(kernel_path, 'addl_code', '*.c')) +
glob(os.path.join(kernel_path, 'unix_kit', '*.c')))
include_dirs = [
os.path.join(kernel_path, 'headers'),
os.path.join(kernel_path, 'headers', 'precision', 'double'),
os.path.join(kernel_path, 'addl_code'),
os.path.join(kernel_path, 'unix_kit')
]
cython_paths = [
os.path.join(base_path, 'cython_src'),
os.path.join(base_path, 'cython_src', 'core'),
os.path.join(SharedExtensionSpec.cython_path, 'precision', 'qd')
]
snappy_dependencies = compute_dependencies(
sources=[os.path.join(SnapPyExtensionSpec.kernel_path, 'addl_code', 'dilog.c'),
os.path.join(SnapPyExtensionSpec.kernel_path, 'unix_kit', 'ostream.c')],
src=SnapPyExtensionSpec.base_path,
dst=base_path)
additional_dependencies = snappy_dependencies
extra_compile_args = SharedExtensionSpec.extra_compile_args
extra_link_args = SharedExtensionSpec.extra_link_args
ext_modules.append(make_extension(OrbExtensionSpec))
class MissingGLError(RuntimeError):
pass
def find_GL_include_dir_mac():
sdk_roots = [
'/Library/Developer/CommandLineTools/SDKs',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs'
]
OS_X_ver = int(platform.mac_ver()[0].split('.')[1])
version_strings = [ 'MacOSX10.%d.sdk' % OS_X_ver, 'MacOSX.sdk' ]
possible_roots = [ '' ] + [
'%s/%s' % (sdk_root, version_string)
for sdk_root in sdk_roots
for version_string in version_strings ]
header_dir = '/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers'
possible_include_dirs = [ root + header_dir for root in possible_roots ]
for include_dir in possible_include_dirs:
if exists(os.path.join(include_dir, 'gl.h')):
return include_dir
raise MissingGLError(
"The OpenGL header gl.h was not found at either of the following "
"locations: %s." % (', '.join(possible_include_dirs)))
try:
class CyOpenGLExtensionSpec:
"""
The CyOpenGL extension. See make_extension for the meaning of the fields.
"""
base_path = os.path.join('src', 'snappy', 'extensions', 'CyOpenGL')
name = 'snappy.extensions.CyOpenGL'
language = 'c'
cython_file = os.path.join(base_path, 'CyOpenGL.pyx')
cython_paths = [
base_path,
os.path.join(base_path, 'common'),
os.path.join(base_path, 'legacy'),
os.path.join(base_path, 'modern') ]
sources = []
additional_dependencies = {}
include_dirs = []
extra_compile_args = SharedExtensionSpec.extra_compile_args
extra_link_args = SharedExtensionSpec.extra_link_args
extra_objects = []
libraries = []
has_headers = False
if sys.platform == 'darwin':
include_dirs += [ find_GL_include_dir_mac() ]
extra_link_args += ['-framework', 'OpenGL']
elif sys.platform == 'linux2' or sys.platform == 'linux':
libraries += ['GL']
gl_header = '/usr/include/GL/gl.h'
if not exists(gl_header):
raise MissingGLError(
"The OpenGL header %s is not installed." % gl_header)
elif sys.platform == 'win32':
# Pick up glew
include_dirs += [ base_path ]
if platform.architecture()[0] == '32bit':
extra_objects += [
os.path.join(
base_path, 'glew/lib/Release/Win32/glew32s.lib')]
else:
extra_objects += [
os.path.join(
base_path, 'glew/lib/Release/x64/glew32s.lib')]
if win_cc == 'msvc':
extra_objects += ['opengl32.lib']
else:
extra_objects += ['/mingw/lib/libopengl32.a']
else:
raise MissingGLError(
"The SnapPy build does not support OpenGL on this platform "
"(%s)." % sys.platform)
ext_modules.append(make_extension(CyOpenGLExtensionSpec))
except MissingGLError as e:
print("***WARNING*** Many graphics features will not be available because "
"OpenGL cannot be build.")
print(e)
env_var = os.environ.get('SNAPPY_ALWAYS_BUILD_CYOPENGL', 'False')
if env_var not in ['0', 'false', 'False']:
raise RuntimeError('Cannot build CyOpenGL but '
'SNAPPY_ALWAYS_BUILD_CYOPENGL is set.')
class TwisterCoreExtensionSpec:
"""
The Twister core extension. See make_extension for the meaning of the fields.
"""
base_path = os.path.join('src', 'snappy', 'twister', 'lib')
kernel_path = os.path.join(base_path, 'kernel')
name = 'snappy.twister.twister_core'
language = 'c++'
sources = [
os.path.join(kernel_path, 'twister.cpp'),
os.path.join(kernel_path, 'manifold.cpp'),
os.path.join(kernel_path, 'parsing.cpp'),
os.path.join(kernel_path, 'global.cpp'),
os.path.join(base_path, 'py_wrapper.cpp') ]
include_dirs = [ kernel_path ]
additional_dependencies = {}
extra_compile_args = SharedExtensionSpec.extra_compile_args
if sys.platform == 'win32' and win_cc == 'msvc':
extra_compile_args += ['/MT']
extra_link_args = []
ext_modules.append(make_extension(TwisterCoreExtensionSpec))
###############################################################################
# snappy
install_requires = ['FXrays>=1.3',
'plink>=2.4.9',
'spherogram>=2.4.1',
'snappy_manifolds>=1.4',
'low_index>=1.2.1',
'tkinter-gl>=1.0',
'decorator',
'packaging',
'pypng', # Used to save OpenGL images.
'PyX', # Used to save PDF images of links.
'pickleshare', # To avoid https://github.com/ipython/ipython/issues/14416
]
try:
import sage
except ImportError:
install_requires.append('cypari>=2.3')
install_requires.append('ipython>=5.0')
# Get version number:
exec(open('src/snappy/version.py').read())
# Get long description from README
long_description = open('README.rst').read()
long_description = long_description.split('Downloads')[0]
# Off we go ...
setup( name = 'snappy',
version = version,
zip_safe = False,
force = True,
python_requires = '>=3.8',
install_requires = install_requires,
packages = ['snappy',
'snappy/manifolds',
'snappy/twister',
'snappy/snap',
'snappy/snap/t3mlite',
'snappy/snap/peripheral',
'snappy/snap/slice_obs_HKL',
'snappy/ptolemy',
'snappy/hyperboloid',
'snappy/geometric_structure',
'snappy/geometric_structure/geodesic',
'snappy/geometric_structure/cusp_neighborhood',
'snappy/upper_halfspace',
'snappy/verify',
'snappy/verify/complex_volume',
'snappy/tiling',
'snappy/drilling',
'snappy/cusps',
'snappy/len_spec',
'snappy/margulis',
'snappy/exterior_to_link',
'snappy/raytracing',
'snappy/raytracing/shaders',
'snappy/raytracing/zoom_slider',
'snappy/tests',
'snappy/tests/files',
'snappy/dev',
'snappy/dev/extended_ptolemy',
'snappy/dev/vericlosed',
'snappy/dev/vericlosed/orb',
],
package_data = {
'snappy' : ['info_icon.gif', 'SnapPy.ico', 'SnapPy.png',
'doc/*.*',
'doc/_images/*',
'doc/_sources/*',
'doc/_static/*',
'doc/_static/js/*',
'doc/_static/css/*',
'doc/_static/css/fonts/*'],
'snappy/manifolds' : ['HTWKnots/*.gz'],
'snappy/twister' : ['surfaces/*'],
'snappy/ptolemy':['magma/*.magma_template',
'testing_files/*magma_out.bz2',
'testing_files/data/pgl2/OrientableCuspedCensus/03_tetrahedra/*magma_out',
'regina_testing_files/*magma_out.bz2',
'testing_files_generalized/*magma_out.bz2',
'regina_testing_files_generalized/*magma_out.bz2',
'testing_files_rur/*rur.bz2'],
'snappy/exterior_to_link': ['geodesic_map.json'],
'snappy/raytracing/shaders' : ['*.glsl', '*.png'],
'snappy/raytracing/zoom_slider': ['*.png', '*.gif'],
'snappy/raytracing/zoom_slider': ['*.png'],
'snappy/tests/files': ['*.orb', '*.tri'],
'snappy/dev/vericlosed/orb' : ['orb_solution_for_snappea_finite_triangulation_mac'],
},
package_dir = {
'': 'src',
'snappy/twister':'src/snappy/twister/lib',
'snappy/dev':'dev/python',
'snappy/dev/extended_ptolemy':'dev/extended_ptolemy',
'snappy/dev/vericlosed':'dev/vericlosed',
'snappy/dev/vericlosed/orb':'dev/vericlosed/orb',
},
ext_modules = ext_modules,
cmdclass = {'clean' : SnapPyClean,
'build_docs': SnapPyBuildDocs,
'test': SnapPyTest,
'app': SnapPyApp,
'sdist':SnapPySdist,
'pip_install':SnapPyPipInstall,
},
entry_points = {'console_scripts': ['SnapPy = snappy.app:main']},
description= 'Studying the topology and geometry of 3-manifolds, with a focus on hyperbolic structures.',
long_description = long_description,
long_description_content_type = 'text/x-rst',
author = 'Marc Culler and Nathan M. Dunfield',
author_email = 'culler@uic.edu, nathan@dunfield.info',
license='GPLv2+',
url = 'http://snappy.computop.org',
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Cython',
'Topic :: Scientific/Engineering :: Mathematics',
],
keywords = '3-manifolds, topology, hyperbolic geometry',
options={
"build_ext": {
"force": any(
len(ext_module.sources) > 0
for ext_module in ext_modules)
}
}
)