-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·225 lines (190 loc) · 7.98 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
__author__ = "Aymen Alsaadi"
__copyright__ = "Copyright 2019. The ICEBERG Project"
__license__ = "MIT"
import os
import sys
import subprocess as sp
import re
import shutil
name = 'geolocation'
mod_root = 'src/iceberg/'
try:
from setuptools import setup, Command, find_packages
except ImportError as e:
print("%s needs setuptools to install" % name)
sys.exit(1)
def set_version(mod_root):
"""
mod_root
a VERSION file containes the version strings is created in mod_root,
during installation. That file is used at runtime to get the version
information.
"""
try:
version_base = None
version_detail = None
# get version from './VERSION'
src_root = os.path.dirname(__file__)
if not src_root:
src_root = '.'
with open(src_root + '/VERSION', 'r') as f:
version_base = f.readline().strip()
# attempt to get version detail information from git
# We only do that though if we are in a repo root dir,
# ie. if 'git rev-parse --show-prefix' returns an empty string --
# otherwise we get confused if the ve lives beneath another repository,
# and the pip version used uses an install tmp dir in the ve space
# instead of /tmp (which seems to happen with some pip/setuptools
# versions).
p = sp.Popen('cd %s ; '
'test -z `git rev-parse --show-prefix` || exit -1; '
'tag=`git describe --tags --always` 2>/dev/null ; '
'branch=`git branch | grep -e "^*" | cut -f 2- -d " "` 2>/dev/null ; '
'echo $tag@$branch' % src_root,
stdout=sp.PIPE, stderr=sp.STDOUT, shell=True)
version_detail = str(p.communicate()[0].strip())
version_detail = version_detail.replace('detached from ', 'detached-')
# remove all non-alphanumeric (and then some) chars
version_detail = re.sub('[/ ]+', '-', version_detail)
version_detail = re.sub('[^[email protected]]+', '', version_detail)
if p.returncode != 0 or \
version_detail == '@' or \
'git-error' in version_detail or \
'not-a-git-repo' in version_detail or \
'not-found' in version_detail or \
'fatal' in version_detail :
version = version_base
elif '@' not in version_base:
version = '%s-%s' % (version_base, version_detail)
else:
version = version_base
# make sure the version files exist for the runtime version inspection
path = '%s/%s' % (src_root, mod_root)
with open(path + "/VERSION", "w") as f:
f.write(version + "\n")
sdist_name = "%s-%s.tar.gz" % (name, version)
sdist_name = sdist_name.replace('/', '-')
sdist_name = sdist_name.replace('@', '-')
sdist_name = sdist_name.replace('#', '-')
sdist_name = sdist_name.replace('_', '-')
if '--record' in sys.argv or \
'bdist_egg' in sys.argv or \
'bdist_wheel' in sys.argv :
# pip install stage 2 or easy_install stage 1
#
# pip install will untar the sdist in a tmp tree. In that tmp
# tree, we won't be able to derive git version tags -- so we pack the
# formerly derived version as ./VERSION
shutil.move("VERSION", "VERSION.bak") # backup version
shutil.copy("%s/VERSION" % path, "VERSION") # use full version instead
os.system ("python setup.py sdist") # build sdist
shutil.copy('dist/%s' % sdist_name,
'%s/%s' % (mod_root, sdist_name)) # copy into tree
shutil.move("VERSION.bak", "VERSION") # restore version
with open(path + "/SDIST", "w") as f:
f.write(sdist_name + "\n")
return version_base, version_detail, sdist_name
except Exception as e :
raise RuntimeError('Could not extract/set version: %s' % e)
# borrowed from the MoinMoin-wiki installer
#
def makeDataFiles(prefix, dir):
""" Create distutils data_files structure from dir
distutil will copy all file rooted under dir into prefix, excluding
dir itself, just like 'ditto src dst' works, and unlike 'cp -r src
dst, which copy src into dst'.
Typical usage:
# install the contents of 'wiki' under sys.prefix+'share/moin'
data_files = makeDataFiles('share/moin', 'wiki')
For this directory structure:
root
file1
file2
dir
file
subdir
file
makeDataFiles('prefix', 'root') will create this distutil data_files structure:
[('prefix', ['file1', 'file2']),
('prefix/dir', ['file']),
('prefix/dir/subdir', ['file'])]
"""
# Strip 'dir/' from of path before joining with prefix
dir = dir.rstrip('/')
strip = len(dir) + 1
found = []
kargs = (prefix, strip, found)
os.path.walk(dir, visit, kargs)
#print found[0]
return found[0]
def visit(kargs, dirname, names):
""" Visit directory, create distutil tuple
Add distutil tuple for each directory using this format:
(destination, [dirname/file1, dirname/file2, ...])
distutil will copy later file1, file2, ... info destination.
"""
(prefix, strip, found) = kargs
files = []
# Iterate over a copy of names, modify names
for name in names[:]:
path = os.path.join(dirname, name)
# Ignore directories - we will visit later
if os.path.isdir(path):
# Remove directories we don't want to visit later
if isbad(name):
names.remove(name)
continue
elif isgood(name):
files.append(path)
destination = os.path.join(prefix, dirname[strip:])
found.append((destination, files))
def isbad(name):
""" Whether name should not be installed """
return (name.startswith('.') or
name.startswith('#') or
name.endswith('.pickle') or
name == 'CVS')
def isgood(name):
""" Whether name should be installed """
if not isbad(name):
if name.endswith('.py') or name.endswith('.json') or name.endswith('.tar'):
return True
return False
# ------------------------------------------------------------------------------
# get version info -- this will create VERSION and srcroot/VERSION
version, version_detail, sdist_name = set_version(mod_root)
setup_args = {
'name' : name,
'version' : version,
'description' : "ICEBERG Geolocation Package.",
'author' : 'RADICAL Group at Rutgers University',
'author_email' : '[email protected]',
'maintainer' : "Aymen Alsaadi",
'maintainer_email' : '[email protected]',
'url' : 'https://github.com/iceberg-project/Geolocation/',
'license' : 'MIT',
'keywords' : "high-resolution imagery workflow execution",
'classifiers' : [
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Environment :: Console',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Utilities',
'Topic :: System :: Distributed Computing',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
'Operating System :: Unix'
],
'namespace_packages': ['geolocation'],
'packages' : find_packages('src/iceberg/'),
'package_dir' : {'': 'src/iceberg/'},
'package_data' : {'': ['VERSION', 'SDIST', sdist_name]},
'install_requires' : ['pandas', 'pyzmq', 'netifaces', 'msgpack'],
'zip_safe' : False,
}
setup (**setup_args)