Fernando Perez | 36d3c16 | 2006-07-12 06:02:28 | [diff] [blame] | 1 | #!/usr/bin/env python |
Travis Oliphant | c8b5a7e | 2006-01-06 02:12:50 | [diff] [blame] | 2 | """NumPy: array processing for numbers, strings, records, and objects. |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 3 | |
Travis Oliphant | c8b5a7e | 2006-01-06 02:12:50 | [diff] [blame] | 4 | NumPy is a general-purpose array-processing package designed to |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 5 | efficiently manipulate large multi-dimensional arrays of arbitrary |
| 6 | records without sacrificing too much speed for small multi-dimensional |
Travis Oliphant | c8b5a7e | 2006-01-06 02:12:50 | [diff] [blame] | 7 | arrays. NumPy is built on the Numeric code base and adds features |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 8 | introduced by numarray as well as an extended C-API and the ability to |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 9 | create arrays of arbitrary type which also makes NumPy suitable for |
| 10 | interfacing with general-purpose data-base applications. |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 11 | |
| 12 | There are also basic facilities for discrete fourier transform, |
| 13 | basic linear algebra and random number generation. |
Charles Harris | 6aa264c | 2013-02-27 20:26:58 | [diff] [blame] | 14 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 15 | """ |
Charles Harris | bb726ca | 2013-04-06 19:25:26 | [diff] [blame] | 16 | from __future__ import division, print_function |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 17 | |
| 18 | DOCLINES = __doc__.split("\n") |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 19 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 20 | import os |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 21 | import sys |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 22 | import subprocess |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 23 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 24 | |
Charles Harris | 28eadc0 | 2013-07-11 18:08:49 | [diff] [blame] | 25 | if 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 Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 28 | if sys.version_info[0] >= 3: |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 29 | import builtins |
Charles Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 30 | else: |
| 31 | import __builtin__ as builtins |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 32 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 33 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 34 | CLASSIFIERS = """\ |
Robert Kern | 19da971 | 2008-06-18 22:53:44 | [diff] [blame] | 35 | Development Status :: 5 - Production/Stable |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 36 | Intended Audience :: Science/Research |
| 37 | Intended Audience :: Developers |
| 38 | License :: OSI Approved |
| 39 | Programming Language :: C |
| 40 | Programming Language :: Python |
rgommers | cdac120 | 2011-01-25 14:02:40 | [diff] [blame] | 41 | Programming Language :: Python :: 3 |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 42 | Topic :: Software Development |
| 43 | Topic :: Scientific/Engineering |
| 44 | Operating System :: Microsoft :: Windows |
| 45 | Operating System :: POSIX |
| 46 | Operating System :: Unix |
| 47 | Operating System :: MacOS |
| 48 | """ |
| 49 | |
Ralf Gommers | 58c1bf7 | 2012-11-05 19:47:23 | [diff] [blame] | 50 | MAJOR = 1 |
Charles Harris | 4d5ac69 | 2013-08-19 00:03:41 | [diff] [blame] | 51 | MINOR = 9 |
Julian Taylor | e4c861f | 2014-12-10 18:31:56 | [diff] [blame] | 52 | MICRO = 2 |
Julian Taylor | c04513c | 2015-02-01 16:40:28 | [diff] [blame] | 53 | ISRELEASED = True |
Julian Taylor | 762c6f1 | 2015-03-01 13:36:27 | [diff] [blame] | 54 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 55 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 56 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 57 | # Return the git revision as a string |
| 58 | def git_version(): |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 59 | def _minimal_ext_cmd(cmd): |
| 60 | # construct minimal environment |
| 61 | env = {} |
David Cournapeau | 5032b52 | 2009-09-18 10:10:39 | [diff] [blame] | 62 | for k in ['SYSTEMROOT', 'PATH']: |
| 63 | v = os.environ.get(k) |
| 64 | if v is not None: |
| 65 | env[k] = v |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 66 | # 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 Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 73 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 74 | out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
Pauli Virtanen | d1a184c | 2010-11-15 01:00:06 | [diff] [blame] | 75 | GIT_REVISION = out.strip().decode('ascii') |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 76 | except OSError: |
Scott Sinclair | d5ed744 | 2010-11-10 05:19:15 | [diff] [blame] | 77 | GIT_REVISION = "Unknown" |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 78 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 79 | return GIT_REVISION |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 80 | |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 81 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
| 82 | # update it when the contents of directories change. |
| 83 | if 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 Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 89 | builtins.__NUMPY_SETUP__ = True |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 90 | |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 91 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 92 | def get_version_info(): |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 93 | # 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 Gommers | cd6d53f | 2011-04-17 14:04:11 | [diff] [blame] | 100 | 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 Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 106 | else: |
| 107 | GIT_REVISION = "Unknown" |
| 108 | |
| 109 | if not ISRELEASED: |
| 110 | FULLVERSION += '.dev-' + GIT_REVISION[:7] |
| 111 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 112 | return FULLVERSION, GIT_REVISION |
| 113 | |
| 114 | |
| 115 | def write_version_py(filename='numpy/version.py'): |
| 116 | cnt = """ |
| 117 | # THIS FILE IS GENERATED FROM NUMPY SETUP.PY |
| 118 | short_version = '%(version)s' |
| 119 | version = '%(version)s' |
| 120 | full_version = '%(full_version)s' |
| 121 | git_revision = '%(git_revision)s' |
| 122 | release = %(isrelease)s |
| 123 | |
| 124 | if not release: |
| 125 | version = full_version |
| 126 | """ |
| 127 | FULLVERSION, GIT_REVISION = get_version_info() |
| 128 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 129 | a = open(filename, 'w') |
| 130 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 131 | a.write(cnt % {'version': VERSION, |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 132 | 'full_version' : FULLVERSION, |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 133 | 'git_revision' : GIT_REVISION, |
| 134 | 'isrelease': str(ISRELEASED)}) |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 135 | finally: |
| 136 | a.close() |
| 137 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 138 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 139 | def configuration(parent_package='',top_path=None): |
| 140 | from numpy.distutils.misc_util import Configuration |
| 141 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 142 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 143 | config.set_options(ignore_setup_xxx_py=True, |
| 144 | assume_default_configuration=True, |
| 145 | delegate_options_to_subpackages=True, |
| 146 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 147 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 148 | config.add_subpackage('numpy') |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 149 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 150 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 151 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 152 | return config |
| 153 | |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 154 | def 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 | |
| 176 | from distutils.command.sdist import sdist |
| 177 | class sdist_checked(sdist): |
| 178 | """ check submodules on sdist to prevent incomplete tarballs """ |
| 179 | def run(self): |
| 180 | check_submodules() |
| 181 | sdist.run(self) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 182 | |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 183 | def 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 Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 193 | def setup_package(): |
Charles Harris | b4180e3 | 2013-04-22 03:26:44 | [diff] [blame] | 194 | src_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 195 | old_path = os.getcwd() |
| 196 | os.chdir(src_path) |
| 197 | sys.path.insert(0, src_path) |
| 198 | |
Pauli Virtanen | 0131218 | 2010-11-23 16:50:54 | [diff] [blame] | 199 | # Rewrite the version file everytime |
| 200 | write_version_py() |
| 201 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 202 | 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 Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 215 | cmdclass={"sdist": sdist_checked}, |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 216 | ) |
| 217 | |
Pauli Virtanen | 0131218 | 2010-11-23 16:50:54 | [diff] [blame] | 218 | # Run build |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 219 | 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 Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 231 | else: |
Matthew Brett | 99cbdba | 2014-05-03 21:04:11 | [diff] [blame] | 232 | if len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel': |
| 233 | # bdist_wheel needs setuptools |
| 234 | import setuptools |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 235 | from numpy.distutils.core import setup |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 236 | 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 Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 240 | metadata['configuration'] = configuration |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 241 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 242 | try: |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 243 | setup(**metadata) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 244 | finally: |
| 245 | del sys.path[0] |
| 246 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 247 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 248 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 249 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 250 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 251 | setup_package() |