forked from tgdane/pygix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·255 lines (208 loc) · 8.66 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
#!/usr/bin/python
# coding: utf8
# /*##########################################################################
#
# Copyright (c) 2015-2016 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.
#
# ###########################################################################*/
__authors__ = ["Jérôme Kieffer", "Thomas Vincent"]
__date__ = "18/03/2016"
__license__ = "MIT"
import sys
import os
from numpy.distutils.misc_util import Configuration
try:
from setuptools import setup
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist
except ImportError:
from numpy.distutils.core import setup
from distutils.command.build_py import build_py as _build_py
from distutils.command.build_ext import build_ext
from distutils.command.sdist import sdist
PROJECT = "pygix"
cmdclass = {}
# Check if action requires build/install
DRY_RUN = len(sys.argv) == 1 or (len(sys.argv) >= 2 and (
'--help' in sys.argv[1:] or
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
'clean', '--name')))
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.md"), "r", encoding='utf-8') as fp:
long_description = fp.read()
return long_description
classifiers = ["Development Status :: 2 - Pre-alpha",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"Programming Language :: Cython",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: Implementation :: CPython",
"Environment :: Console",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"License :: OSI Approved :: GPLv3+",
"Operating System :: Microsoft :: Windows",
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Topic :: Documentation :: Sphinx",
"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
# ################### #
# build_doc commands #
# ################### #
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()
install_requires = ["numpy", "pyFAI"]
setup_requires = ["numpy"]
setup_kwargs.update(
name=PROJECT,
version=get_version(),
url="https://github.com/tgdane/pygix",
author="Thomas Dane",
author_email="thomasgdane@gmail.com",
classifiers=classifiers,
description="Software library for grazing-incidence/fibre X-Ray data analysis",
long_description=get_readme(),
install_requires=install_requires,
setup_requires=setup_requires,
cmdclass=cmdclass,
)
setup(**setup_kwargs)