-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
310 lines (258 loc) · 10.6 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
#!/usr/bin/env python3
# coding: utf8
# /*##########################################################################
#
# Copyright (c) 2013-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""
Data Analysis Highly tailored for Upbl09a
"""
__authors__ = ["Jérôme Kieffer", "Thomas Vincent"]
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "23/06/2020"
__status__ = "development"
import sys
import os
import glob
import logging
logger = logging.getLogger("dahu.setup")
if sys.version_info[0] < 3:
raise SystemError("Freesas requires Python3 !")
from numpy.distutils.misc_util import Configuration
try:
from setuptools import Command, setup
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.sdist import sdist
logger.info("Use setuptools.setup")
except ImportError:
try:
from numpy.distutils.core import Command, setup
except ImportError:
from distutils.core import Command
from distutils.command.build_py import build_py as _build_py
from distutils.command.sdist import sdist
logger.info("Use distutils.core.setup")
PROJECT = "dahu"
cmdclass = {}
def get_version():
import version
return version.strictversion
def get_readme():
dirname = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(dirname, "README.rst"), "r") as fp:
long_description = fp.read()
return long_description
classifiers = ["Development Status :: 3 - Alpha",
"Environment :: Console",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications :: Qt",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Natural Language :: English",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Cython",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development :: Libraries :: Python Modules",
]
# ########## #
# version.py #
# ########## #
class build_py(_build_py):
"""
Enhanced build_py which copies version.py to <PROJECT>._version.py
"""
def find_package_modules(self, package, package_dir):
modules = _build_py.find_package_modules(self, package, package_dir)
if package == PROJECT:
modules.append((PROJECT, '_version', 'version.py'))
return modules
cmdclass['build_py'] = build_py
########
# Test #
########
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import subprocess
errno = subprocess.call([sys.executable, 'run_tests.py'])
if errno != 0:
raise SystemExit(errno)
cmdclass['test'] = PyTest
# ################### #
# build_doc commandes #
# ################### #
try:
import sphinx
import sphinx.util.console
sphinx.util.console.color_terminal = lambda: False
from sphinx.setup_command import BuildDoc
except ImportError:
sphinx = None
else:
# i.e. if sphinx:
class build_doc(BuildDoc):
def run(self):
# make sure the python path is pointing to the newly built
# code so that the documentation is built on this and not a
# previously installed version
build = self.get_finalized_command('build')
sys.path.insert(0, os.path.abspath(build.build_lib))
# # Copy .ui files to the path:
# dst = os.path.join(
# os.path.abspath(build.build_lib), "silx", "gui")
# if not os.path.isdir(dst):
# os.makedirs(dst)
# for i in os.listdir("gui"):
# if i.endswith(".ui"):
# src = os.path.join("gui", i)
# idst = os.path.join(dst, i)
# if not os.path.exists(idst):
# shutil.copy(src, idst)
# Build the Users Guide in HTML and TeX format
for builder in ('html', 'latex'):
self.builder = builder
self.builder_target_dir = os.path.join(self.build_dir, builder)
self.mkpath(self.builder_target_dir)
BuildDoc.run(self)
sys.path.pop(0)
cmdclass['build_doc'] = build_doc
# ############################# #
# numpy.distutils Configuration #
# ############################# #
def configuration(parent_package='', top_path=None):
"""Recursive construction of package info to be used in setup().
See http://docs.scipy.org/doc/numpy/reference/distutils.html#numpy.distutils.misc_util.Configuration
""" # noqa
config = Configuration(None, parent_package, top_path)
config.set_options(
ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
config.add_subpackage(PROJECT)
return config
config = configuration()
################################################################################
# Debian source tree
################################################################################
class sdist_debian(sdist):
"""
Tailor made sdist for debian
* remove auto-generated doc
* remove cython generated .c files
"""
def prune_file_list(self):
sdist.prune_file_list(self)
to_remove = ["doc/build", "doc/pdf", "doc/html", "pylint", "epydoc"]
print("Removing files for debian")
for rm in to_remove:
self.filelist.exclude_pattern(pattern="*", anchor=False, prefix=rm)
# this is for Cython files specifically: remove C & html files
search_root = os.path.dirname(os.path.abspath(__file__))
for root, _, files in os.walk(search_root):
for afile in files:
if os.path.splitext(afile)[1].lower() == ".pyx":
base_file = os.path.join(root, afile)[len(search_root) + 1:-4]
self.filelist.exclude_pattern(pattern=base_file + ".c")
self.filelist.exclude_pattern(pattern=base_file + ".cpp")
self.filelist.exclude_pattern(pattern=base_file + ".html")
def make_distribution(self):
self.prune_file_list()
sdist.make_distribution(self)
dest = self.archive_files[0]
dirname, basename = os.path.split(dest)
base, ext = os.path.splitext(basename)
while ext in [".zip", ".tar", ".bz2", ".gz", ".Z", ".lz", ".orig"]:
base, ext = os.path.splitext(base)
if ext:
dest = "".join((base, ext))
else:
dest = base
sp = dest.split("-")
base = sp[:-1]
nr = sp[-1]
debian_arch = os.path.join(dirname, "-".join(base) + "_" + nr + ".orig.tar.gz")
os.rename(self.archive_files[0], debian_arch)
self.archive_files = [debian_arch]
print("Building debian .orig.tar.gz in %s" % self.archive_files[0])
cmdclass['debian_src'] = sdist_debian
# ##### #
# setup #
# ##### #
setup_kwargs = config.todict()
script_files = glob.glob("scripts/*")
install_requires = ["numpy"]
setup_requires = ["numpy"]
extras_require = {"tango": ["pytango"]}
entry_points = {"console_scripts": ["dahu-server = dahu.app.server:main",
"dahu-register = dahu.app.register:main"]}
plugins = ["dahu.plugins"]
plugin_dir = {"dahu": "dahu",
"dahu.test": "dahu/test",
"dahu.plugins": "plugins"}
for root, dirs, files in os.walk("plugins", topdown=True):
for name in dirs:
base = os.path.join(root, name)
if not os.path.isfile(os.path.join(base, "__init__.py")):
continue
fqn = "dahu." + base.replace(os.sep, ".")
plugins.append(fqn)
plugin_dir[fqn] = base
setup_kwargs.update(name=PROJECT,
version=get_version(),
url="https://github.com/kif/dahu",
author="Jérôme Kieffer",
author_email="[email protected]",
classifiers=classifiers,
description="Python lightweight, plugin based, data analysis engine",
long_description=get_readme(),
install_requires=install_requires,
setup_requires=setup_requires,
extras_require=extras_require,
entry_points=entry_points,
cmdclass=cmdclass,
package_data={'silx.resources': [
# Add here all resources files
'gui/icons/*.png',
]},
zip_safe=False,
packages=["dahu", "dahu.app", "dahu.test"] + plugins,
package_dir=plugin_dir,
test_suite="test",
scripts=script_files,
)
setup(**setup_kwargs)