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