-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
155 lines (136 loc) · 4.07 KB
/
setup.py
File metadata and controls
155 lines (136 loc) · 4.07 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
from setuptools import setup, Extension
import platform
import sys
import subprocess
# TODO: Only run setup.py if `[siffreadermodule]` optional
# dependency set specified
try:
import numpy
except ImportError:
raise Exception("Numpy is not yet installed on this distribution. Install numpy with pip or conda")
from setuptools.command.install import install
#from setuptools.command.install import clean
define_macros = None
extra_compile_args = None
library_dirs = None
libraries = None
# CHANGE THIS TO TRUE FOR DEBUG MODE
# or maybe I should make this a setting in the package itself?
# TODO: debug as a command line option
#DEBUG = True
DEBUG = False
class MSVCInstallCommand(install):
"""
To try to install MSVC build tools on Windows
"""
def has_msvc_build_tools(self)->bool:
# Check if cl.exe is available in PATH
try:
subprocess.check_call(
['cl'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
return True
except Exception:
return False
return False
def install_msvc_build_tools(self):
try:
subprocess.check_call(
[
'choco',
'install',
'visualstudio2019buildtools',
'-y',
]
)
except Exception:
print(
"Could not install MSVC Build Tools with Chocolatey."
+ " Please install them manually with"
+ "https://visualstudio.microsoft.com/visual-cpp-build-tools/"
)
def run(self):
if not self.has_msvc_build_tools():
print("MSVC Build Tools not found."
+ " Attempting to install with Chocolatey..."
)
self.install_msvc_build_tools()
super().run()
installclass = install
if platform.system() == 'Windows':
installclass = MSVCInstallCommand
if DEBUG:
define_macros = [('__DEBUG', 1)]
if platform.system() == 'Windows':
extra_compile_args = ["/std:c++17"]
else:
extra_compile_args = [
"-std=c++11",
#"-Werror"
]
siffmodule = Extension(
name='siffreadermodule',
sources = [
#'siffreadermodule/src/siffio.cpp',
'siffreadermodule/src/siffreader/siffreader.cpp',
'siffreadermodule/src/siffreader/siffreader_writer.cpp',
'siffreadermodule/src/siffreader/flim/histogram_methods.cpp',
'siffreadermodule/src/siffreader/flim/lifetime_methods.cpp',
'siffreadermodule/src/siffreader/intensity/intensity_methods.cpp',
'siffreadermodule/src/siffreader/time/time_methods.cpp',
'siffreadermodule/src/siffreadermodule.cpp',
'siffreadermodule/src/framedata.cpp',
'siffreadermodule/src/sifftotiff.cpp',
#'siffreadermodule/src/pyFrameData.cpp',
],
library_dirs=library_dirs,
include_dirs = [
numpy.get_include(),
],
libraries = libraries,
extra_compile_args=extra_compile_args,
language="c++",
define_macros = define_macros,
#use_scm_version=True,
)
# defined once here so that when it gets called
# multiple times I don't have to remember to re-write
# and update bits
def setupcall():
setup (
packages = ['siffpy'],
ext_modules = [siffmodule],
cmdclass={
'install': installclass,
},
python_requires='>=3.9.0',
)
try:
setupcall()
except Exception:
if (
(platform.system() == 'Darwin') and
('Clang' in sys.version)
):
# For some reason libstdc++ in some compilers doesn't define <string>?
# Sadly libc++ has painfully slow regex, but now
# I don't need to rely on regex tools.
import warnings
warnings.warn(
"""
Some Xcode sets don't define <string> in libstdc++,
so trying again with libc++
"""
)
siffmodule.extra_compile_args.append("-stdlib=libc++")
try:
setupcall()
except Exception:
warnings.warn(
""" Failed to build `siffreadermodule`, the
old file I/O backend. Attempts to use `SiffPy` with
`siffreadermodule` will fail.
"""
)