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. |
| 14 | """ |
| 15 | |
| 16 | DOCLINES = __doc__.split("\n") |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 17 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 18 | import os |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 19 | import shutil |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 20 | import sys |
David Cournapeau | 5864bd2 | 2009-03-27 16:39:34 | [diff] [blame] | 21 | import re |
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 | |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 24 | if sys.version_info[0] < 3: |
| 25 | import __builtin__ as builtins |
| 26 | else: |
| 27 | import builtins |
| 28 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 29 | CLASSIFIERS = """\ |
Robert Kern | 19da971 | 2008-06-18 22:53:44 | [diff] [blame] | 30 | Development Status :: 5 - Production/Stable |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 31 | Intended Audience :: Science/Research |
| 32 | Intended Audience :: Developers |
| 33 | License :: OSI Approved |
| 34 | Programming Language :: C |
| 35 | Programming Language :: Python |
rgommers | cdac120 | 2011-01-25 14:02:40 | [diff] [blame] | 36 | Programming Language :: Python :: 3 |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 37 | Topic :: Software Development |
| 38 | Topic :: Scientific/Engineering |
| 39 | Operating System :: Microsoft :: Windows |
| 40 | Operating System :: POSIX |
| 41 | Operating System :: Unix |
| 42 | Operating System :: MacOS |
| 43 | """ |
| 44 | |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 45 | NAME = 'numpy' |
| 46 | MAINTAINER = "NumPy Developers" |
| 47 | MAINTAINER_EMAIL = "numpy-discussion@scipy.org" |
| 48 | DESCRIPTION = DOCLINES[0] |
| 49 | LONG_DESCRIPTION = "\n".join(DOCLINES[2:]) |
Sandro Tosi | d5d2049 | 2012-12-30 11:12:18 | [diff] [blame] | 50 | URL = "http://www.numpy.org" |
Ralf Gommers | 98ca13d | 2012-11-05 19:47:23 | [diff] [blame] | 51 | DOWNLOAD_URL = "http://sourceforge.net/projects/numpy/files/NumPy/" |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 52 | LICENSE = 'BSD' |
| 53 | CLASSIFIERS = filter(None, CLASSIFIERS.split('\n')) |
Ondřej Čertík | 1a5afd9 | 2012-11-14 23:00:29 | [diff] [blame] | 54 | AUTHOR = "Travis E. Oliphant et al." |
Travis E. Oliphant | f93774d | 2012-07-18 06:44:14 | [diff] [blame] | 55 | AUTHOR_EMAIL = "numpy-discussion@scipy.org" |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 56 | PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"] |
Ralf Gommers | 28ffac7 | 2012-08-21 06:20:56 | [diff] [blame] | 57 | MAJOR = 1 |
| 58 | MINOR = 7 |
Ondrej Certik | 21bda0e | 2013-03-24 18:47:59 | [diff] [blame] | 59 | MICRO = 1 |
Ondřej Čertík | a43307c | 2013-02-06 20:20:42 | [diff] [blame] | 60 | ISRELEASED = True |
Ondrej Certik | 697316a | 2013-04-07 05:05:59 | [diff] [blame] | 61 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 62 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 63 | # Return the git revision as a string |
| 64 | def git_version(): |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 65 | def _minimal_ext_cmd(cmd): |
| 66 | # construct minimal environment |
| 67 | env = {} |
David Cournapeau | 5032b52 | 2009-09-18 10:10:39 | [diff] [blame] | 68 | for k in ['SYSTEMROOT', 'PATH']: |
| 69 | v = os.environ.get(k) |
| 70 | if v is not None: |
| 71 | env[k] = v |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 72 | # LANGUAGE is used on win32 |
| 73 | env['LANGUAGE'] = 'C' |
| 74 | env['LANG'] = 'C' |
| 75 | env['LC_ALL'] = 'C' |
| 76 | out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] |
| 77 | return out |
| 78 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 79 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 80 | out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
Pauli Virtanen | d1a184c | 2010-11-15 01:00:06 | [diff] [blame] | 81 | GIT_REVISION = out.strip().decode('ascii') |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 82 | except OSError: |
Scott Sinclair | d5ed744 | 2010-11-10 05:19:15 | [diff] [blame] | 83 | GIT_REVISION = "Unknown" |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 84 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 85 | return GIT_REVISION |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 86 | |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 87 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
| 88 | # update it when the contents of directories change. |
| 89 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
| 90 | |
| 91 | # This is a bit hackish: we are setting a global variable so that the main |
| 92 | # numpy __init__ can detect if it is being loaded by the setup routine, to |
| 93 | # avoid attempting to load components that aren't built yet. While ugly, it's |
| 94 | # a lot more robust than what was previously being used. |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 95 | builtins.__NUMPY_SETUP__ = True |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 96 | |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 97 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 98 | def write_version_py(filename='numpy/version.py'): |
| 99 | cnt = """ |
David Cournapeau | 914bb15 | 2009-03-27 11:15:47 | [diff] [blame] | 100 | # THIS FILE IS GENERATED FROM NUMPY SETUP.PY |
Scott Sinclair | 0502dab | 2010-11-10 05:24:57 | [diff] [blame] | 101 | short_version = '%(version)s' |
| 102 | version = '%(version)s' |
| 103 | full_version = '%(full_version)s' |
| 104 | git_revision = '%(git_revision)s' |
| 105 | release = %(isrelease)s |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 106 | |
| 107 | if not release: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 108 | version = full_version |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 109 | """ |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 110 | # Adding the git rev number needs to be done inside write_version_py(), |
| 111 | # otherwise the import of numpy.version messes up the build under Python 3. |
| 112 | FULLVERSION = VERSION |
| 113 | if os.path.exists('.git'): |
| 114 | GIT_REVISION = git_version() |
| 115 | elif os.path.exists('numpy/version.py'): |
| 116 | # must be a source distribution, use existing version file |
Ralf Gommers | cd6d53f | 2011-04-17 14:04:11 | [diff] [blame] | 117 | try: |
| 118 | from numpy.version import git_revision as GIT_REVISION |
| 119 | except ImportError: |
| 120 | raise ImportError("Unable to import git_revision. Try removing " \ |
| 121 | "numpy/version.py and the build directory " \ |
| 122 | "before building.") |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 123 | else: |
| 124 | GIT_REVISION = "Unknown" |
| 125 | |
| 126 | if not ISRELEASED: |
| 127 | FULLVERSION += '.dev-' + GIT_REVISION[:7] |
| 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 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 138 | def configuration(parent_package='',top_path=None): |
| 139 | from numpy.distutils.misc_util import Configuration |
| 140 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 141 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 142 | config.set_options(ignore_setup_xxx_py=True, |
| 143 | assume_default_configuration=True, |
| 144 | delegate_options_to_subpackages=True, |
| 145 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 146 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 147 | config.add_subpackage('numpy') |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 148 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 149 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 150 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 151 | return config |
| 152 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 153 | def setup_package(): |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 154 | |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 155 | # Perform 2to3 if needed |
| 156 | local_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 157 | src_path = local_path |
| 158 | |
| 159 | if sys.version_info[0] == 3: |
| 160 | src_path = os.path.join(local_path, 'build', 'py3k') |
| 161 | sys.path.insert(0, os.path.join(local_path, 'tools')) |
| 162 | import py3tool |
| 163 | print("Converting to Python3 via 2to3...") |
| 164 | py3tool.sync_2to3('numpy', os.path.join(src_path, 'numpy')) |
| 165 | |
| 166 | site_cfg = os.path.join(local_path, 'site.cfg') |
| 167 | if os.path.isfile(site_cfg): |
| 168 | shutil.copy(site_cfg, src_path) |
| 169 | |
Ralf Gommers | dba98cc | 2011-08-02 15:34:38 | [diff] [blame] | 170 | # Ugly hack to make pip work with Python 3, see #1857. |
| 171 | # Explanation: pip messes with __file__ which interacts badly with the |
| 172 | # change in directory due to the 2to3 conversion. Therefore we restore |
| 173 | # __file__ to what it would have been otherwise. |
| 174 | global __file__ |
| 175 | __file__ = os.path.join(os.curdir, os.path.basename(__file__)) |
| 176 | if '--egg-base' in sys.argv: |
| 177 | # Change pip-egg-info entry to absolute path, so pip can find it |
| 178 | # after changing directory. |
| 179 | idx = sys.argv.index('--egg-base') |
| 180 | if sys.argv[idx + 1] == 'pip-egg-info': |
| 181 | sys.argv[idx + 1] = os.path.join(local_path, 'pip-egg-info') |
| 182 | |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 183 | old_path = os.getcwd() |
| 184 | os.chdir(src_path) |
| 185 | sys.path.insert(0, src_path) |
| 186 | |
Pauli Virtanen | 0131218 | 2010-11-23 16:50:54 | [diff] [blame] | 187 | # Rewrite the version file everytime |
| 188 | write_version_py() |
| 189 | |
| 190 | # Run build |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 191 | from numpy.distutils.core import setup |
| 192 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 193 | try: |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 194 | setup( |
David Cournapeau | c253b72 | 2009-03-27 11:15:22 | [diff] [blame] | 195 | name=NAME, |
| 196 | maintainer=MAINTAINER, |
| 197 | maintainer_email=MAINTAINER_EMAIL, |
| 198 | description=DESCRIPTION, |
| 199 | long_description=LONG_DESCRIPTION, |
| 200 | url=URL, |
| 201 | download_url=DOWNLOAD_URL, |
| 202 | license=LICENSE, |
| 203 | classifiers=CLASSIFIERS, |
| 204 | author=AUTHOR, |
| 205 | author_email=AUTHOR_EMAIL, |
| 206 | platforms=PLATFORMS, |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 207 | configuration=configuration ) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 208 | finally: |
| 209 | del sys.path[0] |
| 210 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 211 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 212 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 213 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 214 | setup_package() |