/
setup.py
executable file
·354 lines (303 loc) · 12.4 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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Python toolkit for generating and analyzing nanostructure data"""
from __future__ import absolute_import, division, print_function, \
unicode_literals
__docformat__ = 'restructuredtext en'
import os
import sys
import shutil
import subprocess
from distutils.command.clean import clean as Clean
if sys.version_info[0] < 3:
raise RuntimeError("Python version 3.4+ required.\n\n"
"Sorry, but there are features of Python 3\n"
"that I want to take advantage of and without\n"
"worrying about Python 2 compatibility.\n"
"Therefore, Python 2 support was removed starting\n"
"in v0.3.7. Once/if I learn how to automate the\n"
"backporting process from the setup script,\n"
"I will restore Python 2 support that way.\n"
"Until then, if you must install this for Python 2\n"
"you're on your own. It shouldn't be difficult\n"
"but you'll have to manually backport the package\n"
"source code using a Python 3 to Python 2\n"
"compatibility library such as the python `future`\n"
"module, which provides a python script called\n"
"`pasteurize` that can be run on the source\n"
"directory to automate the backporting process.\n"
"You'll also need to hack this setup script\n"
"to remove any exceptions that are raised when\n"
"executed under Python 2.")
#if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 4):
if (3, 0) <= sys.version_info[:2] < (3, 4):
raise RuntimeError("Python 3.4+ required.")
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
try:
import setuptools
except ImportError:
sys.exit("setuptools required for Python3 install.\n"
"`pip install --upgrade setuptools`")
DISTNAME = 'scikit-nano'
DESCRIPTION = __doc__
LONG_DESCRIPTION = ''.join(open('README.rst').readlines()[6:])
AUTHOR = 'Andrew Merrill'
AUTHOR_EMAIL = 'androomerrill@gmail.com'
MAINTAINER = AUTHOR
MAINTAINER_EMAIL = AUTHOR_EMAIL
URL = 'http://docs.scikit-nano.org'
DOWNLOAD_URL = 'https://github.com/scikit-nano/scikit-nano'
KEYWORDS = ['structure data', 'nanoscience', 'nanostructure', 'nanotube',
'graphene', 'structure generator', 'structure analysis']
LICENSE = 'BSD 2-Clause'
CLASSIFIERS = """\
Development Status :: 4 - Beta
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
Programming Language :: Python
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Chemistry
Topic :: Scientific/Engineering :: Physics
Topic :: Scientific/Engineering :: Visualization
Topic :: Software Development
Topic :: Software Development :: Libraries :: Python Modules
"""
MAJOR = 0
MINOR = 4
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
STABLEVERSION = None
if STABLEVERSION is None:
if ISRELEASED:
STABLEVERSION = VERSION
else:
if VERSION == '0.4.0':
STABLEVERSION = '0.3.21'
else:
STABLEVERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO - 1)
# Return the GIT version as a string
def git_version():
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = out.strip().decode('ascii')
except OSError:
GIT_REVISION = "Unknown"
return GIT_REVISION
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
# This is a bit (!) hackish: we are setting a global variable so that the main
# sknano __init__ can detect if it is being loaded by the setup routine, to
# avoid attempting to load components that aren't built yet.
builtins.__SKNANO_SETUP__ = True
class CleanCommand(Clean):
description = \
"Remove build artifacts from the source tree including " \
"__pycache__ directories, .ropeproject directories, and " \
"compiled files in the source tree."
def run(self):
Clean.run(self)
cwd = os.path.abspath(os.path.dirname(__file__))
remove_c_files = not os.path.exists(os.path.join(cwd, 'PKG-INFO'))
if remove_c_files:
cython_hash_file = os.path.join(cwd, 'cythonize.dat')
if os.path.exists(cython_hash_file):
os.unlink(cython_hash_file)
print('Will remove generated .c files')
if os.path.exists('build'):
shutil.rmtree('build')
for dirpath, dirnames, filenames in os.walk('sknano'):
for filename in filenames:
if filename.endswith(('.so', '.pyd', '.pyc', '.dll')):
os.unlink(os.path.join(dirpath, filename))
continue
extension = os.path.splitext(filename)[1]
if remove_c_files and extension in ['.c', '.cxx', 'cpp']:
pyx_file = str.replace(filename, extension, '.pyx')
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname in ('__pycache__', '.ropeproject'):
shutil.rmtree(os.path.join(dirpath, dirname))
for dirpath, dirnames, filenames in os.walk('doc'):
for dirname in dirnames:
if dirname in ('__pycache__', '.ropeproject'):
shutil.rmtree(os.path.join(dirpath, dirname))
def get_version_info():
# Adding the git rev number needs to be done inside
# write_version_py(), otherwise the import of sknano.version messes
# up the build under Python 3.
FULLVERSION = VERSION
if os.path.exists('.git'):
GIT_REVISION = git_version()
elif os.path.exists('sknano/version.py'):
# must be a source distribution, use existing version file
# load it as a separate module to not load sknano/__init__.py
import imp
version = imp.load_source('sknano.version', 'sknano/version.py')
GIT_REVISION = version.git_revision
else:
GIT_REVISION = "Unknown"
if not ISRELEASED:
# FULLVERSION += '.dev'
FULLVERSION += '.dev0+' + GIT_REVISION[:7]
return FULLVERSION, GIT_REVISION
def write_version_py(filename='sknano/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM SCIKIT-NANO SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
full_version = '%(full_version)s'
git_revision = '%(git_revision)s'
release = %(isrelease)s
stable_version = '%(stable_version)s'
if not release:
version = full_version
"""
FULLVERSION, GIT_REVISION = get_version_info()
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION,
'full_version': FULLVERSION,
'git_revision': GIT_REVISION,
'isrelease': str(ISRELEASED),
'stable_version': STABLEVERSION})
finally:
a.close()
def generate_cython():
cwd = os.path.abspath(os.path.dirname(__file__))
print("Cythonizing sources")
p = subprocess.call([sys.executable,
os.path.join(cwd, 'tools', 'cythonize.py'),
'sknano'],
cwd=cwd)
if p != 0:
raise RuntimeError("Running cythonize failed!")
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
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('sknano')
config.get_version('sknano/version.py')
return config
def setup_package():
# Rewrite the version file everytime
write_version_py()
# Figure out whether to add ``*_requires = ['numpy>=`min version`',
# 'scipy>=`min version`']``. We don't want to do that unconditionally,
# because we risk updating an installed numpy/scipy which fails too often.
# Just if the minimum version is not installed, we may give it a try.
build_requires = []
try:
import numpy
numpy_version = \
tuple(
list(map(int, numpy.version.short_version.split('.')[:3]))[:2])
if numpy_version < (1, 9):
raise RuntimeError
except (AttributeError, ImportError, RuntimeError):
build_requires += ['numpy>=1.10.4']
install_requires = build_requires[:]
try:
import scipy
scipy_version = \
tuple(
list(map(int, scipy.version.short_version.split('.')[:3]))[:2])
if scipy_version < (0, 14):
raise RuntimeError
except (AttributeError, ImportError, RuntimeError):
install_requires += ['scipy>=0.17.0']
# # Add six module to install_requires (used in numpydoc git submodule)
# install_requires += ['six>=1.9']
# # Add future module to install requires
# install_requires += ['future>=0.14.3']
install_requires += \
['pyparsing>=2.1.1', 'monty>=0.8.0', 'pymatgen>=3.3.6',
'tabulate>=0.7.5', 'tables>=3.2.2', 'pandas>=0.18.0']
metadata = dict(
name=DISTNAME,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
url=URL,
download_url=DOWNLOAD_URL,
license=LICENSE,
keywords=KEYWORDS,
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
test_suite='nose.collector',
setup_requires=build_requires,
install_requires=install_requires,
extras_require={
'plotting': ['matplotlib>=1.5.1', 'palettable>=2.1.1']
},
entry_points={
'console_scripts': [
'analyze_structure = sknano.scripts.analyze_structure:main',
'nanogen = sknano.scripts.nanogen:main',
'nanogenui = sknano.scripts.nanogenui:main',
'sknano = sknano.scripts.sknano:main'],
},
cmdclass={'clean': CleanCommand},
zip_safe=False, # the package can run out of an .egg file
include_package_data=True,
)
if len(sys.argv) >= 2 and \
('--help' in sys.argv[1:] or sys.argv[1]
in ('--help-commands', 'egg_info', '--version', 'clean')):
# For these actions, NumPy/SciPy are not required.
# They are required to succeed without them when, for example,
# pip is used to install Scipy when Numpy is not yet present in
# the system.
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
FULLVERSION, GIT_REVISION = get_version_info()
metadata['version'] = FULLVERSION
else:
if ((len(sys.argv) >= 2 and sys.argv[1] in
('bdist_wheel', 'bdist_egg')) or ('develop' in sys.argv)):
# bdist_wheel/bdist_egg needs setuptools
import setuptools
from numpy.distutils.core import setup
cwd = os.path.abspath(os.path.dirname(__file__))
if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
# Generate Cython sources, unless building from source release
generate_cython()
metadata['configuration'] = configuration
setup(**metadata)
if __name__ == '__main__':
setup_package()