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 |
| 36 | Topic :: Software Development |
| 37 | Topic :: Scientific/Engineering |
| 38 | Operating System :: Microsoft :: Windows |
| 39 | Operating System :: POSIX |
| 40 | Operating System :: Unix |
| 41 | Operating System :: MacOS |
| 42 | """ |
| 43 | |
David Cournapeau | cc9a446 | 2009-03-27 11:16:13 | [diff] [blame] | 44 | NAME = 'numpy' |
| 45 | MAINTAINER = "NumPy Developers" |
| 46 | MAINTAINER_EMAIL = "numpy-discussion@scipy.org" |
| 47 | DESCRIPTION = DOCLINES[0] |
| 48 | LONG_DESCRIPTION = "\n".join(DOCLINES[2:]) |
| 49 | URL = "http://numpy.scipy.org" |
| 50 | DOWNLOAD_URL = "http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103" |
| 51 | LICENSE = 'BSD' |
| 52 | CLASSIFIERS = filter(None, CLASSIFIERS.split('\n')) |
| 53 | AUTHOR = "Travis E. Oliphant, et.al." |
| 54 | AUTHOR_EMAIL = "oliphant@enthought.com" |
| 55 | PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"] |
Pauli Virtanen | 99adb17 | 2010-07-17 18:40:50 | [diff] [blame] | 56 | MAJOR = 1 |
| 57 | MINOR = 5 |
rgommers | 97cb28e | 2010-10-17 06:33:01 | [diff] [blame] | 58 | MICRO = 1 |
rgommers | 3304791 | 2010-11-08 13:59:32 | [diff] [blame] | 59 | ISRELEASED = True |
rgommers | de969d7 | 2010-11-18 11:14:24 | [diff] [blame] | 60 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 61 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 62 | # Return the svn version as a string, raise a ValueError otherwise |
| 63 | def svn_version(): |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 64 | def _minimal_ext_cmd(cmd): |
| 65 | # construct minimal environment |
| 66 | env = {} |
David Cournapeau | 5032b52 | 2009-09-18 10:10:39 | [diff] [blame] | 67 | for k in ['SYSTEMROOT', 'PATH']: |
| 68 | v = os.environ.get(k) |
| 69 | if v is not None: |
| 70 | env[k] = v |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 71 | # LANGUAGE is used on win32 |
| 72 | env['LANGUAGE'] = 'C' |
| 73 | env['LANG'] = 'C' |
| 74 | env['LC_ALL'] = 'C' |
| 75 | out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] |
| 76 | return out |
| 77 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 78 | try: |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 79 | out = _minimal_ext_cmd(['svn', 'info']) |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 80 | except OSError: |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 81 | print(" --- Could not run svn info --- ") |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 82 | return "" |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 83 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 84 | r = re.compile('Revision: ([0-9]+)') |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 85 | svnver = "" |
Pauli Virtanen | ab391a9 | 2009-12-06 12:49:21 | [diff] [blame] | 86 | |
Pauli Virtanen | 3033a149c | 2009-12-06 13:00:47 | [diff] [blame] | 87 | out = out.decode() |
| 88 | |
| 89 | for line in out.split('\n'): |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 90 | m = r.match(line.strip()) |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 91 | if m: |
| 92 | svnver = m.group(1) |
David Cournapeau | 52fb78d | 2009-03-27 18:37:07 | [diff] [blame] | 93 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 94 | if not svnver: |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 95 | print("Error while parsing svn version") |
| 96 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 97 | return svnver |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 98 | |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 99 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
| 100 | # update it when the contents of directories change. |
| 101 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
| 102 | |
| 103 | # This is a bit hackish: we are setting a global variable so that the main |
| 104 | # numpy __init__ can detect if it is being loaded by the setup routine, to |
| 105 | # avoid attempting to load components that aren't built yet. While ugly, it's |
| 106 | # a lot more robust than what was previously being used. |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 107 | builtins.__NUMPY_SETUP__ = True |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 108 | |
David Cournapeau | d8fc4ad | 2009-04-01 16:18:55 | [diff] [blame] | 109 | FULLVERSION = VERSION |
| 110 | if not ISRELEASED: |
| 111 | FULLVERSION += '.dev' |
| 112 | # If in git or something, bypass the svn rev |
| 113 | if os.path.exists('.svn'): |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 114 | FULLVERSION += svn_version() |
David Cournapeau | d8fc4ad | 2009-04-01 16:18:55 | [diff] [blame] | 115 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 116 | def write_version_py(filename='numpy/version.py'): |
| 117 | cnt = """ |
David Cournapeau | 914bb15 | 2009-03-27 11:15:47 | [diff] [blame] | 118 | # THIS FILE IS GENERATED FROM NUMPY SETUP.PY |
David Cournapeau | a70c483 | 2009-03-27 12:07:37 | [diff] [blame] | 119 | short_version='%(version)s' |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 120 | version='%(version)s' |
| 121 | release=%(isrelease)s |
| 122 | |
| 123 | if not release: |
| 124 | version += '.dev' |
| 125 | import os |
| 126 | svn_version_file = os.path.join(os.path.dirname(__file__), |
| 127 | 'core','__svn_version__.py') |
| 128 | if os.path.isfile(svn_version_file): |
| 129 | import imp |
| 130 | svn = imp.load_module('numpy.core.__svn_version__', |
| 131 | open(svn_version_file), |
| 132 | svn_version_file, |
| 133 | ('.py','U',1)) |
| 134 | version += svn.version |
| 135 | """ |
| 136 | a = open(filename, 'w') |
| 137 | try: |
| 138 | a.write(cnt % {'version': VERSION, 'isrelease': str(ISRELEASED)}) |
| 139 | finally: |
| 140 | a.close() |
| 141 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 142 | def configuration(parent_package='',top_path=None): |
| 143 | from numpy.distutils.misc_util import Configuration |
| 144 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 145 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 146 | config.set_options(ignore_setup_xxx_py=True, |
| 147 | assume_default_configuration=True, |
| 148 | delegate_options_to_subpackages=True, |
| 149 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 150 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 151 | config.add_subpackage('numpy') |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 152 | |
Pearu Peterson | 7b76ca7 | 2007-06-05 18:54:28 | [diff] [blame] | 153 | config.add_data_files(('numpy','*.txt'), |
| 154 | ('numpy','COMPATIBILITY'), |
rgommers | c0440f8 | 2010-08-04 10:57:50 | [diff] [blame] | 155 | ('numpy','site.cfg.example'), |
| 156 | ('numpy/tools', 'tools/py3tool.py')) |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 157 | |
| 158 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 159 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 160 | return config |
| 161 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 162 | def setup_package(): |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 163 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 164 | # Rewrite the version file everytime |
| 165 | if os.path.exists('numpy/version.py'): os.remove('numpy/version.py') |
| 166 | write_version_py() |
| 167 | |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 168 | # Perform 2to3 if needed |
| 169 | local_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 170 | src_path = local_path |
| 171 | |
| 172 | if sys.version_info[0] == 3: |
| 173 | src_path = os.path.join(local_path, 'build', 'py3k') |
| 174 | sys.path.insert(0, os.path.join(local_path, 'tools')) |
| 175 | import py3tool |
| 176 | print("Converting to Python3 via 2to3...") |
| 177 | py3tool.sync_2to3('numpy', os.path.join(src_path, 'numpy')) |
| 178 | |
| 179 | site_cfg = os.path.join(local_path, 'site.cfg') |
| 180 | if os.path.isfile(site_cfg): |
| 181 | shutil.copy(site_cfg, src_path) |
| 182 | |
| 183 | # Run build |
| 184 | old_path = os.getcwd() |
| 185 | os.chdir(src_path) |
| 186 | sys.path.insert(0, src_path) |
| 187 | |
| 188 | from numpy.distutils.core import setup |
| 189 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 190 | try: |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 191 | setup( |
David Cournapeau | c253b72 | 2009-03-27 11:15:22 | [diff] [blame] | 192 | name=NAME, |
| 193 | maintainer=MAINTAINER, |
| 194 | maintainer_email=MAINTAINER_EMAIL, |
| 195 | description=DESCRIPTION, |
| 196 | long_description=LONG_DESCRIPTION, |
| 197 | url=URL, |
| 198 | download_url=DOWNLOAD_URL, |
| 199 | license=LICENSE, |
| 200 | classifiers=CLASSIFIERS, |
| 201 | author=AUTHOR, |
| 202 | author_email=AUTHOR_EMAIL, |
| 203 | platforms=PLATFORMS, |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 204 | configuration=configuration ) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 205 | finally: |
| 206 | del sys.path[0] |
| 207 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 208 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 209 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 210 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 211 | setup_package() |