blob: 5e36ac0caca42c195d5a6918b1d91ff157292f4f [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
Matthew Brettbe575d52016-03-07 20:52:0815All numpy wheels distributed from pypi are BSD licensed.
16
17Windows wheels are linked against the ATLAS BLAS / LAPACK library, restricted
18to SSE2 instructions, so may not give optimal linear algebra performance for
19your machine. See http://docs.scipy.org/doc/numpy/user/install.html for
20alternatives.
21
Travis Oliphantda9c6da2006-01-04 17:31:0722"""
Charles Harrisbb726ca2013-04-06 19:25:2623from __future__ import division, print_function
Travis Oliphantda9c6da2006-01-04 17:31:0724
David Sanders922442f2015-10-19 20:03:3425DOCLINES = (__doc__ or '').split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3126
Pearu Petersone8fa0132003-03-07 18:08:2827import os
28import sys
David Cournapeau5623a7c2009-04-02 16:21:3029import subprocess
Ralf Gommers99e99e92015-12-29 14:24:2230import textwrap
Pearu Petersonc415fd12002-11-18 22:39:3131
Ralf Gommers17716d72013-12-06 19:45:4032
Joseph Fox-Rabinovitz21d2fb72016-04-12 05:34:3933if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 4):
Charles Harris3ce03de2016-04-09 15:18:2234 raise RuntimeError("Python version 2.7 or >= 3.4 required.")
Charles Harris28eadc02013-07-11 18:08:4935
Charles Harris09a52ed2013-03-28 23:13:5336if sys.version_info[0] >= 3:
David Cournapeau2b517692009-12-03 15:53:2937 import builtins
Charles Harris09a52ed2013-03-28 23:13:5338else:
39 import __builtin__ as builtins
David Cournapeau2b517692009-12-03 15:53:2940
Ralf Gommers17716d72013-12-06 19:45:4041
Travis Oliphantda9c6da2006-01-04 17:31:0742CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4443Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0744Intended Audience :: Science/Research
45Intended Audience :: Developers
46License :: OSI Approved
47Programming Language :: C
48Programming Language :: Python
Alex Willmer193668a2015-08-05 09:29:3949Programming Language :: Python :: 2
Alex Willmer193668a2015-08-05 09:29:3950Programming Language :: Python :: 2.7
rgommerscdac1202011-01-25 14:02:4051Programming Language :: Python :: 3
Alex Willmer193668a2015-08-05 09:29:3952Programming Language :: Python :: 3.4
53Programming Language :: Python :: 3.5
Charles Harris9a850402016-11-05 20:18:4454Programming Language :: Python :: 3.6
Alex Willmer193668a2015-08-05 09:29:3955Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:0756Topic :: Software Development
57Topic :: Scientific/Engineering
58Operating System :: Microsoft :: Windows
59Operating System :: POSIX
60Operating System :: Unix
61Operating System :: MacOS
62"""
63
Ralf Gommers58c1bf72012-11-05 19:47:2364MAJOR = 1
Charles Harris11a9b712016-01-20 02:53:2065MINOR = 12
David Cournapeau5e041cb2009-03-27 11:16:0166MICRO = 0
Charles Harris561f1ac2017-01-15 19:49:3267ISRELEASED = True
David Cournapeau5e041cb2009-03-27 11:16:0168VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0369
Ralf Gommers17716d72013-12-06 19:45:4070
Scott Sinclair58e63602010-11-09 15:09:1571# Return the git revision as a string
72def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1673 def _minimal_ext_cmd(cmd):
74 # construct minimal environment
75 env = {}
David Cournapeau5032b522009-09-18 10:10:3976 for k in ['SYSTEMROOT', 'PATH']:
77 v = os.environ.get(k)
78 if v is not None:
79 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1680 # LANGUAGE is used on win32
81 env['LANGUAGE'] = 'C'
82 env['LANG'] = 'C'
83 env['LC_ALL'] = 'C'
84 out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
85 return out
86
David Cournapeau5623a7c2009-04-02 16:21:3087 try:
Scott Sinclair58e63602010-11-09 15:09:1588 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0689 GIT_REVISION = out.strip().decode('ascii')
David Cournapeau5623a7c2009-04-02 16:21:3090 except OSError:
Scott Sinclaird5ed7442010-11-10 05:19:1591 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0192
Scott Sinclair58e63602010-11-09 15:09:1593 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:0194
Ralf Gommers4b0ed792015-12-29 10:29:3895# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
96# properly updated when the contents of directories change (true for distutils,
97# not sure about setuptools).
98if os.path.exists('MANIFEST'):
99 os.remove('MANIFEST')
David Cournapeau5bb1aa52009-03-27 16:39:01100
101# This is a bit hackish: we are setting a global variable so that the main
102# numpy __init__ can detect if it is being loaded by the setup routine, to
103# avoid attempting to load components that aren't built yet. While ugly, it's
104# a lot more robust than what was previously being used.
David Cournapeau2b517692009-12-03 15:53:29105builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:01106
rgommers13212a52011-03-03 16:13:08107
Ralf Gommers17716d72013-12-06 19:45:40108def get_version_info():
Ralf Gommers87e12c12011-03-24 15:30:06109 # Adding the git rev number needs to be done inside write_version_py(),
110 # otherwise the import of numpy.version messes up the build under Python 3.
111 FULLVERSION = VERSION
112 if os.path.exists('.git'):
113 GIT_REVISION = git_version()
114 elif os.path.exists('numpy/version.py'):
115 # must be a source distribution, use existing version file
Ralf Gommerscd6d53f2011-04-17 14:04:11116 try:
117 from numpy.version import git_revision as GIT_REVISION
118 except ImportError:
119 raise ImportError("Unable to import git_revision. Try removing " \
120 "numpy/version.py and the build directory " \
121 "before building.")
Ralf Gommers87e12c12011-03-24 15:30:06122 else:
123 GIT_REVISION = "Unknown"
124
125 if not ISRELEASED:
Ã…smund Hjulstade15f2922015-02-10 17:07:55126 FULLVERSION += '.dev0+' + GIT_REVISION[:7]
Ralf Gommers87e12c12011-03-24 15:30:06127
Ralf Gommers17716d72013-12-06 19:45:40128 return FULLVERSION, GIT_REVISION
129
130
131def write_version_py(filename='numpy/version.py'):
132 cnt = """
133# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
Ralf Gommers105a4982015-12-29 20:58:36134#
135# To compare versions robustly, use `numpy.lib.NumpyVersion`
Ralf Gommers17716d72013-12-06 19:45:40136short_version = '%(version)s'
137version = '%(version)s'
138full_version = '%(full_version)s'
139git_revision = '%(git_revision)s'
140release = %(isrelease)s
141
142if not release:
143 version = full_version
144"""
145 FULLVERSION, GIT_REVISION = get_version_info()
146
David Cournapeaua2ac9852009-03-27 11:15:36147 a = open(filename, 'w')
148 try:
Scott Sinclair58e63602010-11-09 15:09:15149 a.write(cnt % {'version': VERSION,
rgommers13212a52011-03-03 16:13:08150 'full_version' : FULLVERSION,
Scott Sinclair58e63602010-11-09 15:09:15151 'git_revision' : GIT_REVISION,
152 'isrelease': str(ISRELEASED)})
David Cournapeaua2ac9852009-03-27 11:15:36153 finally:
154 a.close()
155
Ralf Gommers17716d72013-12-06 19:45:40156
Pearu Peterson471196b2006-03-31 08:59:36157def configuration(parent_package='',top_path=None):
158 from numpy.distutils.misc_util import Configuration
159
Pearu Peterson17d7cfe2006-04-04 12:26:14160 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36161 config.set_options(ignore_setup_xxx_py=True,
162 assume_default_configuration=True,
163 delegate_options_to_subpackages=True,
164 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18165
Pearu Peterson471196b2006-03-31 08:59:36166 config.add_subpackage('numpy')
Jarrod Millman0b77f0e2007-10-29 14:58:18167
Pearu Peterson17d7cfe2006-04-04 12:26:14168 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01169
Pearu Peterson471196b2006-03-31 08:59:36170 return config
171
Ralf Gommers4b0ed792015-12-29 10:29:38172
Julian Taylor4cd72742014-01-29 21:59:19173def check_submodules():
174 """ verify that the submodules are checked out and clean
175 use `git submodule update --init`; on failure
176 """
177 if not os.path.exists('.git'):
178 return
179 with open('.gitmodules') as f:
180 for l in f:
181 if 'path' in l:
182 p = l.split('=')[-1].strip()
183 if not os.path.exists(p):
184 raise ValueError('Submodule %s missing' % p)
185
186
187 proc = subprocess.Popen(['git', 'submodule', 'status'],
188 stdout=subprocess.PIPE)
189 status, _ = proc.communicate()
190 status = status.decode("ascii", "replace")
191 for line in status.splitlines():
192 if line.startswith('-') or line.startswith('+'):
193 raise ValueError('Submodule not clean: %s' % line)
194
Ralf Gommers4b0ed792015-12-29 10:29:38195
Ralf Gommers6770f982016-01-27 20:34:28196from distutils.command.sdist import sdist
Julian Taylor4cd72742014-01-29 21:59:19197class sdist_checked(sdist):
198 """ check submodules on sdist to prevent incomplete tarballs """
199 def run(self):
200 check_submodules()
201 sdist.run(self)
Travis Oliphant14db4192005-09-14 22:08:46202
Ralf Gommers4b0ed792015-12-29 10:29:38203
Julian Taylorc9fd6342014-04-05 11:13:13204def generate_cython():
205 cwd = os.path.abspath(os.path.dirname(__file__))
206 print("Cythonizing sources")
207 p = subprocess.call([sys.executable,
208 os.path.join(cwd, 'tools', 'cythonize.py'),
209 'numpy/random'],
210 cwd=cwd)
211 if p != 0:
212 raise RuntimeError("Running cythonize failed!")
213
Ralf Gommers4b0ed792015-12-29 10:29:38214
Ralf Gommersb9f48092015-12-29 11:05:30215def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22216 """Check the commands and respond appropriately. Disable broken commands.
217
218 Return a boolean value for whether or not to run the build or not (avoid
219 parsing Cython and template files if False).
220 """
Ralf Gommersb9f48092015-12-29 11:05:30221 if len(sys.argv) < 2:
222 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22223 return True
Ralf Gommersb9f48092015-12-29 11:05:30224
Ralf Gommers99e99e92015-12-29 14:24:22225 info_commands = ['--help-commands', '--name', '--version', '-V',
226 '--fullname', '--author', '--author-email',
227 '--maintainer', '--maintainer-email', '--contact',
228 '--contact-email', '--url', '--license', '--description',
229 '--long-description', '--platforms', '--classifiers',
230 '--keywords', '--provides', '--requires', '--obsoletes']
231 # Add commands that do more than print info, but also don't need Cython and
232 # template parsing.
233 info_commands.extend(['egg_info', 'install_egg_info', 'rotate'])
234
235 for command in info_commands:
236 if command in sys.argv[1:]:
237 return False
238
239 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
240 # fine as they are, but are usually used together with one of the commands
241 # below and not standalone. Hence they're not added to good_commands.
242 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23243 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
Ralf Gommersb9f48092015-12-29 11:05:30244 'bdist_wininst', 'bdist_msi', 'bdist_mpkg')
Ralf Gommers99e99e92015-12-29 14:24:22245
Ralf Gommersb9f48092015-12-29 11:05:30246 for command in good_commands:
247 if command in sys.argv[1:]:
Ralf Gommers99e99e92015-12-29 14:24:22248 return True
Ralf Gommersb9f48092015-12-29 11:05:30249
Ralf Gommersab5c6d02016-01-16 14:21:23250 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22251 # useful messages to the user
252 if 'install' in sys.argv[1:]:
253 print(textwrap.dedent("""
254 Note: if you need reliable uninstall behavior, then install
255 with pip instead of using `setup.py install`:
256
257 - `pip install .` (from a git repo or downloaded source
258 release)
Pierre de Buyl3f6672a2016-09-06 12:54:08259 - `pip install numpy` (last NumPy release on PyPi)
Ralf Gommers99e99e92015-12-29 14:24:22260
261 """))
262 return True
263
264 if '--help' in sys.argv[1:] or '-h' in sys.argv[1]:
265 print(textwrap.dedent("""
Pierre de Buyl3f6672a2016-09-06 12:54:08266 NumPy-specific help
Ralf Gommers99e99e92015-12-29 14:24:22267 -------------------
268
Pierre de Buyl3f6672a2016-09-06 12:54:08269 To install NumPy from here with reliable uninstall, we recommend
270 that you use `pip install .`. To install the latest NumPy release
Ralf Gommers99e99e92015-12-29 14:24:22271 from PyPi, use `pip install numpy`.
272
273 For help with build/installation issues, please ask on the
274 numpy-discussion mailing list. If you are sure that you have run
275 into a bug, please report it at https://github.com/numpy/numpy/issues.
276
277 Setuptools commands help
278 ------------------------
279 """))
280 return False
281
282 # The following commands aren't supported. They can only be executed when
283 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30284 bad_commands = dict(
285 test="""
286 `setup.py test` is not supported. Use one of the following
287 instead:
288
289 - `python runtests.py` (to build and test)
290 - `python runtests.py --no-build` (to test installed numpy)
291 - `>>> numpy.test()` (run tests for installed numpy
292 from within an interpreter)
293 """,
294 upload="""
295 `setup.py upload` is not supported, because it's insecure.
296 Instead, build what you want to upload and upload those files
297 with `twine upload -s <filenames>` instead.
298 """,
299 upload_docs="`setup.py upload_docs` is not supported",
300 easy_install="`setup.py easy_install` is not supported",
301 clean="""
302 `setup.py clean` is not supported, use one of the following instead:
303
304 - `git clean -xdf` (cleans all files)
305 - `git clean -Xdf` (cleans all versioned files, doesn't touch
306 files that aren't checked into the git repo)
307 """,
308 check="`setup.py check` is not supported",
309 register="`setup.py register` is not supported",
310 bdist_dumb="`setup.py bdist_dumb` is not supported",
Ralf Gommers99e99e92015-12-29 14:24:22311 bdist="`setup.py bdist` is not supported",
312 build_sphinx="""
313 `setup.py build_sphinx` is not supported, use the
314 Makefile under doc/""",
315 flake8="`setup.py flake8` is not supported, use flake8 standalone",
Ralf Gommersb9f48092015-12-29 11:05:30316 )
Ralf Gommers99e99e92015-12-29 14:24:22317 bad_commands['nosetests'] = bad_commands['test']
Luca Mussi69d2cc82016-04-07 11:24:49318 for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
Ralf Gommers99e99e92015-12-29 14:24:22319 'register', 'check', 'install_data', 'install_headers',
320 'install_lib', 'install_scripts', ):
321 bad_commands[command] = "`setup.py %s` is not supported" % command
322
Ralf Gommersb9f48092015-12-29 11:05:30323 for command in bad_commands.keys():
324 if command in sys.argv[1:]:
Ralf Gommersb9f48092015-12-29 11:05:30325 print(textwrap.dedent(bad_commands[command]) +
326 "\nAdd `--force` to your command to use it anyway if you "
327 "must (unsupported).\n")
328 sys.exit(1)
329
Ralf Gommers99e99e92015-12-29 14:24:22330 # If we got here, we didn't detect what setup.py command was given
331 import warnings
332 warnings.warn("Unrecognized setuptools command, proceeding with "
Sebastian Berg7884a8c2016-01-23 14:58:58333 "generating Cython sources and expanding templates", stacklevel=2)
Ralf Gommers99e99e92015-12-29 14:24:22334 return True
Ralf Gommersb9f48092015-12-29 11:05:30335
336
Ralf Gommers17716d72013-12-06 19:45:40337def setup_package():
Charles Harrisb4180e32013-04-22 03:26:44338 src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
Pauli Virtanen68159432009-12-06 11:56:18339 old_path = os.getcwd()
340 os.chdir(src_path)
341 sys.path.insert(0, src_path)
342
Pauli Virtanen01312182010-11-23 16:50:54343 # Rewrite the version file everytime
344 write_version_py()
345
Ralf Gommers17716d72013-12-06 19:45:40346 metadata = dict(
347 name = 'numpy',
348 maintainer = "NumPy Developers",
349 maintainer_email = "numpy-discussion@scipy.org",
350 description = DOCLINES[0],
351 long_description = "\n".join(DOCLINES[2:]),
352 url = "http://www.numpy.org",
353 author = "Travis E. Oliphant et al.",
354 download_url = "http://sourceforge.net/projects/numpy/files/NumPy/",
355 license = 'BSD',
356 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
357 platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
358 test_suite='nose.collector',
Julian Taylor4cd72742014-01-29 21:59:19359 cmdclass={"sdist": sdist_checked},
Ralf Gommers17716d72013-12-06 19:45:40360 )
361
Ralf Gommers99e99e92015-12-29 14:24:22362 if "--force" in sys.argv:
363 run_build = True
364 else:
365 # Raise errors for unsupported commands, improve help output, etc.
366 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30367
368 from setuptools import setup
Ralf Gommers99e99e92015-12-29 14:24:22369 if run_build:
Ralf Gommers17716d72013-12-06 19:45:40370 from numpy.distutils.core import setup
Julian Taylorc9fd6342014-04-05 11:13:13371 cwd = os.path.abspath(os.path.dirname(__file__))
372 if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
373 # Generate Cython sources, unless building from source release
374 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38375
Ralf Gommers17716d72013-12-06 19:45:40376 metadata['configuration'] = configuration
Ralf Gommers99e99e92015-12-29 14:24:22377 else:
378 # Version number is added to metadata inside configuration() if build
379 # is run.
380 metadata['version'] = get_version_info()[0]
Pauli Virtanen68159432009-12-06 11:56:18381
Pearu Petersone8fa0132003-03-07 18:08:28382 try:
Ralf Gommers17716d72013-12-06 19:45:40383 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28384 finally:
385 del sys.path[0]
386 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46387 return
Pearu Petersonc415fd12002-11-18 22:39:31388
Ralf Gommers17716d72013-12-06 19:45:40389
Travis Oliphant14db4192005-09-14 22:08:46390if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28391 setup_package()
Ralf Gommersbbee7472016-08-21 05:23:35392 # This may avoid problems where numpy is installed via ``*_requires`` by
393 # setuptools, the global namespace isn't reset properly, and then numpy is
394 # imported later (which will then fail to load numpy extension modules).
395 # See gh-7956 for details
396 del builtins.__NUMPY_SETUP__