blob: cc8f3c18f26ae1cf3e94caca533bf142636509dc [file] [log] [blame]
Fernando Perez36d3c162006-07-12 06:02:281#!/usr/bin/env python
Travis Oliphantc8b5a7e2006-01-06 02:12:502"""NumPy: array processing for numbers, strings, records, and objects.
Travis Oliphantda9c6da2006-01-04 17:31:073
Travis Oliphantc8b5a7e2006-01-06 02:12:504NumPy is a general-purpose array-processing package designed to
Travis Oliphantda9c6da2006-01-04 17:31:075efficiently manipulate large multi-dimensional arrays of arbitrary
6records without sacrificing too much speed for small multi-dimensional
Travis Oliphantc8b5a7e2006-01-06 02:12:507arrays. NumPy is built on the Numeric code base and adds features
Travis Oliphantda9c6da2006-01-04 17:31:078introduced by numarray as well as an extended C-API and the ability to
Travis Oliphant00a35872007-05-31 04:57:019create arrays of arbitrary type which also makes NumPy suitable for
10interfacing with general-purpose data-base applications.
Travis Oliphantda9c6da2006-01-04 17:31:0711
12There are also basic facilities for discrete fourier transform,
13basic linear algebra and random number generation.
Charles Harris6aa264c2013-02-27 20:26:5814
Travis Oliphantda9c6da2006-01-04 17:31:0715"""
Charles Harrisbb726ca2013-04-06 19:25:2616from __future__ import division, print_function
Travis Oliphantda9c6da2006-01-04 17:31:0717
David Sanders922442f2015-10-19 20:03:3418DOCLINES = (__doc__ or '').split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3119
Pearu Petersone8fa0132003-03-07 18:08:2820import os
21import sys
David Cournapeau5623a7c2009-04-02 16:21:3022import subprocess
Ralf Gommers99e99e92015-12-29 14:24:2223import textwrap
Pearu Petersonc415fd12002-11-18 22:39:3124
Ralf Gommers17716d72013-12-06 19:45:4025
Charles Harris28eadc02013-07-11 18:08:4926if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
27 raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.")
28
Charles Harris09a52ed2013-03-28 23:13:5329if sys.version_info[0] >= 3:
David Cournapeau2b517692009-12-03 15:53:2930 import builtins
Charles Harris09a52ed2013-03-28 23:13:5331else:
32 import __builtin__ as builtins
David Cournapeau2b517692009-12-03 15:53:2933
Ralf Gommers17716d72013-12-06 19:45:4034
Travis Oliphantda9c6da2006-01-04 17:31:0735CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4436Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0737Intended Audience :: Science/Research
38Intended Audience :: Developers
39License :: OSI Approved
40Programming Language :: C
41Programming Language :: Python
Alex Willmer193668a2015-08-05 09:29:3942Programming Language :: Python :: 2
43Programming Language :: Python :: 2.6
44Programming Language :: Python :: 2.7
rgommerscdac1202011-01-25 14:02:4045Programming Language :: Python :: 3
Alex Willmer193668a2015-08-05 09:29:3946Programming Language :: Python :: 3.2
47Programming Language :: Python :: 3.3
48Programming Language :: Python :: 3.4
49Programming Language :: Python :: 3.5
50Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:0751Topic :: Software Development
52Topic :: Scientific/Engineering
53Operating System :: Microsoft :: Windows
54Operating System :: POSIX
55Operating System :: Unix
56Operating System :: MacOS
57"""
58
Ralf Gommers58c1bf72012-11-05 19:47:2359MAJOR = 1
Charles Harrisb06dbc12015-08-03 01:55:1460MINOR = 11
David Cournapeau5e041cb2009-03-27 11:16:0161MICRO = 0
Charles Harris4092a9e2016-03-27 20:13:5262ISRELEASED = True
David Cournapeau5e041cb2009-03-27 11:16:0163VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0364
Ralf Gommers17716d72013-12-06 19:45:4065
Scott Sinclair58e63602010-11-09 15:09:1566# Return the git revision as a string
67def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1668 def _minimal_ext_cmd(cmd):
69 # construct minimal environment
70 env = {}
David Cournapeau5032b522009-09-18 10:10:3971 for k in ['SYSTEMROOT', 'PATH']:
72 v = os.environ.get(k)
73 if v is not None:
74 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1675 # LANGUAGE is used on win32
76 env['LANGUAGE'] = 'C'
77 env['LANG'] = 'C'
78 env['LC_ALL'] = 'C'
79 out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
80 return out
81
David Cournapeau5623a7c2009-04-02 16:21:3082 try:
Scott Sinclair58e63602010-11-09 15:09:1583 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0684 GIT_REVISION = out.strip().decode('ascii')
David Cournapeau5623a7c2009-04-02 16:21:3085 except OSError:
Scott Sinclaird5ed7442010-11-10 05:19:1586 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0187
Scott Sinclair58e63602010-11-09 15:09:1588 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:0189
Ralf Gommers4b0ed792015-12-29 10:29:3890# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
91# properly updated when the contents of directories change (true for distutils,
92# not sure about setuptools).
93if os.path.exists('MANIFEST'):
94 os.remove('MANIFEST')
David Cournapeau5bb1aa52009-03-27 16:39:0195
96# This is a bit hackish: we are setting a global variable so that the main
97# numpy __init__ can detect if it is being loaded by the setup routine, to
98# avoid attempting to load components that aren't built yet. While ugly, it's
99# a lot more robust than what was previously being used.
David Cournapeau2b517692009-12-03 15:53:29100builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:01101
rgommers13212a52011-03-03 16:13:08102
Ralf Gommers17716d72013-12-06 19:45:40103def get_version_info():
Ralf Gommers87e12c12011-03-24 15:30:06104 # Adding the git rev number needs to be done inside write_version_py(),
105 # otherwise the import of numpy.version messes up the build under Python 3.
106 FULLVERSION = VERSION
107 if os.path.exists('.git'):
108 GIT_REVISION = git_version()
109 elif os.path.exists('numpy/version.py'):
110 # must be a source distribution, use existing version file
Ralf Gommerscd6d53f2011-04-17 14:04:11111 try:
112 from numpy.version import git_revision as GIT_REVISION
113 except ImportError:
114 raise ImportError("Unable to import git_revision. Try removing " \
115 "numpy/version.py and the build directory " \
116 "before building.")
Ralf Gommers87e12c12011-03-24 15:30:06117 else:
118 GIT_REVISION = "Unknown"
119
120 if not ISRELEASED:
Ã…smund Hjulstade15f2922015-02-10 17:07:55121 FULLVERSION += '.dev0+' + GIT_REVISION[:7]
Ralf Gommers87e12c12011-03-24 15:30:06122
Ralf Gommers17716d72013-12-06 19:45:40123 return FULLVERSION, GIT_REVISION
124
125
126def write_version_py(filename='numpy/version.py'):
127 cnt = """
128# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
Ralf Gommers105a4982015-12-29 20:58:36129#
130# To compare versions robustly, use `numpy.lib.NumpyVersion`
Ralf Gommers17716d72013-12-06 19:45:40131short_version = '%(version)s'
132version = '%(version)s'
133full_version = '%(full_version)s'
134git_revision = '%(git_revision)s'
135release = %(isrelease)s
136
137if not release:
138 version = full_version
139"""
140 FULLVERSION, GIT_REVISION = get_version_info()
141
David Cournapeaua2ac9852009-03-27 11:15:36142 a = open(filename, 'w')
143 try:
Scott Sinclair58e63602010-11-09 15:09:15144 a.write(cnt % {'version': VERSION,
rgommers13212a52011-03-03 16:13:08145 'full_version' : FULLVERSION,
Scott Sinclair58e63602010-11-09 15:09:15146 'git_revision' : GIT_REVISION,
147 'isrelease': str(ISRELEASED)})
David Cournapeaua2ac9852009-03-27 11:15:36148 finally:
149 a.close()
150
Ralf Gommers17716d72013-12-06 19:45:40151
Pearu Peterson471196b2006-03-31 08:59:36152def configuration(parent_package='',top_path=None):
153 from numpy.distutils.misc_util import Configuration
154
Pearu Peterson17d7cfe2006-04-04 12:26:14155 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36156 config.set_options(ignore_setup_xxx_py=True,
157 assume_default_configuration=True,
158 delegate_options_to_subpackages=True,
159 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18160
Pearu Peterson471196b2006-03-31 08:59:36161 config.add_subpackage('numpy')
Jarrod Millman0b77f0e2007-10-29 14:58:18162
Pearu Peterson17d7cfe2006-04-04 12:26:14163 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01164
Pearu Peterson471196b2006-03-31 08:59:36165 return config
166
Ralf Gommers4b0ed792015-12-29 10:29:38167
Julian Taylor4cd72742014-01-29 21:59:19168def check_submodules():
169 """ verify that the submodules are checked out and clean
170 use `git submodule update --init`; on failure
171 """
172 if not os.path.exists('.git'):
173 return
174 with open('.gitmodules') as f:
175 for l in f:
176 if 'path' in l:
177 p = l.split('=')[-1].strip()
178 if not os.path.exists(p):
179 raise ValueError('Submodule %s missing' % p)
180
181
182 proc = subprocess.Popen(['git', 'submodule', 'status'],
183 stdout=subprocess.PIPE)
184 status, _ = proc.communicate()
185 status = status.decode("ascii", "replace")
186 for line in status.splitlines():
187 if line.startswith('-') or line.startswith('+'):
188 raise ValueError('Submodule not clean: %s' % line)
189
Ralf Gommers4b0ed792015-12-29 10:29:38190
Ralf Gommers7f5efd12016-01-27 20:34:28191from distutils.command.sdist import sdist
Julian Taylor4cd72742014-01-29 21:59:19192class sdist_checked(sdist):
193 """ check submodules on sdist to prevent incomplete tarballs """
194 def run(self):
195 check_submodules()
196 sdist.run(self)
Travis Oliphant14db4192005-09-14 22:08:46197
Ralf Gommers4b0ed792015-12-29 10:29:38198
Julian Taylorc9fd6342014-04-05 11:13:13199def generate_cython():
200 cwd = os.path.abspath(os.path.dirname(__file__))
201 print("Cythonizing sources")
202 p = subprocess.call([sys.executable,
203 os.path.join(cwd, 'tools', 'cythonize.py'),
204 'numpy/random'],
205 cwd=cwd)
206 if p != 0:
207 raise RuntimeError("Running cythonize failed!")
208
Ralf Gommers4b0ed792015-12-29 10:29:38209
Ralf Gommersb9f48092015-12-29 11:05:30210def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22211 """Check the commands and respond appropriately. Disable broken commands.
212
213 Return a boolean value for whether or not to run the build or not (avoid
214 parsing Cython and template files if False).
215 """
Ralf Gommersb9f48092015-12-29 11:05:30216 if len(sys.argv) < 2:
217 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22218 return True
Ralf Gommersb9f48092015-12-29 11:05:30219
Ralf Gommers99e99e92015-12-29 14:24:22220 info_commands = ['--help-commands', '--name', '--version', '-V',
221 '--fullname', '--author', '--author-email',
222 '--maintainer', '--maintainer-email', '--contact',
223 '--contact-email', '--url', '--license', '--description',
224 '--long-description', '--platforms', '--classifiers',
225 '--keywords', '--provides', '--requires', '--obsoletes']
226 # Add commands that do more than print info, but also don't need Cython and
227 # template parsing.
228 info_commands.extend(['egg_info', 'install_egg_info', 'rotate'])
229
230 for command in info_commands:
231 if command in sys.argv[1:]:
232 return False
233
234 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
235 # fine as they are, but are usually used together with one of the commands
236 # below and not standalone. Hence they're not added to good_commands.
237 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23238 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
Ralf Gommersb9f48092015-12-29 11:05:30239 'bdist_wininst', 'bdist_msi', 'bdist_mpkg')
Ralf Gommers99e99e92015-12-29 14:24:22240
Ralf Gommersb9f48092015-12-29 11:05:30241 for command in good_commands:
242 if command in sys.argv[1:]:
Ralf Gommers99e99e92015-12-29 14:24:22243 return True
Ralf Gommersb9f48092015-12-29 11:05:30244
Ralf Gommersab5c6d02016-01-16 14:21:23245 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22246 # useful messages to the user
247 if 'install' in sys.argv[1:]:
248 print(textwrap.dedent("""
249 Note: if you need reliable uninstall behavior, then install
250 with pip instead of using `setup.py install`:
251
252 - `pip install .` (from a git repo or downloaded source
253 release)
254 - `pip install numpy` (last Numpy release on PyPi)
255
256 """))
257 return True
258
259 if '--help' in sys.argv[1:] or '-h' in sys.argv[1]:
260 print(textwrap.dedent("""
261 Numpy-specific help
262 -------------------
263
264 To install Numpy from here with reliable uninstall, we recommend
265 that you use `pip install .`. To install the latest Numpy release
266 from PyPi, use `pip install numpy`.
267
268 For help with build/installation issues, please ask on the
269 numpy-discussion mailing list. If you are sure that you have run
270 into a bug, please report it at https://github.com/numpy/numpy/issues.
271
272 Setuptools commands help
273 ------------------------
274 """))
275 return False
276
277 # The following commands aren't supported. They can only be executed when
278 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30279 bad_commands = dict(
280 test="""
281 `setup.py test` is not supported. Use one of the following
282 instead:
283
284 - `python runtests.py` (to build and test)
285 - `python runtests.py --no-build` (to test installed numpy)
286 - `>>> numpy.test()` (run tests for installed numpy
287 from within an interpreter)
288 """,
289 upload="""
290 `setup.py upload` is not supported, because it's insecure.
291 Instead, build what you want to upload and upload those files
292 with `twine upload -s <filenames>` instead.
293 """,
294 upload_docs="`setup.py upload_docs` is not supported",
295 easy_install="`setup.py easy_install` is not supported",
296 clean="""
297 `setup.py clean` is not supported, use one of the following instead:
298
299 - `git clean -xdf` (cleans all files)
300 - `git clean -Xdf` (cleans all versioned files, doesn't touch
301 files that aren't checked into the git repo)
302 """,
303 check="`setup.py check` is not supported",
304 register="`setup.py register` is not supported",
305 bdist_dumb="`setup.py bdist_dumb` is not supported",
Ralf Gommers99e99e92015-12-29 14:24:22306 bdist="`setup.py bdist` is not supported",
307 build_sphinx="""
308 `setup.py build_sphinx` is not supported, use the
309 Makefile under doc/""",
310 flake8="`setup.py flake8` is not supported, use flake8 standalone",
Ralf Gommersb9f48092015-12-29 11:05:30311 )
Ralf Gommers99e99e92015-12-29 14:24:22312 bad_commands['nosetests'] = bad_commands['test']
313 for commands in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
314 'register', 'check', 'install_data', 'install_headers',
315 'install_lib', 'install_scripts', ):
316 bad_commands[command] = "`setup.py %s` is not supported" % command
317
Ralf Gommersb9f48092015-12-29 11:05:30318 for command in bad_commands.keys():
319 if command in sys.argv[1:]:
Ralf Gommersb9f48092015-12-29 11:05:30320 print(textwrap.dedent(bad_commands[command]) +
321 "\nAdd `--force` to your command to use it anyway if you "
322 "must (unsupported).\n")
323 sys.exit(1)
324
Ralf Gommers99e99e92015-12-29 14:24:22325 # If we got here, we didn't detect what setup.py command was given
326 import warnings
327 warnings.warn("Unrecognized setuptools command, proceeding with "
328 "generating Cython sources and expanding templates")
329 return True
Ralf Gommersb9f48092015-12-29 11:05:30330
331
Ralf Gommers17716d72013-12-06 19:45:40332def setup_package():
Charles Harrisb4180e32013-04-22 03:26:44333 src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
Pauli Virtanen68159432009-12-06 11:56:18334 old_path = os.getcwd()
335 os.chdir(src_path)
336 sys.path.insert(0, src_path)
337
Pauli Virtanen01312182010-11-23 16:50:54338 # Rewrite the version file everytime
339 write_version_py()
340
Ralf Gommers17716d72013-12-06 19:45:40341 metadata = dict(
342 name = 'numpy',
343 maintainer = "NumPy Developers",
344 maintainer_email = "numpy-discussion@scipy.org",
345 description = DOCLINES[0],
346 long_description = "\n".join(DOCLINES[2:]),
347 url = "http://www.numpy.org",
348 author = "Travis E. Oliphant et al.",
349 download_url = "http://sourceforge.net/projects/numpy/files/NumPy/",
350 license = 'BSD',
351 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
352 platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
353 test_suite='nose.collector',
Julian Taylor4cd72742014-01-29 21:59:19354 cmdclass={"sdist": sdist_checked},
Ralf Gommers17716d72013-12-06 19:45:40355 )
356
Ralf Gommers99e99e92015-12-29 14:24:22357 if "--force" in sys.argv:
358 run_build = True
359 else:
360 # Raise errors for unsupported commands, improve help output, etc.
361 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30362
363 from setuptools import setup
Ralf Gommers99e99e92015-12-29 14:24:22364 if run_build:
Ralf Gommers17716d72013-12-06 19:45:40365 from numpy.distutils.core import setup
Julian Taylorc9fd6342014-04-05 11:13:13366 cwd = os.path.abspath(os.path.dirname(__file__))
367 if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
368 # Generate Cython sources, unless building from source release
369 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38370
Ralf Gommers17716d72013-12-06 19:45:40371 metadata['configuration'] = configuration
Ralf Gommers99e99e92015-12-29 14:24:22372 else:
373 # Version number is added to metadata inside configuration() if build
374 # is run.
375 metadata['version'] = get_version_info()[0]
Pauli Virtanen68159432009-12-06 11:56:18376
Pearu Petersone8fa0132003-03-07 18:08:28377 try:
Ralf Gommers17716d72013-12-06 19:45:40378 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28379 finally:
380 del sys.path[0]
381 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46382 return
Pearu Petersonc415fd12002-11-18 22:39:31383
Ralf Gommers17716d72013-12-06 19:45:40384
Travis Oliphant14db4192005-09-14 22:08:46385if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28386 setup_package()