blob: e85110b4e960fe60a37972bf63a8a80d281a2925 [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
18DOCLINES = __doc__.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
rgommerscdac1202011-01-25 14:02:4041Programming Language :: Python :: 3
Travis Oliphantda9c6da2006-01-04 17:31:0742Topic :: Software Development
43Topic :: Scientific/Engineering
44Operating System :: Microsoft :: Windows
45Operating System :: POSIX
46Operating System :: Unix
47Operating System :: MacOS
48"""
49
Ralf Gommers58c1bf72012-11-05 19:47:2350MAJOR = 1
Charles Harris4d5ac692013-08-19 00:03:4151MINOR = 9
Julian Taylore4c861f2014-12-10 18:31:5652MICRO = 2
Julian Taylorc04513c2015-02-01 16:40:2853ISRELEASED = True
Julian Taylor762c6f12015-03-01 13:36:2754VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0355
Ralf Gommers17716d72013-12-06 19:45:4056
Scott Sinclair58e63602010-11-09 15:09:1557# Return the git revision as a string
58def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1659 def _minimal_ext_cmd(cmd):
60 # construct minimal environment
61 env = {}
David Cournapeau5032b522009-09-18 10:10:3962 for k in ['SYSTEMROOT', 'PATH']:
63 v = os.environ.get(k)
64 if v is not None:
65 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1666 # LANGUAGE is used on win32
67 env['LANGUAGE'] = 'C'
68 env['LANG'] = 'C'
69 env['LC_ALL'] = 'C'
70 out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
71 return out
72
David Cournapeau5623a7c2009-04-02 16:21:3073 try:
Scott Sinclair58e63602010-11-09 15:09:1574 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0675 GIT_REVISION = out.strip().decode('ascii')
David Cournapeau5623a7c2009-04-02 16:21:3076 except OSError:
Scott Sinclaird5ed7442010-11-10 05:19:1577 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0178
Scott Sinclair58e63602010-11-09 15:09:1579 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:0180
David Cournapeau5bb1aa52009-03-27 16:39:0181# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
82# update it when the contents of directories change.
83if os.path.exists('MANIFEST'): os.remove('MANIFEST')
84
85# This is a bit hackish: we are setting a global variable so that the main
86# numpy __init__ can detect if it is being loaded by the setup routine, to
87# avoid attempting to load components that aren't built yet. While ugly, it's
88# a lot more robust than what was previously being used.
David Cournapeau2b517692009-12-03 15:53:2989builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:0190
rgommers13212a52011-03-03 16:13:0891
Ralf Gommers17716d72013-12-06 19:45:4092def get_version_info():
Ralf Gommers87e12c12011-03-24 15:30:0693 # Adding the git rev number needs to be done inside write_version_py(),
94 # otherwise the import of numpy.version messes up the build under Python 3.
95 FULLVERSION = VERSION
96 if os.path.exists('.git'):
97 GIT_REVISION = git_version()
98 elif os.path.exists('numpy/version.py'):
99 # must be a source distribution, use existing version file
Ralf Gommerscd6d53f2011-04-17 14:04:11100 try:
101 from numpy.version import git_revision as GIT_REVISION
102 except ImportError:
103 raise ImportError("Unable to import git_revision. Try removing " \
104 "numpy/version.py and the build directory " \
105 "before building.")
Ralf Gommers87e12c12011-03-24 15:30:06106 else:
107 GIT_REVISION = "Unknown"
108
109 if not ISRELEASED:
110 FULLVERSION += '.dev-' + GIT_REVISION[:7]
111
Ralf Gommers17716d72013-12-06 19:45:40112 return FULLVERSION, GIT_REVISION
113
114
115def write_version_py(filename='numpy/version.py'):
116 cnt = """
117# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
118short_version = '%(version)s'
119version = '%(version)s'
120full_version = '%(full_version)s'
121git_revision = '%(git_revision)s'
122release = %(isrelease)s
123
124if not release:
125 version = full_version
126"""
127 FULLVERSION, GIT_REVISION = get_version_info()
128
David Cournapeaua2ac9852009-03-27 11:15:36129 a = open(filename, 'w')
130 try:
Scott Sinclair58e63602010-11-09 15:09:15131 a.write(cnt % {'version': VERSION,
rgommers13212a52011-03-03 16:13:08132 'full_version' : FULLVERSION,
Scott Sinclair58e63602010-11-09 15:09:15133 'git_revision' : GIT_REVISION,
134 'isrelease': str(ISRELEASED)})
David Cournapeaua2ac9852009-03-27 11:15:36135 finally:
136 a.close()
137
Ralf Gommers17716d72013-12-06 19:45:40138
Pearu Peterson471196b2006-03-31 08:59:36139def configuration(parent_package='',top_path=None):
140 from numpy.distutils.misc_util import Configuration
141
Pearu Peterson17d7cfe2006-04-04 12:26:14142 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36143 config.set_options(ignore_setup_xxx_py=True,
144 assume_default_configuration=True,
145 delegate_options_to_subpackages=True,
146 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18147
Pearu Peterson471196b2006-03-31 08:59:36148 config.add_subpackage('numpy')
Jarrod Millman0b77f0e2007-10-29 14:58:18149
Pearu Peterson17d7cfe2006-04-04 12:26:14150 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01151
Pearu Peterson471196b2006-03-31 08:59:36152 return config
153
Julian Taylor4cd72742014-01-29 21:59:19154def check_submodules():
155 """ verify that the submodules are checked out and clean
156 use `git submodule update --init`; on failure
157 """
158 if not os.path.exists('.git'):
159 return
160 with open('.gitmodules') as f:
161 for l in f:
162 if 'path' in l:
163 p = l.split('=')[-1].strip()
164 if not os.path.exists(p):
165 raise ValueError('Submodule %s missing' % p)
166
167
168 proc = subprocess.Popen(['git', 'submodule', 'status'],
169 stdout=subprocess.PIPE)
170 status, _ = proc.communicate()
171 status = status.decode("ascii", "replace")
172 for line in status.splitlines():
173 if line.startswith('-') or line.startswith('+'):
174 raise ValueError('Submodule not clean: %s' % line)
175
176from distutils.command.sdist import sdist
177class sdist_checked(sdist):
178 """ check submodules on sdist to prevent incomplete tarballs """
179 def run(self):
180 check_submodules()
181 sdist.run(self)
Travis Oliphant14db4192005-09-14 22:08:46182
Julian Taylorc9fd6342014-04-05 11:13:13183def generate_cython():
184 cwd = os.path.abspath(os.path.dirname(__file__))
185 print("Cythonizing sources")
186 p = subprocess.call([sys.executable,
187 os.path.join(cwd, 'tools', 'cythonize.py'),
188 'numpy/random'],
189 cwd=cwd)
190 if p != 0:
191 raise RuntimeError("Running cythonize failed!")
192
Ralf Gommers17716d72013-12-06 19:45:40193def setup_package():
Charles Harrisb4180e32013-04-22 03:26:44194 src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
Pauli Virtanen68159432009-12-06 11:56:18195 old_path = os.getcwd()
196 os.chdir(src_path)
197 sys.path.insert(0, src_path)
198
Pauli Virtanen01312182010-11-23 16:50:54199 # Rewrite the version file everytime
200 write_version_py()
201
Ralf Gommers17716d72013-12-06 19:45:40202 metadata = dict(
203 name = 'numpy',
204 maintainer = "NumPy Developers",
205 maintainer_email = "numpy-discussion@scipy.org",
206 description = DOCLINES[0],
207 long_description = "\n".join(DOCLINES[2:]),
208 url = "http://www.numpy.org",
209 author = "Travis E. Oliphant et al.",
210 download_url = "http://sourceforge.net/projects/numpy/files/NumPy/",
211 license = 'BSD',
212 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
213 platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
214 test_suite='nose.collector',
Julian Taylor4cd72742014-01-29 21:59:19215 cmdclass={"sdist": sdist_checked},
Ralf Gommers17716d72013-12-06 19:45:40216 )
217
Pauli Virtanen01312182010-11-23 16:50:54218 # Run build
Ralf Gommers17716d72013-12-06 19:45:40219 if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
220 sys.argv[1] in ('--help-commands', 'egg_info', '--version',
221 'clean')):
222 # Use setuptools for these commands (they don't work well or at all
223 # with distutils). For normal builds use distutils.
224 try:
225 from setuptools import setup
226 except ImportError:
227 from distutils.core import setup
228
229 FULLVERSION, GIT_REVISION = get_version_info()
230 metadata['version'] = FULLVERSION
Ralf Gommers17716d72013-12-06 19:45:40231 else:
Matthew Brett99cbdba2014-05-03 21:04:11232 if len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel':
233 # bdist_wheel needs setuptools
234 import setuptools
Ralf Gommers17716d72013-12-06 19:45:40235 from numpy.distutils.core import setup
Julian Taylorc9fd6342014-04-05 11:13:13236 cwd = os.path.abspath(os.path.dirname(__file__))
237 if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
238 # Generate Cython sources, unless building from source release
239 generate_cython()
Ralf Gommers17716d72013-12-06 19:45:40240 metadata['configuration'] = configuration
Pauli Virtanen68159432009-12-06 11:56:18241
Pearu Petersone8fa0132003-03-07 18:08:28242 try:
Ralf Gommers17716d72013-12-06 19:45:40243 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28244 finally:
245 del sys.path[0]
246 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46247 return
Pearu Petersonc415fd12002-11-18 22:39:31248
Ralf Gommers17716d72013-12-06 19:45:40249
Travis Oliphant14db4192005-09-14 22:08:46250if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28251 setup_package()