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 |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 21 | import shutil |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 22 | import sys |
David Cournapeau | 5864bd2 | 2009-03-27 16:39:34 | [diff] [blame] | 23 | import re |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 24 | import subprocess |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 25 | |
Charles Harris | 28eadc0 | 2013-07-11 18:08:49 | [diff] [blame] | 26 | if 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 Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 29 | if sys.version_info[0] >= 3: |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 30 | import builtins |
Charles Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 31 | else: |
| 32 | import __builtin__ as builtins |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [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 | |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 50 | NAME = 'numpy' |
| 51 | MAINTAINER = "NumPy Developers" |
| 52 | MAINTAINER_EMAIL = "numpy-discussion@scipy.org" |
| 53 | DESCRIPTION = DOCLINES[0] |
| 54 | LONG_DESCRIPTION = "\n".join(DOCLINES[2:]) |
Sandro Tosi | 864353e | 2012-12-30 11:12:18 | [diff] [blame] | 55 | URL = "http://www.numpy.org" |
Ralf Gommers | 58c1bf7 | 2012-11-05 19:47:23 | [diff] [blame] | 56 | DOWNLOAD_URL = "http://sourceforge.net/projects/numpy/files/NumPy/" |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 57 | LICENSE = 'BSD' |
Charles Harris | b990ed5 | 2013-02-28 17:58:40 | [diff] [blame] | 58 | CLASSIFIERS = [_f for _f in CLASSIFIERS.split('\n') if _f] |
Stefan van der Walt | ddbb4bd | 2012-11-14 21:56:24 | [diff] [blame] | 59 | AUTHOR = "Travis E. Oliphant et al." |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 60 | AUTHOR_EMAIL = "oliphant@enthought.com" |
| 61 | PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"] |
Ralf Gommers | 58c1bf7 | 2012-11-05 19:47:23 | [diff] [blame] | 62 | MAJOR = 1 |
| 63 | MINOR = 8 |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 64 | MICRO = 0 |
Charles Harris | a60b390 | 2013-10-28 23:21:02 | [diff] [blame] | 65 | ISRELEASED = True |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 66 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 67 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 68 | # Return the git revision as a string |
| 69 | def git_version(): |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 70 | def _minimal_ext_cmd(cmd): |
| 71 | # construct minimal environment |
| 72 | env = {} |
David Cournapeau | 5032b52 | 2009-09-18 10:10:39 | [diff] [blame] | 73 | for k in ['SYSTEMROOT', 'PATH']: |
| 74 | v = os.environ.get(k) |
| 75 | if v is not None: |
| 76 | env[k] = v |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 77 | # LANGUAGE is used on win32 |
| 78 | env['LANGUAGE'] = 'C' |
| 79 | env['LANG'] = 'C' |
| 80 | env['LC_ALL'] = 'C' |
| 81 | out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] |
| 82 | return out |
| 83 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 84 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 85 | out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
Pauli Virtanen | d1a184c | 2010-11-15 01:00:06 | [diff] [blame] | 86 | GIT_REVISION = out.strip().decode('ascii') |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 87 | except OSError: |
Scott Sinclair | d5ed744 | 2010-11-10 05:19:15 | [diff] [blame] | 88 | GIT_REVISION = "Unknown" |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 89 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 90 | return GIT_REVISION |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 91 | |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 92 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
| 93 | # update it when the contents of directories change. |
| 94 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
| 95 | |
| 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 Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 100 | builtins.__NUMPY_SETUP__ = True |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 101 | |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 102 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 103 | def write_version_py(filename='numpy/version.py'): |
| 104 | cnt = """ |
David Cournapeau | 914bb15 | 2009-03-27 11:15:47 | [diff] [blame] | 105 | # THIS FILE IS GENERATED FROM NUMPY SETUP.PY |
Scott Sinclair | 0502dab | 2010-11-10 05:24:57 | [diff] [blame] | 106 | short_version = '%(version)s' |
| 107 | version = '%(version)s' |
| 108 | full_version = '%(full_version)s' |
| 109 | git_revision = '%(git_revision)s' |
| 110 | release = %(isrelease)s |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 111 | |
| 112 | if not release: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 113 | version = full_version |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 114 | """ |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 115 | # Adding the git rev number needs to be done inside write_version_py(), |
| 116 | # otherwise the import of numpy.version messes up the build under Python 3. |
| 117 | FULLVERSION = VERSION |
| 118 | if os.path.exists('.git'): |
| 119 | GIT_REVISION = git_version() |
| 120 | elif os.path.exists('numpy/version.py'): |
| 121 | # must be a source distribution, use existing version file |
Ralf Gommers | cd6d53f | 2011-04-17 14:04:11 | [diff] [blame] | 122 | try: |
| 123 | from numpy.version import git_revision as GIT_REVISION |
| 124 | except ImportError: |
| 125 | raise ImportError("Unable to import git_revision. Try removing " \ |
| 126 | "numpy/version.py and the build directory " \ |
| 127 | "before building.") |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 128 | else: |
| 129 | GIT_REVISION = "Unknown" |
| 130 | |
| 131 | if not ISRELEASED: |
| 132 | FULLVERSION += '.dev-' + GIT_REVISION[:7] |
| 133 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 134 | a = open(filename, 'w') |
| 135 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 136 | a.write(cnt % {'version': VERSION, |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 137 | 'full_version' : FULLVERSION, |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 138 | 'git_revision' : GIT_REVISION, |
| 139 | 'isrelease': str(ISRELEASED)}) |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 140 | finally: |
| 141 | a.close() |
| 142 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 143 | def configuration(parent_package='',top_path=None): |
| 144 | from numpy.distutils.misc_util import Configuration |
| 145 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 146 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 147 | config.set_options(ignore_setup_xxx_py=True, |
| 148 | assume_default_configuration=True, |
| 149 | delegate_options_to_subpackages=True, |
| 150 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 151 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 152 | config.add_subpackage('numpy') |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 153 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 154 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 155 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 156 | return config |
| 157 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 158 | def setup_package(): |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 159 | |
Charles Harris | b4180e3 | 2013-04-22 03:26:44 | [diff] [blame] | 160 | src_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 161 | old_path = os.getcwd() |
| 162 | os.chdir(src_path) |
| 163 | sys.path.insert(0, src_path) |
| 164 | |
Pauli Virtanen | 0131218 | 2010-11-23 16:50:54 | [diff] [blame] | 165 | # Rewrite the version file everytime |
| 166 | write_version_py() |
| 167 | |
| 168 | # Run build |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 169 | from numpy.distutils.core import setup |
| 170 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 171 | try: |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 172 | setup( |
David Cournapeau | c253b72 | 2009-03-27 11:15:22 | [diff] [blame] | 173 | name=NAME, |
| 174 | maintainer=MAINTAINER, |
| 175 | maintainer_email=MAINTAINER_EMAIL, |
| 176 | description=DESCRIPTION, |
| 177 | long_description=LONG_DESCRIPTION, |
| 178 | url=URL, |
| 179 | download_url=DOWNLOAD_URL, |
| 180 | license=LICENSE, |
| 181 | classifiers=CLASSIFIERS, |
| 182 | author=AUTHOR, |
| 183 | author_email=AUTHOR_EMAIL, |
| 184 | platforms=PLATFORMS, |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 185 | configuration=configuration ) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 186 | finally: |
| 187 | del sys.path[0] |
| 188 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 189 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 190 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 191 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 192 | setup_package() |