forked from imageio/imageio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
299 lines (236 loc) · 9.2 KB
/
setup.py
File metadata and controls
299 lines (236 loc) · 9.2 KB
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
# -*- coding: utf-8 -*-
# Copyright (C) 2015, imageio contributors
#
# imageio is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
# styletest: skip
"""
Before release:
* Run test suite on pypy (with numpy)
* Run test suite on Windows 32
* Run test suite on Windows 64
* Run test suite on OS X
* Write release notes
* Check if docs are still good
* Maybe test pypi page via "python setup.py register -r test"
Release:
* Increase __version__
* git tag the release
* Upload to Pypi:
* python setup.py register
* python setup.py sdist_all upload
* Update, build and upload conda package
After release:
* Set __version__ to dev
* Announce
"""
import os
import os.path as op
import sys
import shutil
from distutils.core import Command
from distutils.command.sdist import sdist
from distutils.command.build_py import build_py
try:
from setuptools import setup # Supports wheels
except ImportError:
from distutils.core import setup # Supports anything else
name = 'imageio'
description = 'Library for reading and writing a wide range of image formats.'
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
# Get version and docstring
__version__ = None
__doc__ = ''
docStatus = 0 # Not started, in progress, done
initFile = os.path.join(THIS_DIR, 'imageio', '__init__.py')
for line in open(initFile).readlines():
if (line.startswith('__version__')):
exec(line.strip())
elif line.startswith('"""'):
if docStatus == 0:
docStatus = 1
line = line.lstrip('"')
elif docStatus == 1:
docStatus = 2
if docStatus == 1:
__doc__ += line
# Template for long description. __doc__ gets inserted here
long_description = """
.. image:: https://travis-ci.org/imageio/imageio.svg?branch=master
:target: https://travis-ci.org/imageio/imageio'
.. image:: https://coveralls.io/repos/imageio/imageio/badge.png?branch=master
:target: https://coveralls.io/r/imageio/imageio?branch=master
__doc__
Release notes: http://imageio.readthedocs.org/en/latest/releasenotes.html
Example:
.. code-block:: python
>>> import imageio
>>> im = imageio.imread('astronaut.png')
>>> im.shape # im is a numpy array
(512, 512, 3)
>>> imageio.imwrite('astronaut-gray.jpg', im[:, :, 0])
See the `user API <http://imageio.readthedocs.org/en/latest/userapi.html>`_
or `examples <http://imageio.readthedocs.org/en/latest/examples.html>`_
for more information.
All distribution files are independent of the Python version. The
platform-specific archives contain a few images and the freeimage
library for that platform. These are recommended if you do not want to
rely on an internet connection at runtime / install-time.
"""
# Prepare resources dir
package_data = []
package_data.append('resources/shipped_resources_go_here')
package_data.append('resources/*.*')
package_data.append('resources/images/*.*')
package_data.append('resources/freeimage/*.*')
package_data.append('resources/ffmpeg/*.*')
package_data.append('resources/avbin/*.*')
def _set_crossplatform_resources(resource_dir):
import imageio
# Clear now
if op.isdir(resource_dir):
shutil.rmtree(resource_dir)
os.mkdir(resource_dir)
open(op.join(resource_dir, 'shipped_resources_go_here'), 'wb')
# Load images
for fname in ['images/chelsea.png',
'images/chelsea.zip',
'images/astronaut.png',
'images/newtonscradle.gif',
'images/cockatoo.mp4',
'images/realshort.mp4',
'images/stent.npz',
]:
imageio.core.get_remote_file(fname, resource_dir,
force_download=True)
def _set_platform_resources(resource_dir, platform):
import imageio
# Create file to show platform
assert platform
open(op.join(resource_dir, 'platform_%s' % platform), 'wb')
# Load freeimage
fname = imageio.plugins.freeimage.FNAME_PER_PLATFORM[platform]
imageio.core.get_remote_file('freeimage/'+fname, resource_dir,
force_download=True)
# Load ffmpeg
#fname = imageio.plugins.ffmpeg.FNAME_PER_PLATFORM[platform]
#imageio.core.get_remote_file('ffmpeg/'+fname, resource_dir,
# force_download=True)
class test_command(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from imageio import testing
os.environ['IMAGEIO_NO_INTERNET'] = '1' # run tests without inet
sys.exit(testing.test_unit())
class build_with_fi(build_py):
def run(self):
# Download images and libs
import imageio
resource_dir = imageio.core.resource_dirs()[0]
_set_crossplatform_resources(resource_dir)
_set_platform_resources(resource_dir, imageio.core.get_platform())
# Build as normal
build_py.run(self)
class sdist_all(sdist):
""" Build all platform specific dist files, that contain
a few images and the freeimage lib of the platform.
"""
def run(self):
sdist.run(self)
import imageio
# Get base tarbal
import tarfile
distdir = op.join(THIS_DIR, 'dist')
tarfilename = op.join(distdir, 'imageio-%s.tar.gz' % __version__)
assert op.isfile(tarfilename)
# Create/clean build dir
build_dir = op.join(distdir, 'temp')
if op.isdir(build_dir):
shutil.rmtree(build_dir)
os.mkdir(build_dir)
# Extract, get resource dir
with tarfile.open(tarfilename, 'r:gz') as tf:
tf.extractall(build_dir)
resource_dir = op.join(build_dir, 'imageio-%s' % __version__,
'imageio', 'resources')
assert os.path.isdir(resource_dir)
# Prepare the libs resource directory with cross-platform
# resources, so we can copy these for each platform
_set_crossplatform_resources(imageio.core.resource_dirs()[0])
# Create archives
dist_files = self.distribution.dist_files
for plat in ['', 'linux64', 'linux32', 'win64', 'win32', 'osx64']:
fname = self._create_dists_for_platform(resource_dir, plat)
dist_files.append(('sdist', 'any', 'dist/'+fname))
# Clean up
shutil.rmtree(build_dir)
def _create_dists_for_platform(self, resource_dir, plat):
import zipfile
import imageio
# Copy over crossplatform resources and add platform specifics
shutil.rmtree(resource_dir)
if plat:
shutil.copytree(imageio.core.resource_dirs()[0], resource_dir)
_set_platform_resources(resource_dir, plat)
else:
os.mkdir(resource_dir)
open(op.join(resource_dir, 'shipped_resources_go_here'), 'wb')
# Zip it
distdir = op.join(THIS_DIR, 'dist')
build_dir = op.join(distdir, 'temp')
zipfname = 'imageio-%s.zip' % __version__
if plat:
zipfname = 'imageio-%s-%s.zip' % (__version__, plat)
zipfilename = op.join(distdir, zipfname)
zf = zipfile.ZipFile(zipfilename, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(build_dir):
for fname in files:
filename = op.join(root, fname)
relpath = op.relpath(filename, build_dir)
relpath = relpath.replace('imageio-%s' % __version__,
zipfname[:-4])
zf.write(filename, relpath)
zf.close()
return zipfname
setup(
cmdclass={'sdist_all': sdist_all,
'build_with_fi': build_with_fi,
'test': test_command},
name = name,
version = __version__,
author = 'imageio contributors',
author_email = 'almar.klein@gmail.com',
license = '(new) BSD',
url = 'http://imageio.github.io/',
download_url = 'http://pypi.python.org/pypi/imageio',
keywords = "image imread imwrite io animation volume FreeImage ffmpeg",
description = description,
long_description = long_description.replace('__doc__', __doc__),
platforms = 'any',
provides = ['imageio'],
requires = ['numpy'],
packages = ['imageio', 'imageio.core', 'imageio.plugins'],
package_dir = {'imageio': 'imageio'},
# Data in the package
package_data = {'imageio': package_data},
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'Intended Audience :: Education',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
)