forked from ome/omero-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
240 lines (202 loc) · 6.65 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright 2008-2020 The Open Microscopy Environment, Glencoe Software, Inc.
All rights reserved.
Use is subject to license terms supplied in LICENSE.txt
"""
from __future__ import print_function
import glob
import sys
import os
from setuptools import (
Command,
setup,
find_packages,
)
try:
from StringIO import StringIO
from StringIO import StringIO as BytesIO
except ImportError:
# Python 3
from io import StringIO
from io import BytesIO
from shutil import (
copy,
rmtree,
)
try:
from urllib.request import urlopen
except ImportError:
# Python 2
from urllib import urlopen
from zipfile import ZipFile
try:
import configparser
except ImportError:
# Python 2
import ConfigParser as configparser
def get_blitz_location():
config_blitz_version = "5.5.5"
# simplified strings
defaultsect = configparser.DEFAULTSECT
version_key = "versions.omero-blitz"
url_key = "versions.omero-blitz-url"
# detect if in Jenkins or not
if "ZIP_FILE" in os.environ:
config_blitz_url = os.environ.get("ZIP_FILE")
elif "JENKINS_URL" in os.environ:
config_blitz_url = os.environ.get("JENKINS_URL")
config_blitz_url += "job/OMERO-build-build/lastSuccessfulBuild/"
config_blitz_url += "artifact/omero-blitz/build/distributions/"
config_blitz_url += "omero-blitz-VERSION-python.zip"
else:
config_blitz_url = (
"https://artifacts.openmicroscopy.org/artifactory/ome.releases/"
"org/openmicroscopy/omero-blitz/VERSION/"
"omero-blitz-VERSION-python.zip")
# load version.properties if available
config_path = os.environ.get("VERSION_PROPERTIES",
"artifact/version.properties")
if os.path.exists(config_path):
config_obj = configparser.RawConfigParser({
url_key: config_blitz_url,
version_key: config_blitz_version,
})
with open(config_path) as f:
config_str = StringIO('[%s]\n%s' % (defaultsect, f.read()))
config_obj.readfp(config_str)
config_blitz_url = config_obj.get(defaultsect, url_key)
config_blitz_version = config_obj.get(defaultsect, version_key)
# replace VERSION in the final url and return
config_blitz_url = config_blitz_url.replace(
"VERSION", config_blitz_version)
return config_blitz_url
def download_blitz_target():
loc = get_blitz_location()
if "ZIP_FILE" in os.environ:
zipfile = ZipFile(loc)
else:
print("Downloading %s ..." % loc, file=sys.stderr)
resp = urlopen(loc)
content = resp.read()
content = BytesIO(content)
zipfile = ZipFile(content)
zipfile.extractall("target")
def _relative_symlink_file(src, dst):
relsrc = os.path.relpath(src, os.path.dirname(dst))
try:
os.symlink(relsrc, dst)
print(src, dst)
except OSError as e:
if e.errno != 17:
raise
os.remove(dst)
os.symlink(relsrc, dst)
def copy_src_to_target(symlink=False):
for dirpath, dirs, files in os.walk("src"):
for filename in files:
topath = dirpath.replace("src", "target", 1)
if not os.path.exists(topath):
os.makedirs(topath)
fromfile = os.path.sep.join([dirpath, filename])
tofile = os.path.sep.join([topath, filename])
if symlink:
_relative_symlink_file(fromfile, tofile)
else:
copy(fromfile, tofile)
# https://coderwall.com/p/3q_czg/custom-subcommand-at-setup-py
class DevTargetCommand(Command):
"""
Recreate "target" with symlinks to files in "src" to ease development.
For example, `pip install -e .` will work.
Changes in files under "src" will be automatically seen in the installed
module.
If you add or remove files in src you must re-run both of these commands:
python setup.py devtarget
pip install -e .
"""
description = (
'Recreate target with symlinks to files in src to ease development')
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
rmtree('target')
download_blitz_target()
copy_src_to_target(symlink=True)
print("If this is installed as an editable module re-run "
"`pip install -e .`")
if not os.path.exists('target'):
download_blitz_target()
copy_src_to_target()
packageless = glob.glob("target/*.py")
packageless = [x[7:-3] for x in packageless]
packages = find_packages(where="target")
sys.path.append("target")
from omero_version import omero_version as ov # noqa
def read(fname):
"""
Utility function to read the README file.
:rtype : String
"""
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name="omero-py",
version=ov,
description="Python bindings to the OMERO.blitz server",
long_description=read("README.rst"),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v2 '
'or later (GPLv2+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
], # Get strings from
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
author="The Open Microscopy Team",
author_email="[email protected]",
url='https://github.com/ome/omero-py',
project_urls={
'Documentation':
'https://docs.openmicroscopy.org/omero/latest/developers/'
'Python.html',
'Bug tracker': 'https://github.com/ome/omero-py/issues',
'API': 'https://omero-py.readthedocs.io/',
},
package_dir={"": "target"},
packages=packages,
package_data={
'omero.gateway': ['pilfonts/*'],
'omero.gateway.scripts': ['imgs/*']},
py_modules=packageless,
entry_points={
'console_scripts': ['omero=omero.main:main'],
},
python_requires='>=3',
install_requires=[
'appdirs',
'future',
'numpy',
'Pillow',
'PyYAML',
'zeroc-ice>=3.6.5,<3.7',
'pywin32; platform_system=="Windows"',
'requests',
'portalocker'
],
tests_require=[
'pytest',
'mox3',
],
cmdclass={
'devtarget': DevTargetCommand,
},
)