Changqing Li | 583901a | 2020-03-04 08:22:40 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
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 | """ |
David Sanders | 922442f | 2015-10-19 20:03:34 | [diff] [blame] | 20 | DOCLINES = (__doc__ or '').split("\n") |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 21 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 22 | import os |
| 23 | import sys |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 24 | import subprocess |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 25 | import textwrap |
Hugo van Kemenade | f3a6b33 | 2020-10-04 09:09:52 | [diff] [blame] | 26 | import warnings |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 27 | import builtins |
Charles Harris | 9b29742 | 2021-05-25 19:35:42 | [diff] [blame] | 28 | import re |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 29 | |
Ralf Gommers | f66d5db | 2020-12-22 20:11:50 | [diff] [blame] | 30 | |
| 31 | # Python supported version checks. Keep right after stdlib imports to ensure we |
| 32 | # get a sensible error for older Python versions |
| 33 | if sys.version_info[:2] < (3, 7): |
| 34 | raise RuntimeError("Python version >= 3.7 required.") |
| 35 | |
| 36 | |
| 37 | import versioneer |
| 38 | |
| 39 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 40 | # This is a bit hackish: we are setting a global variable so that the main |
| 41 | # numpy __init__ can detect if it is being loaded by the setup routine, to |
| 42 | # avoid attempting to load components that aren't built yet. While ugly, it's |
| 43 | # a lot more robust than what was previously being used. |
| 44 | builtins.__NUMPY_SETUP__ = True |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 45 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 46 | # Needed for backwards code compatibility below and in some CI scripts. |
| 47 | # The version components are changed from ints to strings, but only VERSION |
| 48 | # seems to matter outside of this module and it was already a str. |
| 49 | FULLVERSION = versioneer.get_version() |
Charles Harris | 9b29742 | 2021-05-25 19:35:42 | [diff] [blame] | 50 | |
| 51 | # Capture the version string: |
| 52 | # 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0 |
| 53 | # 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0 |
| 54 | # 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0 |
| 55 | # 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0 |
| 56 | ISRELEASED = re.search(r'(dev|\+)', FULLVERSION) is None |
| 57 | MAJOR, MINOR, MICRO = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION).groups() |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 58 | VERSION = '{}.{}.{}'.format(MAJOR, MINOR, MICRO) |
| 59 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 60 | # The first version not in the `Programming Language :: Python :: ...` classifiers above |
| 61 | if sys.version_info >= (3, 10): |
Charles Harris | ca11e4e | 2020-12-12 15:17:01 | [diff] [blame] | 62 | fmt = "NumPy {} may not yet support Python {}.{}." |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 63 | warnings.warn( |
Charles Harris | ca11e4e | 2020-12-12 15:17:01 | [diff] [blame] | 64 | fmt.format(VERSION, *sys.version_info[:2]), |
| 65 | RuntimeWarning) |
| 66 | del fmt |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 67 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 68 | # BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be |
| 69 | # properly updated when the contents of directories change (true for distutils, |
| 70 | # not sure about setuptools). |
| 71 | if os.path.exists('MANIFEST'): |
| 72 | os.remove('MANIFEST') |
| 73 | |
| 74 | # We need to import setuptools here in order for it to persist in sys.modules. |
Charles Harris | fed2509 | 2020-12-10 18:58:47 | [diff] [blame] | 75 | # Its presence/absence is used in subclassing setup in numpy/distutils/core.py. |
| 76 | # However, we need to run the distutils version of sdist, so import that first |
| 77 | # so that it is in sys.modules |
| 78 | import numpy.distutils.command.sdist |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 79 | import setuptools |
| 80 | |
| 81 | # Initialize cmdclass from versioneer |
| 82 | from numpy.distutils.core import numpy_cmdclass |
| 83 | cmdclass = versioneer.get_cmdclass(numpy_cmdclass) |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 84 | |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 85 | CLASSIFIERS = """\ |
Robert Kern | 19da971 | 2008-06-18 22:53:44 | [diff] [blame] | 86 | Development Status :: 5 - Production/Stable |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 87 | Intended Audience :: Science/Research |
| 88 | Intended Audience :: Developers |
johnthagen | 5cb80d6 | 2020-10-22 12:43:03 | [diff] [blame] | 89 | License :: OSI Approved :: BSD License |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 90 | Programming Language :: C |
| 91 | Programming Language :: Python |
rgommers | cdac120 | 2011-01-25 14:02:40 | [diff] [blame] | 92 | Programming Language :: Python :: 3 |
Ralf Gommers | 943695b | 2018-06-28 02:26:19 | [diff] [blame] | 93 | Programming Language :: Python :: 3.7 |
Grzegorz Bokota | c861a36 | 2019-10-24 18:29:09 | [diff] [blame] | 94 | Programming Language :: Python :: 3.8 |
Hugo van Kemenade | 79a8e16 | 2020-10-04 11:59:53 | [diff] [blame] | 95 | Programming Language :: Python :: 3.9 |
Charles Harris | e3b5f1d | 2021-08-13 16:42:26 | [diff] [blame] | 96 | Programming Language :: Python :: 3.10 |
Jon Dufresne | 334201d | 2019-08-27 04:18:35 | [diff] [blame] | 97 | Programming Language :: Python :: 3 :: Only |
Alex Willmer | 193668a | 2015-08-05 09:29:39 | [diff] [blame] | 98 | Programming Language :: Python :: Implementation :: CPython |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 99 | Topic :: Software Development |
| 100 | Topic :: Scientific/Engineering |
Bas van Beek | e592c27 | 2020-10-04 13:10:42 | [diff] [blame] | 101 | Typing :: Typed |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 102 | Operating System :: Microsoft :: Windows |
| 103 | Operating System :: POSIX |
| 104 | Operating System :: Unix |
| 105 | Operating System :: MacOS |
| 106 | """ |
| 107 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 108 | |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 109 | def configuration(parent_package='', top_path=None): |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 110 | from numpy.distutils.misc_util import Configuration |
| 111 | |
Pearu Peterson | 17d7cfe | 2006-04-04 12:26:14 | [diff] [blame] | 112 | config = Configuration(None, parent_package, top_path) |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 113 | config.set_options(ignore_setup_xxx_py=True, |
| 114 | assume_default_configuration=True, |
| 115 | delegate_options_to_subpackages=True, |
| 116 | quiet=True) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 117 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 118 | config.add_subpackage('numpy') |
Charles Harris | 054d93a | 2017-11-29 18:53:21 | [diff] [blame] | 119 | config.add_data_files(('numpy', 'LICENSE.txt')) |
scoder | e1211b8 | 2020-08-05 04:28:30 | [diff] [blame] | 120 | config.add_data_files(('numpy', 'numpy/*.pxd')) |
Jarrod Millman | 0b77f0e | 2007-10-29 14:58:18 | [diff] [blame] | 121 | |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 122 | config.get_version('numpy/version.py') # sets config.version |
Travis Oliphant | 00a3587 | 2007-05-31 04:57:01 | [diff] [blame] | 123 | |
Pearu Peterson | 471196b | 2006-03-31 08:59:36 | [diff] [blame] | 124 | return config |
| 125 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 126 | |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 127 | def check_submodules(): |
| 128 | """ verify that the submodules are checked out and clean |
| 129 | use `git submodule update --init`; on failure |
| 130 | """ |
| 131 | if not os.path.exists('.git'): |
| 132 | return |
| 133 | with open('.gitmodules') as f: |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 134 | for line in f: |
| 135 | if 'path' in line: |
| 136 | p = line.split('=')[-1].strip() |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 137 | if not os.path.exists(p): |
Wojciech Rzadkowski | dabf31c | 2020-05-22 15:43:08 | [diff] [blame] | 138 | raise ValueError('Submodule {} missing'.format(p)) |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 139 | |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 140 | proc = subprocess.Popen(['git', 'submodule', 'status'], |
| 141 | stdout=subprocess.PIPE) |
| 142 | status, _ = proc.communicate() |
| 143 | status = status.decode("ascii", "replace") |
| 144 | for line in status.splitlines(): |
| 145 | if line.startswith('-') or line.startswith('+'): |
Wojciech Rzadkowski | dabf31c | 2020-05-22 15:43:08 | [diff] [blame] | 146 | raise ValueError('Submodule not clean: {}'.format(line)) |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 147 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 148 | |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 149 | class concat_license_files(): |
Ralf Gommers | 3341590 | 2019-05-07 09:00:50 | [diff] [blame] | 150 | """Merge LICENSE.txt and LICENSES_bundled.txt for sdist creation |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 151 | |
| 152 | Done this way to keep LICENSE.txt in repo as exact BSD 3-clause (see |
| 153 | gh-13447). This makes GitHub state correctly how NumPy is licensed. |
| 154 | """ |
| 155 | def __init__(self): |
| 156 | self.f1 = 'LICENSE.txt' |
Ralf Gommers | 3341590 | 2019-05-07 09:00:50 | [diff] [blame] | 157 | self.f2 = 'LICENSES_bundled.txt' |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 158 | |
| 159 | def __enter__(self): |
Ralf Gommers | 3341590 | 2019-05-07 09:00:50 | [diff] [blame] | 160 | """Concatenate files and remove LICENSES_bundled.txt""" |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 161 | with open(self.f1, 'r') as f1: |
| 162 | self.bsd_text = f1.read() |
| 163 | |
| 164 | with open(self.f1, 'a') as f1: |
| 165 | with open(self.f2, 'r') as f2: |
| 166 | self.bundled_text = f2.read() |
| 167 | f1.write('\n\n') |
| 168 | f1.write(self.bundled_text) |
| 169 | |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 170 | def __exit__(self, exception_type, exception_value, traceback): |
| 171 | """Restore content of both files""" |
| 172 | with open(self.f1, 'w') as f: |
| 173 | f.write(self.bsd_text) |
| 174 | |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 175 | |
Charles Harris | fed2509 | 2020-12-10 18:58:47 | [diff] [blame] | 176 | # Need to inherit from versioneer version of sdist to get the encoded |
| 177 | # version information. |
| 178 | class sdist_checked(cmdclass['sdist']): |
Julian Taylor | 4cd7274 | 2014-01-29 21:59:19 | [diff] [blame] | 179 | """ check submodules on sdist to prevent incomplete tarballs """ |
| 180 | def run(self): |
| 181 | check_submodules() |
Ralf Gommers | a08fb60 | 2019-05-03 14:44:23 | [diff] [blame] | 182 | with concat_license_files(): |
Charles Harris | fed2509 | 2020-12-10 18:58:47 | [diff] [blame] | 183 | super().run() |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 184 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 185 | |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 186 | def get_build_overrides(): |
| 187 | """ |
mattip | c2f9300 | 2020-01-05 15:00:30 | [diff] [blame] | 188 | Custom build commands to add `-std=c99` to compilation |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 189 | """ |
| 190 | from numpy.distutils.command.build_clib import build_clib |
| 191 | from numpy.distutils.command.build_ext import build_ext |
mattip | 57fb47c | 2020-07-28 03:39:16 | [diff] [blame] | 192 | from distutils.version import LooseVersion |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 193 | |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 194 | def _needs_gcc_c99_flag(obj): |
| 195 | if obj.compiler.compiler_type != 'unix': |
| 196 | return False |
| 197 | |
| 198 | cc = obj.compiler.compiler[0] |
| 199 | if "gcc" not in cc: |
| 200 | return False |
| 201 | |
| 202 | # will print something like '4.2.1\n' |
| 203 | out = subprocess.run([cc, '-dumpversion'], stdout=subprocess.PIPE, |
| 204 | stderr=subprocess.PIPE, universal_newlines=True) |
| 205 | # -std=c99 is default from this version on |
| 206 | if LooseVersion(out.stdout) >= LooseVersion('5.0'): |
| 207 | return False |
| 208 | return True |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 209 | |
| 210 | class new_build_clib(build_clib): |
| 211 | def build_a_library(self, build_info, lib_name, libraries): |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 212 | if _needs_gcc_c99_flag(self): |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 213 | args = build_info.get('extra_compiler_args') or [] |
mattip | c2f9300 | 2020-01-05 15:00:30 | [diff] [blame] | 214 | args.append('-std=c99') |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 215 | build_info['extra_compiler_args'] = args |
| 216 | build_clib.build_a_library(self, build_info, lib_name, libraries) |
| 217 | |
| 218 | class new_build_ext(build_ext): |
| 219 | def build_extension(self, ext): |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 220 | if _needs_gcc_c99_flag(self): |
mattip | c2f9300 | 2020-01-05 15:00:30 | [diff] [blame] | 221 | if '-std=c99' not in ext.extra_compile_args: |
| 222 | ext.extra_compile_args.append('-std=c99') |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 223 | build_ext.build_extension(self, ext) |
| 224 | return new_build_clib, new_build_ext |
| 225 | |
| 226 | |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 227 | def generate_cython(): |
| 228 | cwd = os.path.abspath(os.path.dirname(__file__)) |
| 229 | print("Cythonizing sources") |
mattip | 4e6a812 | 2019-05-23 04:54:47 | [diff] [blame] | 230 | for d in ('random',): |
mattip | fa8af41 | 2019-03-20 10:39:53 | [diff] [blame] | 231 | p = subprocess.call([sys.executable, |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 232 | os.path.join(cwd, 'tools', 'cythonize.py'), |
| 233 | 'numpy/{0}'.format(d)], |
| 234 | cwd=cwd) |
mattip | fa8af41 | 2019-03-20 10:39:53 | [diff] [blame] | 235 | if p != 0: |
| 236 | raise RuntimeError("Running cythonize failed!") |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 237 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 238 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 239 | def parse_setuppy_commands(): |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 240 | """Check the commands and respond appropriately. Disable broken commands. |
| 241 | |
| 242 | Return a boolean value for whether or not to run the build or not (avoid |
| 243 | parsing Cython and template files if False). |
| 244 | """ |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 245 | args = sys.argv[1:] |
| 246 | |
| 247 | if not args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 248 | # User forgot to give an argument probably, let setuptools handle that. |
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 | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 251 | info_commands = ['--help-commands', '--name', '--version', '-V', |
| 252 | '--fullname', '--author', '--author-email', |
| 253 | '--maintainer', '--maintainer-email', '--contact', |
| 254 | '--contact-email', '--url', '--license', '--description', |
| 255 | '--long-description', '--platforms', '--classifiers', |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 256 | '--keywords', '--provides', '--requires', '--obsoletes', |
| 257 | 'version',] |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 258 | |
| 259 | for command in info_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 260 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 261 | return False |
| 262 | |
| 263 | # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work |
| 264 | # fine as they are, but are usually used together with one of the commands |
| 265 | # below and not standalone. Hence they're not added to good_commands. |
| 266 | good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py', |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 267 | 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm', |
Ralf Gommers | 491d26b | 2021-01-27 21:48:58 | [diff] [blame] | 268 | 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src', |
| 269 | 'bdist_egg') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 270 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 271 | for command in good_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 272 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 273 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 274 | |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 275 | # The following commands are supported, but we need to show more |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 276 | # useful messages to the user |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 277 | if 'install' in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 278 | print(textwrap.dedent(""" |
| 279 | Note: if you need reliable uninstall behavior, then install |
| 280 | with pip instead of using `setup.py install`: |
| 281 | |
| 282 | - `pip install .` (from a git repo or downloaded source |
| 283 | release) |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 284 | - `pip install numpy` (last NumPy release on PyPi) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 285 | |
| 286 | """)) |
| 287 | return True |
| 288 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 289 | if '--help' in args or '-h' in sys.argv[1]: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 290 | print(textwrap.dedent(""" |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 291 | NumPy-specific help |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 292 | ------------------- |
| 293 | |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 294 | To install NumPy from here with reliable uninstall, we recommend |
| 295 | that you use `pip install .`. To install the latest NumPy release |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 296 | from PyPi, use `pip install numpy`. |
| 297 | |
| 298 | For help with build/installation issues, please ask on the |
| 299 | numpy-discussion mailing list. If you are sure that you have run |
| 300 | into a bug, please report it at https://github.com/numpy/numpy/issues. |
| 301 | |
| 302 | Setuptools commands help |
| 303 | ------------------------ |
| 304 | """)) |
| 305 | return False |
| 306 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 307 | # The following commands aren't supported. They can only be executed when |
| 308 | # the user explicitly adds a --force command-line argument. |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 309 | bad_commands = dict( |
| 310 | test=""" |
| 311 | `setup.py test` is not supported. Use one of the following |
| 312 | instead: |
| 313 | |
| 314 | - `python runtests.py` (to build and test) |
| 315 | - `python runtests.py --no-build` (to test installed numpy) |
| 316 | - `>>> numpy.test()` (run tests for installed numpy |
| 317 | from within an interpreter) |
| 318 | """, |
| 319 | upload=""" |
| 320 | `setup.py upload` is not supported, because it's insecure. |
| 321 | Instead, build what you want to upload and upload those files |
| 322 | with `twine upload -s <filenames>` instead. |
| 323 | """, |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 324 | clean=""" |
| 325 | `setup.py clean` is not supported, use one of the following instead: |
| 326 | |
| 327 | - `git clean -xdf` (cleans all files) |
| 328 | - `git clean -Xdf` (cleans all versioned files, doesn't touch |
| 329 | files that aren't checked into the git repo) |
| 330 | """, |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 331 | build_sphinx=""" |
| 332 | `setup.py build_sphinx` is not supported, use the |
| 333 | Makefile under doc/""", |
| 334 | flake8="`setup.py flake8` is not supported, use flake8 standalone", |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 335 | ) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 336 | bad_commands['nosetests'] = bad_commands['test'] |
Luca Mussi | 69d2cc8 | 2016-04-07 11:24:49 | [diff] [blame] | 337 | for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb', |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 338 | 'register', 'check', 'install_data', 'install_headers', |
| 339 | 'install_lib', 'install_scripts', ): |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 340 | bad_commands[command] = "`setup.py %s` is not supported" % command |
| 341 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 342 | for command in bad_commands.keys(): |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 343 | if command in args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 344 | print(textwrap.dedent(bad_commands[command]) + |
| 345 | "\nAdd `--force` to your command to use it anyway if you " |
| 346 | "must (unsupported).\n") |
| 347 | sys.exit(1) |
| 348 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 349 | # Commands that do more than print info, but also don't need Cython and |
| 350 | # template parsing. |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 351 | other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info'] |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 352 | for command in other_commands: |
| 353 | if command in args: |
| 354 | return False |
| 355 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 356 | # If we got here, we didn't detect what setup.py command was given |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 357 | raise RuntimeError("Unrecognized setuptools command: {}".format(args)) |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 358 | |
| 359 | |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 360 | def get_docs_url(): |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 361 | if 'dev' in VERSION: |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 362 | return "https://numpy.org/devdocs" |
| 363 | else: |
Qiyu8 | 779d306 | 2020-11-03 12:30:49 | [diff] [blame] | 364 | # For releases, this URL ends up on pypi. |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 365 | # By pinning the version, users looking at old PyPI releases can get |
| 366 | # to the associated docs easily. |
| 367 | return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR) |
| 368 | |
| 369 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 370 | def setup_package(): |
mattip | 8b26655 | 2019-07-03 22:24:42 | [diff] [blame] | 371 | src_path = os.path.dirname(os.path.abspath(__file__)) |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 372 | old_path = os.getcwd() |
| 373 | os.chdir(src_path) |
| 374 | sys.path.insert(0, src_path) |
| 375 | |
Charles Harris | f22a33b | 2018-08-22 17:57:48 | [diff] [blame] | 376 | # The f2py scripts that will be installed |
| 377 | if sys.platform == 'win32': |
| 378 | f2py_cmds = [ |
| 379 | 'f2py = numpy.f2py.f2py2e:main', |
| 380 | ] |
| 381 | else: |
| 382 | f2py_cmds = [ |
| 383 | 'f2py = numpy.f2py.f2py2e:main', |
| 384 | 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1], |
| 385 | 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2], |
| 386 | ] |
| 387 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 388 | cmdclass["sdist"] = sdist_checked |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 389 | metadata = dict( |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 390 | name='numpy', |
| 391 | maintainer="NumPy Developers", |
| 392 | maintainer_email="numpy-discussion@python.org", |
| 393 | description=DOCLINES[0], |
| 394 | long_description="\n".join(DOCLINES[2:]), |
| 395 | url="https://www.numpy.org", |
| 396 | author="Travis E. Oliphant et al.", |
| 397 | download_url="https://pypi.python.org/pypi/numpy", |
Jarrod Millman | 0486b6d | 2019-04-12 01:11:21 | [diff] [blame] | 398 | project_urls={ |
| 399 | "Bug Tracker": "https://github.com/numpy/numpy/issues", |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 400 | "Documentation": get_docs_url(), |
Jarrod Millman | 0486b6d | 2019-04-12 01:11:21 | [diff] [blame] | 401 | "Source Code": "https://github.com/numpy/numpy", |
| 402 | }, |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 403 | license='BSD', |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 404 | classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 405 | platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], |
Charles Harris | b3b6cc0 | 2020-05-18 22:26:10 | [diff] [blame] | 406 | test_suite='pytest', |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 407 | version=versioneer.get_version(), |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 408 | cmdclass=cmdclass, |
Ralf Gommers | 1e8d6a8 | 2021-07-18 20:32:38 | [diff] [blame] | 409 | python_requires='>=3.7,<3.11', |
Nathaniel J. Smith | f46e716 | 2018-01-23 08:02:04 | [diff] [blame] | 410 | zip_safe=False, |
Charles Harris | f22a33b | 2018-08-22 17:57:48 | [diff] [blame] | 411 | entry_points={ |
| 412 | 'console_scripts': f2py_cmds |
| 413 | }, |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 414 | ) |
| 415 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 416 | if "--force" in sys.argv: |
| 417 | run_build = True |
Ralf Gommers | 20c3c2a | 2017-06-20 10:09:40 | [diff] [blame] | 418 | sys.argv.remove('--force') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 419 | else: |
| 420 | # Raise errors for unsupported commands, improve help output, etc. |
| 421 | run_build = parse_setuppy_commands() |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 422 | |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 423 | if run_build: |
Mike Taves | 07bf33f | 2020-02-04 19:21:51 | [diff] [blame] | 424 | # patches distutils, even though we don't use it |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 425 | #from setuptools import setup |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 426 | from numpy.distutils.core import setup |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 427 | |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 428 | if 'sdist' not in sys.argv: |
Ralf Gommers | d630d96 | 2019-09-08 05:01:41 | [diff] [blame] | 429 | # Generate Cython sources, unless we're generating an sdist |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 430 | generate_cython() |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 431 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 432 | metadata['configuration'] = configuration |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 433 | # Customize extension building |
| 434 | cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides() |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 435 | else: |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 436 | #from numpy.distutils.core import setup |
Mike Taves | 07bf33f | 2020-02-04 19:21:51 | [diff] [blame] | 437 | from setuptools import setup |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 438 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 439 | try: |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 440 | setup(**metadata) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 441 | finally: |
| 442 | del sys.path[0] |
| 443 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 444 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 445 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 446 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 447 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 448 | setup_package() |
Ralf Gommers | bbee747 | 2016-08-21 05:23:35 | [diff] [blame] | 449 | # This may avoid problems where numpy is installed via ``*_requires`` by |
| 450 | # setuptools, the global namespace isn't reset properly, and then numpy is |
| 451 | # imported later (which will then fail to load numpy extension modules). |
| 452 | # See gh-7956 for details |
| 453 | del builtins.__NUMPY_SETUP__ |