forked from hyperspy/hyperspy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
211 lines (193 loc) · 7.74 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
# -*- coding: utf-8 -*-
# Copyright 2007-2011 The HyperSpy developers
#
# This file is part of HyperSpy.
#
# HyperSpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HyperSpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.
from distutils.core import setup
import distutils.dir_util
import os
import subprocess
import sys
import fileinput
import hyperspy.Release as Release
# clean the build directory so we aren't mixing Windows and Linux
# installations carelessly.
if os.path.exists('build'):
distutils.dir_util.remove_tree('build')
install_req = ['scipy',
'ipython',
'matplotlib (>= 1.2)',
'numpy',
'traits',
'traitsui', ]
def are_we_building4windows():
for arg in sys.argv:
if 'wininst' in arg:
return True
scripts = ['bin/hyperspy', ]
if are_we_building4windows() or os.name in ['nt', 'dos']:
# In the Windows command prompt we can't execute Python scripts
# without a .py extension. A solution is to create batch files
# that runs the different scripts.
# (code adapted from scitools)
scripts.extend(('bin/win_post_installation.py',
'bin/install_hyperspy_here.py',
'bin/uninstall_hyperspy_here.py'))
batch_files = []
for script in scripts:
batch_file = os.path.splitext(script)[0] + '.bat'
f = open(batch_file, "w")
f.write('set path=%~dp0;%~dp0\..\;%PATH%\n')
f.write('python "%%~dp0\%s" %%*\n' % os.path.split(script)[1])
f.close()
batch_files.append(batch_file)
if script in ('bin/hyperspy'):
for env in ('qtconsole', 'notebook'):
batch_file = os.path.splitext(script)[0] + '_%s' % env + '.bat'
f = open(batch_file, "w")
f.write('set path=%~dp0;%~dp0\..\;%PATH%\n')
f.write('cd %1\n')
if env == "qtconsole":
f.write('start pythonw "%%~dp0\%s " %s \n' % (
os.path.split(script)[1], env))
else:
f.write('python "%%~dp0\%s" %s \n' %
(os.path.split(script)[1], env))
batch_files.append(batch_file)
scripts.extend(batch_files)
class update_version_when_dev:
def __enter__(self):
self.release_version = Release.version
# Get the hash from the git repository if available
self.restore_version = False
git_master_path = ".git/refs/heads/master"
if "+dev" in self.release_version and \
os.path.isfile(git_master_path):
try:
p = subprocess.Popen(["git", "describe",
"--tags", "--dirty", "--always"],
stdout=subprocess.PIPE)
stdout = p.communicate()[0]
if p.returncode != 0:
raise EnvironmentError
else:
version = stdout[1:].strip()
if str(self.release_version[:-4] + '-') in version:
version = version.replace(
self.release_version[:-4] + '-',
self.release_version[:-4] + '+git')
self.version = version
except EnvironmentError:
# Git is not available, but the .git directory exists
# Therefore we can get just the master hash
with open(git_master_path) as f:
masterhash = f.readline()
self.version = self.release_version.replace(
"+dev", "+git-%s" % masterhash[:7])
for line in fileinput.FileInput("hyperspy/Release.py",
inplace=1):
if line.startswith('version = '):
print "version = \"%s\"" % self.version
else:
print line,
self.restore_version = True
else:
self.version = self.release_version
return self.version
def __exit__(self, type, value, traceback):
if self.restore_version is True:
for line in fileinput.FileInput("hyperspy/Release.py",
inplace=1):
if line.startswith('version = '):
print "version = \"%s\"" % self.release_version
else:
print line,
with update_version_when_dev() as version:
setup(
name="hyperspy",
package_dir={'hyperspy': 'hyperspy'},
version=version,
packages=['hyperspy',
'hyperspy._components',
'hyperspy.io_plugins',
'hyperspy.drawing',
'hyperspy.learn',
'hyperspy._signals',
'hyperspy.gui',
'hyperspy.utils',
'hyperspy.tests',
'hyperspy.tests.axes',
'hyperspy.tests.component',
'hyperspy.tests.drawing',
'hyperspy.tests.io',
'hyperspy.tests.model',
'hyperspy.tests.mva',
'hyperspy.tests.signal',
'hyperspy.tests.utils',
'hyperspy.models',
'hyperspy.misc',
'hyperspy.misc.eels',
'hyperspy.misc.eds',
'hyperspy.misc.io',
'hyperspy.misc.machine_learning',
'hyperspy.misc.mpfit',
'hyperspy.misc.mpfit.tests',
'hyperspy.misc.borrowed',
'hyperspy.misc.borrowed.astroML',
],
requires=install_req,
scripts=scripts,
package_data=
{
'hyperspy':
['bin/*.py',
'ipython_profile/*',
'data/*.ico',
'tests/io/dm3_1D_data/*.dm3',
'tests/io/dm3_2D_data/*.dm3',
'tests/io/dm3_3D_data/*.dm3',
'tests/io/dm4_1D_data/*.dm4',
'tests/io/dm4_2D_data/*.dm4',
'tests/io/dm4_3D_data/*.dm4',
'tests/io/msa_files/*.msa',
'tests/io/hdf5_files/*.hdf5',
'tests/io/tiff_files/*.tif',
'tests/io/npy_files/*.npy',
'tests/drawing/*.ipynb',
],
},
author=Release.authors['all'][0],
author_email=Release.authors['all'][1],
maintainer='Francisco de la Peña',
maintainer_email='fjd29@cam.ac.uk',
description=Release.description,
long_description=open('README.txt').read(),
license=Release.license,
platforms=Release.platforms,
url=Release.url,
#~ test_suite = 'nose.collector',
keywords=Release.keywords,
classifiers=[
"Programming Language :: Python :: 2.7",
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
],
)