-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
230 lines (195 loc) · 7.02 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
try:
import setuptools # @UnusedImport # NOQA
except:
pass
try:
import numpy # @UnusedImport # NOQA
except:
msg = ("No module named numpy. "
"Please install numpy first, it is needed before installing ObsPy.")
raise ImportError(msg)
import sys
import os
import inspect
import glob
import platform
from distutils.errors import DistutilsSetupError
from numpy.distutils.core import setup
from numpy.distutils.ccompiler import get_default_compiler
from numpy.distutils.command.build import build
from numpy.distutils.command.install import install
from numpy.distutils.exec_command import exec_command, find_executable
from numpy.distutils.misc_util import Configuration
from setuptools import find_packages
from obspy.core.util.libnames import _get_lib_name
print(sys.path.pop(0))
# Directory of the current file in the (hopefully) most reliable way
# possible, according to krischer
SETUP_DIRECTORY = os.path.dirname(os.path.abspath(inspect.getfile(
inspect.currentframe())))
print(SETUP_DIRECTORY)
# def find_packages():
# """
# Simple function to find all modules under the current folder.
# """
# modules = []
# for dirpath, _, filenames in os.walk(os.path.join(SETUP_DIRECTORY,
# "msnoise_tomo")):
# if "__init__.py" in filenames:
# modules.append(os.path.relpath(dirpath, SETUP_DIRECTORY))
# return [_i.replace(os.sep, ".") for _i in modules]
# check for MSVC
if platform.system() == "Windows" and (
'msvc' in sys.argv or
'-c' not in sys.argv and
get_default_compiler() == 'msvc'):
IS_MSVC = True
else:
IS_MSVC = False
# helper function for collecting export symbols from .def files
def export_symbols(*path):
lines = open(os.path.join(*path), 'r').readlines()[2:]
return [s.strip() for s in lines if s.strip() != '']
# Use system libraries? Set later...
EXTERNAL_LIBS = False
# adds --with-system-libs command-line option if possible
def add_features():
if 'setuptools' not in sys.modules or not hasattr(setuptools, 'Feature'):
return {}
class ExternalLibFeature(setuptools.Feature):
def include_in(self, dist):
global EXTERNAL_LIBS
EXTERNAL_LIBS = True
def exclude_from(self, dist):
global EXTERNAL_LIBS
EXTERNAL_LIBS = False
return {
'system-libs': ExternalLibFeature(
'use of system C libraries',
standard=False,
EXTERNAL_LIBS=True
)
}
# monkey patches for MS Visual Studio
if IS_MSVC:
import distutils
from distutils.msvc9compiler import MSVCCompiler
# for Python 2.x only -> support library paths containing spaces
if distutils.__version__.startswith('2.'):
def _library_dir_option(self, dir):
return '/LIBPATH:"%s"' % (dir)
MSVCCompiler.library_dir_option = _library_dir_option
# remove 'init' entry in exported symbols
def _get_export_symbols(self, ext):
return ext.export_symbols
from distutils.command.build_ext import build_ext
build_ext.get_export_symbols = _get_export_symbols
def configuration(parent_package="", top_path=None):
"""
Config function mainly used to compile C code.
"""
config = Configuration("", parent_package, top_path)
# Smoothing Matrix
path = "src"
files = [os.path.join(path, "mk_MatPaths.c"),]
# compiler specific options
kwargs = {}
if IS_MSVC:
# get export symbols
kwargs['export_symbols'] = export_symbols(path, 'mk_MatPaths.def')
config.add_extension(_get_lib_name("mk_MatPaths", add_extension_suffix=False),
files, **kwargs)
# Smoothing Matrix
path = "src"
files = [os.path.join(path, "mkMatSmoothing.c"),]
# compiler specific options
kwargs = {}
if IS_MSVC:
# get export symbols
kwargs['export_symbols'] = export_symbols(path, 'mkMatSmoothing.def')
config.add_extension(_get_lib_name("mkMatSmoothing", add_extension_suffix=False),
files, **kwargs)
# FTAN
path = "src"
files = []
for module in ["configparser.cpp",
"fft_NR.cpp",
"fta_param.cpp",
"libfta.cpp",
"readsac.cpp",
"vg_fta.cpp"]:
files.append(os.path.join(path, module))
# compiler specific options
kwargs = {}
if IS_MSVC:
# get export symbols
kwargs['export_symbols'] = export_symbols(path, 'vg_fta.def')
config.add_extension(_get_lib_name("vg_fta", add_extension_suffix=False), files, **kwargs)
# HACK to avoid: "WARNING: '' not a valid package name; please use only .-separated package names in setup.py"
config = config.todict()
config["packages"] = []
del config["package_dir"]
return config
def setupPackage():
setup(
name='msnoise_tomo',
version='0.1b',
packages=find_packages(),
package_dir={"msnoise_tomo": "msnoise_tomo"},
package_data={'msnoise_tomo': ['img/*.*']},
namespace_packages=[],
include_package_data=True,
install_requires=['msnoise',
'shapely',
'pyproj',
],
entry_points={
'msnoise.plugins.commands': [
'tomo = msnoise_tomo.plugin_definition:tomo',
],
'msnoise.plugins.jobtypes': [
'register = msnoise_tomo.plugin_definition:register_job_types',
],
'msnoise.plugins.table_def': [
'TomoConfig = msnoise_tomo.tomo_table_def:TomoConfig',
],
'msnoise.plugins.admin_view': [
'TomoConfigView = msnoise_tomo.plugin_definition:TomoConfigView',
],
},
author="Thomas Lecocq & MSNoise dev team",
author_email="[email protected]",
description="A Python Package for Monitoring Seismic Velocity Changes using Ambient Seismic Noise",
license="EUPL 1.1",
url="http://www.msnoise.org",
keywords="",
extras_require={},
features=add_features(),
zip_safe=False,
ext_package="msnoise_tomo.lib",
configuration=configuration
)
if __name__ == "__main__":
if 'clean' in sys.argv and '--all' in sys.argv:
print("I'm here!!")
import shutil
# delete complete build directory
path = os.path.join(SETUP_DIRECTORY, 'build')
try:
shutil.rmtree(path)
except:
pass
# delete all shared libs from lib directory
path = os.path.join(SETUP_DIRECTORY, 'msnoise_tomo', 'lib')
for filename in glob.glob(path + os.sep + '*.pyd'):
try:
os.remove(filename)
except:
pass
for filename in glob.glob(path + os.sep + '*.so'):
try:
os.remove(filename)
except:
pass
else:
setupPackage()