blob: 7c22c6416fba7e3a1332ce7338194eff13d71ac8 [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 Sanders4db07542015-10-19 20:03:3418DOCLINES = (__doc__ or '').split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3119
Pearu Petersone8fa0132003-03-07 18:08:2820import os
Pearu Petersone8fa0132003-03-07 18:08:2821import sys
David Cournapeau5623a7c2009-04-02 16:21:3022import subprocess
Pearu Petersonc415fd12002-11-18 22:39:3123
Ralf Gommers17716d72013-12-06 19:45:4024
Charles Harris28eadc02013-07-11 18:08:4925if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
26 raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.")
27
Charles Harris09a52ed2013-03-28 23:13:5328if sys.version_info[0] >= 3:
David Cournapeau2b517692009-12-03 15:53:2929 import builtins
Charles Harris09a52ed2013-03-28 23:13:5330else:
31 import __builtin__ as builtins
David Cournapeau2b517692009-12-03 15:53:2932
Ralf Gommers17716d72013-12-06 19:45:4033
Travis Oliphantda9c6da2006-01-04 17:31:0734CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4435Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0736Intended Audience :: Science/Research
37Intended Audience :: Developers
38License :: OSI Approved
39Programming Language :: C
40Programming Language :: Python
Alex Willmerb268c2d2015-08-05 09:29:3941Programming Language :: Python :: 2
42Programming Language :: Python :: 2.6
43Programming Language :: Python :: 2.7
rgommerscdac1202011-01-25 14:02:4044Programming Language :: Python :: 3
Alex Willmerb268c2d2015-08-05 09:29:3945Programming Language :: Python :: 3.2
46Programming Language :: Python :: 3.3
47Programming Language :: Python :: 3.4
48Programming Language :: Python :: 3.5
49Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:0750Topic :: Software Development
51Topic :: Scientific/Engineering
52Operating System :: Microsoft :: Windows
53Operating System :: POSIX
54Operating System :: Unix
55Operating System :: MacOS
56"""
57
Ralf Gommers58c1bf72012-11-05 19:47:2358MAJOR = 1
Charles Harris6f5329f2014-05-04 23:07:3059MINOR = 10
Charles Harrise46c2d72016-01-07 02:21:0060MICRO = 4
61ISRELEASED = True
David Cournapeau5e041cb2009-03-27 11:16:0162VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0363
Ralf Gommers17716d72013-12-06 19:45:4064
Scott Sinclair58e63602010-11-09 15:09:1565# Return the git revision as a string
66def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1667 def _minimal_ext_cmd(cmd):
68 # construct minimal environment
69 env = {}
David Cournapeau5032b522009-09-18 10:10:3970 for k in ['SYSTEMROOT', 'PATH']:
71 v = os.environ.get(k)
72 if v is not None:
73 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1674 # LANGUAGE is used on win32
75 env['LANGUAGE'] = 'C'
76 env['LANG'] = 'C'
77 env['LC_ALL'] = 'C'
78 out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
79 return out
80
David Cournapeau5623a7c2009-04-02 16:21:3081 try:
Scott Sinclair58e63602010-11-09 15:09:1582 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0683 GIT_REVISION = out.strip().decode('ascii')
David Cournapeau5623a7c2009-04-02 16:21:3084 except OSError:
Scott Sinclaird5ed7442010-11-10 05:19:1585 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0186
Scott Sinclair58e63602010-11-09 15:09:1587 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:0188
David Cournapeau5bb1aa52009-03-27 16:39:0189# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
90# update it when the contents of directories change.
91if os.path.exists('MANIFEST'): os.remove('MANIFEST')
92
93# This is a bit hackish: we are setting a global variable so that the main
94# numpy __init__ can detect if it is being loaded by the setup routine, to
95# avoid attempting to load components that aren't built yet. While ugly, it's
96# a lot more robust than what was previously being used.
David Cournapeau2b517692009-12-03 15:53:2997builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:0198
rgommers13212a52011-03-03 16:13:0899
Ralf Gommers17716d72013-12-06 19:45:40100def get_version_info():
Ralf Gommers87e12c12011-03-24 15:30:06101 # Adding the git rev number needs to be done inside write_version_py(),
102 # otherwise the import of numpy.version messes up the build under Python 3.
103 FULLVERSION = VERSION
104 if os.path.exists('.git'):
105 GIT_REVISION = git_version()
106 elif os.path.exists('numpy/version.py'):
107 # must be a source distribution, use existing version file
Ralf Gommerscd6d53f2011-04-17 14:04:11108 try:
109 from numpy.version import git_revision as GIT_REVISION
110 except ImportError:
111 raise ImportError("Unable to import git_revision. Try removing " \
112 "numpy/version.py and the build directory " \
113 "before building.")
Ralf Gommers87e12c12011-03-24 15:30:06114 else:
115 GIT_REVISION = "Unknown"
116
117 if not ISRELEASED:
Ã…smund Hjulstade15f2922015-02-10 17:07:55118 FULLVERSION += '.dev0+' + GIT_REVISION[:7]
Ralf Gommers87e12c12011-03-24 15:30:06119
Ralf Gommers17716d72013-12-06 19:45:40120 return FULLVERSION, GIT_REVISION
121
122
123def write_version_py(filename='numpy/version.py'):
124 cnt = """
125# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
126short_version = '%(version)s'
127version = '%(version)s'
128full_version = '%(full_version)s'
129git_revision = '%(git_revision)s'
130release = %(isrelease)s
131
132if not release:
133 version = full_version
134"""
135 FULLVERSION, GIT_REVISION = get_version_info()
136
David Cournapeaua2ac9852009-03-27 11:15:36137 a = open(filename, 'w')
138 try:
Scott Sinclair58e63602010-11-09 15:09:15139 a.write(cnt % {'version': VERSION,
rgommers13212a52011-03-03 16:13:08140 'full_version' : FULLVERSION,
Scott Sinclair58e63602010-11-09 15:09:15141 'git_revision' : GIT_REVISION,
142 'isrelease': str(ISRELEASED)})
David Cournapeaua2ac9852009-03-27 11:15:36143 finally:
144 a.close()
145
Ralf Gommers17716d72013-12-06 19:45:40146
Pearu Peterson471196b2006-03-31 08:59:36147def configuration(parent_package='',top_path=None):
148 from numpy.distutils.misc_util import Configuration
149
Pearu Peterson17d7cfe2006-04-04 12:26:14150 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36151 config.set_options(ignore_setup_xxx_py=True,
152 assume_default_configuration=True,
153 delegate_options_to_subpackages=True,
154 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18155
Pearu Peterson471196b2006-03-31 08:59:36156 config.add_subpackage('numpy')
Jarrod Millman0b77f0e2007-10-29 14:58:18157
Pearu Peterson17d7cfe2006-04-04 12:26:14158 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01159
Pearu Peterson471196b2006-03-31 08:59:36160 return config
161
Julian Taylor4cd72742014-01-29 21:59:19162def check_submodules():
163 """ verify that the submodules are checked out and clean
164 use `git submodule update --init`; on failure
165 """
166 if not os.path.exists('.git'):
167 return
168 with open('.gitmodules') as f:
169 for l in f:
170 if 'path' in l:
171 p = l.split('=')[-1].strip()
172 if not os.path.exists(p):
173 raise ValueError('Submodule %s missing' % p)
174
175
176 proc = subprocess.Popen(['git', 'submodule', 'status'],
177 stdout=subprocess.PIPE)
178 status, _ = proc.communicate()
179 status = status.decode("ascii", "replace")
180 for line in status.splitlines():
181 if line.startswith('-') or line.startswith('+'):
182 raise ValueError('Submodule not clean: %s' % line)
183
184from distutils.command.sdist import sdist
185class sdist_checked(sdist):
186 """ check submodules on sdist to prevent incomplete tarballs """
187 def run(self):
188 check_submodules()
189 sdist.run(self)
Travis Oliphant14db4192005-09-14 22:08:46190
Julian Taylorc9fd6342014-04-05 11:13:13191def generate_cython():
192 cwd = os.path.abspath(os.path.dirname(__file__))
193 print("Cythonizing sources")
194 p = subprocess.call([sys.executable,
195 os.path.join(cwd, 'tools', 'cythonize.py'),
196 'numpy/random'],
197 cwd=cwd)
198 if p != 0:
199 raise RuntimeError("Running cythonize failed!")
200
Ralf Gommers17716d72013-12-06 19:45:40201def setup_package():
Charles Harrisb4180e32013-04-22 03:26:44202 src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
Pauli Virtanen68159432009-12-06 11:56:18203 old_path = os.getcwd()
204 os.chdir(src_path)
205 sys.path.insert(0, src_path)
206
Pauli Virtanen01312182010-11-23 16:50:54207 # Rewrite the version file everytime
208 write_version_py()
209
Ralf Gommers17716d72013-12-06 19:45:40210 metadata = dict(
211 name = 'numpy',
212 maintainer = "NumPy Developers",
213 maintainer_email = "numpy-discussion@scipy.org",
214 description = DOCLINES[0],
215 long_description = "\n".join(DOCLINES[2:]),
216 url = "http://www.numpy.org",
217 author = "Travis E. Oliphant et al.",
218 download_url = "http://sourceforge.net/projects/numpy/files/NumPy/",
219 license = 'BSD',
220 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
221 platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
222 test_suite='nose.collector',
Julian Taylor4cd72742014-01-29 21:59:19223 cmdclass={"sdist": sdist_checked},
Ralf Gommers17716d72013-12-06 19:45:40224 )
225
Pauli Virtanen01312182010-11-23 16:50:54226 # Run build
Ralf Gommers17716d72013-12-06 19:45:40227 if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
228 sys.argv[1] in ('--help-commands', 'egg_info', '--version',
229 'clean')):
230 # Use setuptools for these commands (they don't work well or at all
231 # with distutils). For normal builds use distutils.
232 try:
233 from setuptools import setup
234 except ImportError:
235 from distutils.core import setup
236
237 FULLVERSION, GIT_REVISION = get_version_info()
238 metadata['version'] = FULLVERSION
Ralf Gommers17716d72013-12-06 19:45:40239 else:
Julian Taylor0c1a5df2015-10-09 23:15:12240 if (len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel' or
241 sys.version_info[0] < 3 and sys.platform == "win32"):
242 # bdist_wheel and the MS python2.7 VS sdk needs setuptools
243 # the latter can also be triggered by (see python issue23246)
244 # SET DISTUTILS_USE_SDK=1
245 # SET MSSdk=1
Matthew Brett99cbdba2014-05-03 21:04:11246 import setuptools
Ralf Gommers17716d72013-12-06 19:45:40247 from numpy.distutils.core import setup
Julian Taylorc9fd6342014-04-05 11:13:13248 cwd = os.path.abspath(os.path.dirname(__file__))
249 if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
250 # Generate Cython sources, unless building from source release
251 generate_cython()
Ralf Gommers17716d72013-12-06 19:45:40252 metadata['configuration'] = configuration
Pauli Virtanen68159432009-12-06 11:56:18253
Pearu Petersone8fa0132003-03-07 18:08:28254 try:
Ralf Gommers17716d72013-12-06 19:45:40255 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28256 finally:
257 del sys.path[0]
258 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46259 return
Pearu Petersonc415fd12002-11-18 22:39:31260
Ralf Gommers17716d72013-12-06 19:45:40261
Travis Oliphant14db4192005-09-14 22:08:46262if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28263 setup_package()