forked from xraypy/xraylarch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
203 lines (170 loc) · 6.07 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
#!/usr/bin/env python
"""
Setup.py for xraylarch
"""
import os
import sys
import time
import shutil
import subprocess
import importlib
from setuptools import setup, find_packages
try:
from pip._internal import main as pipmain
HAS_PIPMAIN = True
except ImportError:
HAS_PIPMAIN = False
HAS_CONDA = os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
cmdline_args = sys.argv[1:]
INSTALL = len(cmdline_args)> 0 and (cmdline_args[0] == 'install')
DEVELOP = len(cmdline_args)> 0 and (cmdline_args[0] == 'develop')
uname = sys.platform.lower()
if os.name == 'nt':
uname = 'win'
if uname.startswith('linux'):
uname = 'linux'
_version__ = None
with open(os.path.join('larch', 'version.py'), 'r') as version_file:
lines = version_file.readlines()
for line in lines:
line = line[:-1]
if line.startswith('__version__'):
key, vers = [w.strip() for w in line.split('=')]
__version__ = vers.replace("'", "").replace('"', "").strip()
## Dependencies: required and recommended modules
## do not use `install_requires` for conda environments
install_reqs = []
if not HAS_CONDA:
with open('requirements.txt', 'r') as f:
install_reqs = f.read().splitlines()
if HAS_PIPMAIN and not HAS_CONDA:
mods = ['install']
for req in install_reqs:
req = req.strip()
if not req.startswith('#'):
mods.append(req.split()[0])
try:
pipmain(mods)
except:
pass
recommended = (('dioptas', 'dioptas', 'XRD Display and Integraton'),
('tomopy', 'tomopy', 'Tomographic reconstructions'),
('psycopg2', 'psycopg2', 'Interacting with PostgresQL databases'),
('pycifrw', 'CifFile', 'Reading CIF files'),
)
missing = []
try:
import matplotlib
matplotlib.use('WXAgg')
except:
pass
for modname, impname, desc in recommended:
try:
x = importlib.import_module(impname)
import_ok = True
except ImportError:
import_ok = False
if HAS_PIPMAIN and not import_ok:
try:
pipmain(['install', modname])
except:
pass
try:
x = importlib.import_module(impname)
import_ok = True
except ImportError:
import_ok = False
if not import_ok:
missing.append(' {:25.25s} {:s}'.format(modname, desc))
## For Travis-CI, need to write a local site config file
##
if os.environ.get('TRAVIS_CI_TEST', '0') == '1':
time.sleep(0.2)
pjoin = os.path.join
pexists = os.path.exists
bindir = 'bin'
pyexe = pjoin(bindir, 'python')
larchbin = 'larch'
if uname == 'win':
bindir = 'Scripts'
pyexe = 'python.exe'
larchbin = 'larch-script.py'
# list of top level scripts to add to Python's bin/
scripts = ['larch', 'larch_server', 'feff6l', 'feff8l', 'xas_viewer',
'gse_mapviewer', 'gse_dtcorrect', 'xrd1d_viewer','xrd2d_viewer',
'dioptas_larch', 'xrfdisplay', 'xrfdisplay_epics']
larch_apps = ['{0:s} = larch.apps:run_{0:s}'.format(n) for n in scripts]
packages = ['larch', 'larch.bin']
for pname in find_packages('larch'):
packages.append('larch.%s' % pname)
package_data = ['icons/*', 'xray/*.dat', 'xray/*.db', 'xrd/*.db',
'bin/darwin64/*', 'bin/linux64/*', 'bin/win64/*',
'bin/win32/*']
if INSTALL:
# before install: remove historical cruft, including old plugins
cruft = {'bin': ['larch_makeicons', 'larch_gui', 'larch_client',
'gse_scanviewer', 'feff8l_ff2x', 'feff8l_genfmt',
'feff8l_pathfinder', 'feff8l_pot', 'feff8l_rdinp',
'feff8l_xsph']}
def remove_file(base, fname):
fullname = pjoin(base, fname)
if pexists(fullname):
try:
os.unlink(fullname)
except:
pass
for category, flist in cruft.items():
if category == 'bin':
basedir = pjoin(sys.exec_prefix, bindir)
for fname in flist:
remove_file(basedir, fname)
# remove all files in share/larch from earlier code layouts
# system-wide larch directory
larchdir = pjoin(sys.exec_prefix, 'share', 'larch')
for dirname in ('plugins', 'dlls', 'icons'):
fname = pjoin(larchdir, dirname)
if os.path.exists(fname):
try:
shutil.rmtree(fname)
except PermissionError:
pass
# now we have all the data files, so we can run setup
setup(name = 'xraylarch',
version = __version__,
author = 'Matthew Newville and the X-rayLarch Development Team',
author_email = '[email protected]',
url = 'http://xraypy.github.io/xraylarch/',
download_url = 'http://xraypy.github.io/xraylarch/',
license = 'BSD',
description = 'Synchrotron X-ray data analysis in python',
python_requires='>=3.5.1',
install_requires=install_reqs,
packages = packages,
package_data={'larch': package_data},
entry_points = {'console_scripts' : larch_apps},
platforms = ['Windows', 'Linux', 'Mac OS X'],
classifiers=['Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'Programming Language :: Python',
'License :: OSI Approved :: BSD License',
'Topic :: Scientific/Engineering'],
)
# create desktop icons
if INSTALL or DEVELOP:
subprocess.check_call((pjoin(sys.exec_prefix, sys.executable),
pjoin(sys.exec_prefix, bindir, larchbin), '-m'))
if len(missing) > 0:
dl = "#%s#" % ("="*75)
msg = """%s
Note: Some optional Python Packages were not found.
Some functionality will not be available without these packages:
Package Name Needed for
---------------- ----------------------------------
%s
---------------- ----------------------------------
If you need these capabilities, you may be able to install them with
pip install <Package Name>
or
conda install -c gsecars <Package Name>
%s"""
print(msg % (dl, '\n'.join(missing), dl))