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