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 | |
Matthew Brett | be575d5 | 2016-03-07 20:52:08 | [diff] [blame] | 15 | All numpy wheels distributed from pypi are BSD licensed. |
| 16 | |
| 17 | Windows wheels are linked against the ATLAS BLAS / LAPACK library, restricted |
| 18 | to SSE2 instructions, so may not give optimal linear algebra performance for |
| 19 | your machine. See http://docs.scipy.org/doc/numpy/user/install.html for |
| 20 | alternatives. |
| 21 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 22 | """ |
Charles Harris | bb726ca | 2013-04-06 19:25:26 | [diff] [blame] | 23 | from __future__ import division, print_function |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 24 | |
David Sanders | 922442f | 2015-10-19 20:03:34 | [diff] [blame] | 25 | DOCLINES = (__doc__ or '').split("\n") |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 26 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 27 | import os |
| 28 | import sys |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 29 | import subprocess |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 30 | import textwrap |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 31 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 32 | |
Joseph Fox-Rabinovitz | 21d2fb7 | 2016-04-12 05:34:39 | [diff] [blame] | 33 | if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 4): |
Charles Harris | 3ce03de | 2016-04-09 15:18:22 | [diff] [blame] | 34 | raise RuntimeError("Python version 2.7 or >= 3.4 required.") |
Charles Harris | 28eadc0 | 2013-07-11 18:08:49 | [diff] [blame] | 35 | |
Charles Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 36 | if sys.version_info[0] >= 3: |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 37 | import builtins |
Charles Harris | 09a52ed | 2013-03-28 23:13:53 | [diff] [blame] | 38 | else: |
| 39 | import __builtin__ as builtins |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 40 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 41 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 42 | CLASSIFIERS = """\ |
Robert Kern | 19da971 | 2008-06-18 22:53:44 | [diff] [blame] | 43 | Development Status :: 5 - Production/Stable |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 44 | Intended Audience :: Science/Research |
| 45 | Intended Audience :: Developers |
| 46 | License :: OSI Approved |
| 47 | Programming Language :: C |
| 48 | Programming Language :: Python |
Alex Willmer | 193668a | 2015-08-05 09:29:39 | [diff] [blame] | 49 | Programming Language :: Python :: 2 |
Alex Willmer | 193668a | 2015-08-05 09:29:39 | [diff] [blame] | 50 | Programming Language :: Python :: 2.7 |
rgommers | cdac120 | 2011-01-25 14:02:40 | [diff] [blame] | 51 | Programming Language :: Python :: 3 |
Alex Willmer | 193668a | 2015-08-05 09:29:39 | [diff] [blame] | 52 | Programming Language :: Python :: 3.4 |
| 53 | Programming Language :: Python :: 3.5 |
Charles Harris | b33a5ee | 2016-11-05 19:48:30 | [diff] [blame] | 54 | Programming Language :: Python :: 3.6 |
Ralf Gommers | a5e8037 | 2018-06-28 02:26:19 | [diff] [blame] | 55 | Programming Language :: Python :: 3.7 |
Alex Willmer | 193668a | 2015-08-05 09:29:39 | [diff] [blame] | 56 | Programming Language :: Python :: Implementation :: CPython |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 57 | Topic :: Software Development |
| 58 | Topic :: Scientific/Engineering |
| 59 | Operating System :: Microsoft :: Windows |
| 60 | Operating System :: POSIX |
| 61 | Operating System :: Unix |
| 62 | Operating System :: MacOS |
| 63 | """ |
| 64 | |
Ralf Gommers | 58c1bf7 | 2012-11-05 19:47:23 | [diff] [blame] | 65 | MAJOR = 1 |
Charles Harris | 7978dd4 | 2017-12-11 23:26:35 | [diff] [blame] | 66 | MINOR = 15 |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 67 | MICRO = 0 |
Charles Harris | ccfbcc1 | 2018-07-23 12:56:33 | [diff] [blame] | 68 | ISRELEASED = True |
Charles Harris | 9f5f168 | 2018-07-09 20:46:15 | [diff] [blame] | 69 | VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
Stefan van der Walt | b9a22d7 | 2009-06-17 14:28:03 | [diff] [blame] | 70 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 71 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 72 | # Return the git revision as a string |
| 73 | def git_version(): |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 74 | def _minimal_ext_cmd(cmd): |
| 75 | # construct minimal environment |
| 76 | env = {} |
Robert Kern | c0be995 | 2017-03-09 00:38:54 | [diff] [blame] | 77 | for k in ['SYSTEMROOT', 'PATH', 'HOME']: |
David Cournapeau | 5032b52 | 2009-09-18 10:10:39 | [diff] [blame] | 78 | v = os.environ.get(k) |
| 79 | if v is not None: |
| 80 | env[k] = v |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 81 | # LANGUAGE is used on win32 |
| 82 | env['LANGUAGE'] = 'C' |
| 83 | env['LANG'] = 'C' |
| 84 | env['LC_ALL'] = 'C' |
Charles Harris | 054d93a | 2017-11-29 18:53:21 | [diff] [blame] | 85 | out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0] |
David Cournapeau | 44d92ec | 2009-06-01 05:43:16 | [diff] [blame] | 86 | return out |
| 87 | |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 88 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 89 | out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
Pauli Virtanen | d1a184c | 2010-11-15 01:00:06 | [diff] [blame] | 90 | GIT_REVISION = out.strip().decode('ascii') |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 91 | except OSError: |
Scott Sinclair | d5ed744 | 2010-11-10 05:19:15 | [diff] [blame] | 92 | GIT_REVISION = "Unknown" |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 93 | |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 94 | return GIT_REVISION |
David Cournapeau | 5e041cb | 2009-03-27 11:16:01 | [diff] [blame] | 95 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 96 | # BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be |
| 97 | # properly updated when the contents of directories change (true for distutils, |
| 98 | # not sure about setuptools). |
| 99 | if os.path.exists('MANIFEST'): |
| 100 | os.remove('MANIFEST') |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 101 | |
| 102 | # This is a bit hackish: we are setting a global variable so that the main |
| 103 | # numpy __init__ can detect if it is being loaded by the setup routine, to |
| 104 | # avoid attempting to load components that aren't built yet. While ugly, it's |
| 105 | # a lot more robust than what was previously being used. |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 106 | builtins.__NUMPY_SETUP__ = True |
David Cournapeau | 5bb1aa5 | 2009-03-27 16:39:01 | [diff] [blame] | 107 | |
rgommers | 13212a5 | 2011-03-03 16:13:08 | [diff] [blame] | 108 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 109 | def get_version_info(): |
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: |
Ã…smund Hjulstad | e15f292 | 2015-02-10 17:07:55 | [diff] [blame] | 127 | FULLVERSION += '.dev0+' + GIT_REVISION[:7] |
Ralf Gommers | 87e12c1 | 2011-03-24 15:30:06 | [diff] [blame] | 128 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 129 | return FULLVERSION, GIT_REVISION |
| 130 | |
| 131 | |
| 132 | def write_version_py(filename='numpy/version.py'): |
| 133 | cnt = """ |
| 134 | # THIS FILE IS GENERATED FROM NUMPY SETUP.PY |
Ralf Gommers | 105a498 | 2015-12-29 20:58:36 | [diff] [blame] | 135 | # |
| 136 | # To compare versions robustly, use `numpy.lib.NumpyVersion` |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 137 | short_version = '%(version)s' |
| 138 | version = '%(version)s' |
| 139 | full_version = '%(full_version)s' |
| 140 | git_revision = '%(git_revision)s' |
| 141 | release = %(isrelease)s |
| 142 | |
| 143 | if not release: |
| 144 | version = full_version |
| 145 | """ |
| 146 | FULLVERSION, GIT_REVISION = get_version_info() |
| 147 | |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 148 | a = open(filename, 'w') |
| 149 | try: |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 150 | a.write(cnt % {'version': VERSION, |
Charles Harris | 054d93a | 2017-11-29 18:53:21 | [diff] [blame] | 151 | 'full_version': FULLVERSION, |
| 152 | 'git_revision': GIT_REVISION, |
Scott Sinclair | 58e6360 | 2010-11-09 15:09:15 | [diff] [blame] | 153 | 'isrelease': str(ISRELEASED)}) |
David Cournapeau | a2ac985 | 2009-03-27 11:15:36 | [diff] [blame] | 154 | finally: |
| 155 | a.close() |
| 156 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 157 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 158 | def configuration(parent_package='',top_path=None): |
| 159 | from numpy.distutils.misc_util import Configuration |
| 160 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 161 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 162 | config.set_options(ignore_setup_xxx_py=True, |
| 163 | assume_default_configuration=True, |
| 164 | delegate_options_to_subpackages=True, |
| 165 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 166 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 167 | config.add_subpackage('numpy') |
Charles Harris | 054d93a | 2017-11-29 18:53:21 | [diff] [blame] | 168 | config.add_data_files(('numpy', 'LICENSE.txt')) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 169 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 170 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 171 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 172 | return config |
| 173 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 174 | |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 175 | def check_submodules(): |
| 176 | """ verify that the submodules are checked out and clean |
| 177 | use `git submodule update --init`; on failure |
| 178 | """ |
| 179 | if not os.path.exists('.git'): |
| 180 | return |
| 181 | with open('.gitmodules') as f: |
| 182 | for l in f: |
| 183 | if 'path' in l: |
| 184 | p = l.split('=')[-1].strip() |
| 185 | if not os.path.exists(p): |
| 186 | raise ValueError('Submodule %s missing' % p) |
| 187 | |
| 188 | |
| 189 | proc = subprocess.Popen(['git', 'submodule', 'status'], |
| 190 | stdout=subprocess.PIPE) |
| 191 | status, _ = proc.communicate() |
| 192 | status = status.decode("ascii", "replace") |
| 193 | for line in status.splitlines(): |
| 194 | if line.startswith('-') or line.startswith('+'): |
| 195 | raise ValueError('Submodule not clean: %s' % line) |
| 196 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 197 | |
Ralf Gommers | 6770f98 | 2016-01-27 20:34:28 | [diff] [blame] | 198 | from distutils.command.sdist import sdist |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 199 | class sdist_checked(sdist): |
| 200 | """ check submodules on sdist to prevent incomplete tarballs """ |
| 201 | def run(self): |
| 202 | check_submodules() |
| 203 | sdist.run(self) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 204 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 205 | |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 206 | def generate_cython(): |
| 207 | cwd = os.path.abspath(os.path.dirname(__file__)) |
| 208 | print("Cythonizing sources") |
| 209 | p = subprocess.call([sys.executable, |
| 210 | os.path.join(cwd, 'tools', 'cythonize.py'), |
| 211 | 'numpy/random'], |
| 212 | cwd=cwd) |
| 213 | if p != 0: |
| 214 | raise RuntimeError("Running cythonize failed!") |
| 215 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 216 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 217 | def parse_setuppy_commands(): |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 218 | """Check the commands and respond appropriately. Disable broken commands. |
| 219 | |
| 220 | Return a boolean value for whether or not to run the build or not (avoid |
| 221 | parsing Cython and template files if False). |
| 222 | """ |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 223 | args = sys.argv[1:] |
| 224 | |
| 225 | if not args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 226 | # User forgot to give an argument probably, let setuptools handle that. |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 227 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 228 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 229 | info_commands = ['--help-commands', '--name', '--version', '-V', |
| 230 | '--fullname', '--author', '--author-email', |
| 231 | '--maintainer', '--maintainer-email', '--contact', |
| 232 | '--contact-email', '--url', '--license', '--description', |
| 233 | '--long-description', '--platforms', '--classifiers', |
| 234 | '--keywords', '--provides', '--requires', '--obsoletes'] |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 235 | |
| 236 | for command in info_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 237 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 238 | return False |
| 239 | |
| 240 | # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work |
| 241 | # fine as they are, but are usually used together with one of the commands |
| 242 | # below and not standalone. Hence they're not added to good_commands. |
| 243 | good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py', |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 244 | 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm', |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 245 | 'bdist_wininst', 'bdist_msi', 'bdist_mpkg') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 246 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 247 | for command in good_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 248 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 249 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 250 | |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 251 | # The following commands are supported, but we need to show more |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 252 | # useful messages to the user |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 253 | if 'install' in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 254 | print(textwrap.dedent(""" |
| 255 | Note: if you need reliable uninstall behavior, then install |
| 256 | with pip instead of using `setup.py install`: |
| 257 | |
| 258 | - `pip install .` (from a git repo or downloaded source |
| 259 | release) |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 260 | - `pip install numpy` (last NumPy release on PyPi) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 261 | |
| 262 | """)) |
| 263 | return True |
| 264 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 265 | if '--help' in args or '-h' in sys.argv[1]: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 266 | print(textwrap.dedent(""" |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 267 | NumPy-specific help |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 268 | ------------------- |
| 269 | |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 270 | To install NumPy from here with reliable uninstall, we recommend |
| 271 | that you use `pip install .`. To install the latest NumPy release |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 272 | from PyPi, use `pip install numpy`. |
| 273 | |
| 274 | For help with build/installation issues, please ask on the |
| 275 | numpy-discussion mailing list. If you are sure that you have run |
| 276 | into a bug, please report it at https://github.com/numpy/numpy/issues. |
| 277 | |
| 278 | Setuptools commands help |
| 279 | ------------------------ |
| 280 | """)) |
| 281 | return False |
| 282 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 283 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 284 | # The following commands aren't supported. They can only be executed when |
| 285 | # the user explicitly adds a --force command-line argument. |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 286 | bad_commands = dict( |
| 287 | test=""" |
| 288 | `setup.py test` is not supported. Use one of the following |
| 289 | instead: |
| 290 | |
| 291 | - `python runtests.py` (to build and test) |
| 292 | - `python runtests.py --no-build` (to test installed numpy) |
| 293 | - `>>> numpy.test()` (run tests for installed numpy |
| 294 | from within an interpreter) |
| 295 | """, |
| 296 | upload=""" |
| 297 | `setup.py upload` is not supported, because it's insecure. |
| 298 | Instead, build what you want to upload and upload those files |
| 299 | with `twine upload -s <filenames>` instead. |
| 300 | """, |
| 301 | upload_docs="`setup.py upload_docs` is not supported", |
| 302 | easy_install="`setup.py easy_install` is not supported", |
| 303 | clean=""" |
| 304 | `setup.py clean` is not supported, use one of the following instead: |
| 305 | |
| 306 | - `git clean -xdf` (cleans all files) |
| 307 | - `git clean -Xdf` (cleans all versioned files, doesn't touch |
| 308 | files that aren't checked into the git repo) |
| 309 | """, |
| 310 | check="`setup.py check` is not supported", |
| 311 | register="`setup.py register` is not supported", |
| 312 | bdist_dumb="`setup.py bdist_dumb` is not supported", |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 313 | bdist="`setup.py bdist` is not supported", |
| 314 | build_sphinx=""" |
| 315 | `setup.py build_sphinx` is not supported, use the |
| 316 | Makefile under doc/""", |
| 317 | flake8="`setup.py flake8` is not supported, use flake8 standalone", |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 318 | ) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 319 | bad_commands['nosetests'] = bad_commands['test'] |
Luca Mussi | 69d2cc8 | 2016-04-07 11:24:49 | [diff] [blame] | 320 | for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb', |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 321 | 'register', 'check', 'install_data', 'install_headers', |
| 322 | 'install_lib', 'install_scripts', ): |
| 323 | bad_commands[command] = "`setup.py %s` is not supported" % command |
| 324 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 325 | for command in bad_commands.keys(): |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 326 | if command in args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 327 | print(textwrap.dedent(bad_commands[command]) + |
| 328 | "\nAdd `--force` to your command to use it anyway if you " |
| 329 | "must (unsupported).\n") |
| 330 | sys.exit(1) |
| 331 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 332 | # Commands that do more than print info, but also don't need Cython and |
| 333 | # template parsing. |
| 334 | other_commands = ['egg_info', 'install_egg_info', 'rotate'] |
| 335 | for command in other_commands: |
| 336 | if command in args: |
| 337 | return False |
| 338 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 339 | # If we got here, we didn't detect what setup.py command was given |
| 340 | import warnings |
| 341 | warnings.warn("Unrecognized setuptools command, proceeding with " |
Sebastian Berg | 7884a8c | 2016-01-23 14:58:58 | [diff] [blame] | 342 | "generating Cython sources and expanding templates", stacklevel=2) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 343 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 344 | |
| 345 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 346 | def setup_package(): |
Charles Harris | b4180e3 | 2013-04-22 03:26:44 | [diff] [blame] | 347 | src_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 348 | old_path = os.getcwd() |
| 349 | os.chdir(src_path) |
| 350 | sys.path.insert(0, src_path) |
| 351 | |
Pauli Virtanen | 0131218 | 2010-11-23 16:50:54 | [diff] [blame] | 352 | # Rewrite the version file everytime |
| 353 | write_version_py() |
| 354 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 355 | metadata = dict( |
| 356 | name = 'numpy', |
| 357 | maintainer = "NumPy Developers", |
Ralf Gommers | 46f7dca | 2017-03-26 07:52:46 | [diff] [blame] | 358 | maintainer_email = "numpy-discussion@python.org", |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 359 | description = DOCLINES[0], |
| 360 | long_description = "\n".join(DOCLINES[2:]), |
| 361 | url = "http://www.numpy.org", |
| 362 | author = "Travis E. Oliphant et al.", |
Charles Harris | ec5985d | 2018-01-10 18:00:11 | [diff] [blame] | 363 | download_url = "https://pypi.python.org/pypi/numpy", |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 364 | license = 'BSD', |
| 365 | classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], |
| 366 | platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], |
| 367 | test_suite='nose.collector', |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 368 | cmdclass={"sdist": sdist_checked}, |
Ralf Gommers | 343de6f | 2017-04-15 21:29:55 | [diff] [blame] | 369 | python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*', |
Nathaniel J. Smith | f46e716 | 2018-01-23 08:02:04 | [diff] [blame] | 370 | zip_safe=False, |
xoviat | bb7b126 | 2018-01-30 23:25:12 | [diff] [blame] | 371 | entry_points={ |
| 372 | 'console_scripts': [ |
| 373 | 'f2py = numpy.f2py.__main__:main', |
| 374 | 'conv-template = numpy.distutils.conv_template:main', |
xoviat | a2ad5f1 | 2018-02-14 23:50:57 | [diff] [blame] | 375 | 'from-template = numpy.distutils.from_template:main', |
xoviat | bb7b126 | 2018-01-30 23:25:12 | [diff] [blame] | 376 | ] |
| 377 | }, |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 378 | ) |
| 379 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 380 | if "--force" in sys.argv: |
| 381 | run_build = True |
Ralf Gommers | 20c3c2a | 2017-06-20 10:09:40 | [diff] [blame] | 382 | sys.argv.remove('--force') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 383 | else: |
| 384 | # Raise errors for unsupported commands, improve help output, etc. |
| 385 | run_build = parse_setuppy_commands() |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 386 | |
| 387 | from setuptools import setup |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 388 | if run_build: |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 389 | from numpy.distutils.core import setup |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 390 | cwd = os.path.abspath(os.path.dirname(__file__)) |
| 391 | if not os.path.exists(os.path.join(cwd, 'PKG-INFO')): |
| 392 | # Generate Cython sources, unless building from source release |
| 393 | generate_cython() |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 394 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 395 | metadata['configuration'] = configuration |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 396 | else: |
| 397 | # Version number is added to metadata inside configuration() if build |
| 398 | # is run. |
| 399 | metadata['version'] = get_version_info()[0] |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 400 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 401 | try: |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 402 | setup(**metadata) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 403 | finally: |
| 404 | del sys.path[0] |
| 405 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 406 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 407 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 408 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 409 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 410 | setup_package() |
Ralf Gommers | bbee747 | 2016-08-21 05:23:35 | [diff] [blame] | 411 | # This may avoid problems where numpy is installed via ``*_requires`` by |
| 412 | # setuptools, the global namespace isn't reset properly, and then numpy is |
| 413 | # imported later (which will then fail to load numpy extension modules). |
| 414 | # See gh-7956 for details |
| 415 | del builtins.__NUMPY_SETUP__ |