blob: 92e0c7fc6b8c689d19d2e56e7c51ab3c593b54dc [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.
14"""
15
16DOCLINES = __doc__.split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3117
Pearu Petersone8fa0132003-03-07 18:08:2818import os
Pauli Virtanen68159432009-12-06 11:56:1819import shutil
Pearu Petersone8fa0132003-03-07 18:08:2820import sys
David Cournapeau5864bd22009-03-27 16:39:3421import re
David Cournapeau5623a7c2009-04-02 16:21:3022import subprocess
Pearu Petersonc415fd12002-11-18 22:39:3123
David Cournapeau2b517692009-12-03 15:53:2924if sys.version_info[0] < 3:
25 import __builtin__ as builtins
26else:
27 import builtins
28
Travis Oliphantda9c6da2006-01-04 17:31:0729CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4430Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0731Intended Audience :: Science/Research
32Intended Audience :: Developers
33License :: OSI Approved
34Programming Language :: C
35Programming Language :: Python
rgommerscdac1202011-01-25 14:02:4036Programming Language :: Python :: 3
Travis Oliphantda9c6da2006-01-04 17:31:0737Topic :: Software Development
38Topic :: Scientific/Engineering
39Operating System :: Microsoft :: Windows
40Operating System :: POSIX
41Operating System :: Unix
42Operating System :: MacOS
43"""
44
David Cournapeaucc9a4462009-03-27 11:16:1345NAME = 'numpy'
46MAINTAINER = "NumPy Developers"
47MAINTAINER_EMAIL = "numpy-discussion@scipy.org"
48DESCRIPTION = DOCLINES[0]
49LONG_DESCRIPTION = "\n".join(DOCLINES[2:])
Sandro Tosid5d20492012-12-30 11:12:1850URL = "http://www.numpy.org"
Ralf Gommers98ca13d2012-11-05 19:47:2351DOWNLOAD_URL = "http://sourceforge.net/projects/numpy/files/NumPy/"
David Cournapeaucc9a4462009-03-27 11:16:1352LICENSE = 'BSD'
53CLASSIFIERS = filter(None, CLASSIFIERS.split('\n'))
Ondřej Čertík1a5afd92012-11-14 23:00:2954AUTHOR = "Travis E. Oliphant et al."
Travis E. Oliphantf93774d2012-07-18 06:44:1455AUTHOR_EMAIL = "numpy-discussion@scipy.org"
David Cournapeaucc9a4462009-03-27 11:16:1356PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
Ralf Gommers28ffac72012-08-21 06:20:5657MAJOR = 1
58MINOR = 7
Ondrej Certik21bda0e2013-03-24 18:47:5959MICRO = 1
Ondřej Čertíka43307c2013-02-06 20:20:4260ISRELEASED = True
Ondrej Certik697316a2013-04-07 05:05:5961VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0362
Scott Sinclair58e63602010-11-09 15:09:1563# Return the git revision as a string
64def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1665 def _minimal_ext_cmd(cmd):
66 # construct minimal environment
67 env = {}
David Cournapeau5032b522009-09-18 10:10:3968 for k in ['SYSTEMROOT', 'PATH']:
69 v = os.environ.get(k)
70 if v is not None:
71 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1672 # 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 Cournapeau5623a7c2009-04-02 16:21:3079 try:
Scott Sinclair58e63602010-11-09 15:09:1580 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0681 GIT_REVISION = out.strip().decode('ascii')
David Cournapeau5623a7c2009-04-02 16:21:3082 except OSError:
Scott Sinclaird5ed7442010-11-10 05:19:1583 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0184
Scott Sinclair58e63602010-11-09 15:09:1585 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:0186
David Cournapeau5bb1aa52009-03-27 16:39:0187# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
88# update it when the contents of directories change.
89if 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 Cournapeau2b517692009-12-03 15:53:2995builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:0196
rgommers13212a52011-03-03 16:13:0897
David Cournapeaua2ac9852009-03-27 11:15:3698def write_version_py(filename='numpy/version.py'):
99 cnt = """
David Cournapeau914bb152009-03-27 11:15:47100# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
Scott Sinclair0502dab2010-11-10 05:24:57101short_version = '%(version)s'
102version = '%(version)s'
103full_version = '%(full_version)s'
104git_revision = '%(git_revision)s'
105release = %(isrelease)s
David Cournapeaua2ac9852009-03-27 11:15:36106
107if not release:
Scott Sinclair58e63602010-11-09 15:09:15108 version = full_version
David Cournapeaua2ac9852009-03-27 11:15:36109"""
Ralf Gommers87e12c12011-03-24 15:30:06110 # 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 Gommerscd6d53f2011-04-17 14:04:11117 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 Gommers87e12c12011-03-24 15:30:06123 else:
124 GIT_REVISION = "Unknown"
125
126 if not ISRELEASED:
127 FULLVERSION += '.dev-' + GIT_REVISION[:7]
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
Pearu Peterson471196b2006-03-31 08:59:36138def configuration(parent_package='',top_path=None):
139 from numpy.distutils.misc_util import Configuration
140
Pearu Peterson17d7cfe2006-04-04 12:26:14141 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36142 config.set_options(ignore_setup_xxx_py=True,
143 assume_default_configuration=True,
144 delegate_options_to_subpackages=True,
145 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18146
Pearu Peterson471196b2006-03-31 08:59:36147 config.add_subpackage('numpy')
Jarrod Millman0b77f0e2007-10-29 14:58:18148
Pearu Peterson17d7cfe2006-04-04 12:26:14149 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01150
Pearu Peterson471196b2006-03-31 08:59:36151 return config
152
Pearu Petersone8fa0132003-03-07 18:08:28153def setup_package():
Travis Oliphant14db4192005-09-14 22:08:46154
Pauli Virtanen68159432009-12-06 11:56:18155 # 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 Gommersdba98cc2011-08-02 15:34:38170 # 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 Virtanen68159432009-12-06 11:56:18183 old_path = os.getcwd()
184 os.chdir(src_path)
185 sys.path.insert(0, src_path)
186
Pauli Virtanen01312182010-11-23 16:50:54187 # Rewrite the version file everytime
188 write_version_py()
189
190 # Run build
Pauli Virtanen68159432009-12-06 11:56:18191 from numpy.distutils.core import setup
192
Pearu Petersone8fa0132003-03-07 18:08:28193 try:
Pearu Peterson17d7cfe2006-04-04 12:26:14194 setup(
David Cournapeauc253b722009-03-27 11:15:22195 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 Peterson17d7cfe2006-04-04 12:26:14207 configuration=configuration )
Pearu Petersone8fa0132003-03-07 18:08:28208 finally:
209 del sys.path[0]
210 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46211 return
Pearu Petersonc415fd12002-11-18 22:39:31212
Travis Oliphant14db4192005-09-14 22:08:46213if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28214 setup_package()