Changqing Li | 583901a | 2020-03-04 08:22:40 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Travis Oliphant | da9c6da | 2006-01-04 17:31:07 | [diff] [blame] | 2 | """ |
hannah | 6c2fa30 | 2022-11-01 16:28:36 | [diff] [blame] | 3 | Numpy build options can be modified with a site.cfg file. |
| 4 | See site.cfg.example for a template and more information. |
| 5 | """ |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 6 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 7 | import os |
hannah | ce57eea | 2022-10-31 03:00:03 | [diff] [blame] | 8 | from pathlib import Path |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 9 | import sys |
David Cournapeau | 5623a7c | 2009-04-02 16:21:30 | [diff] [blame] | 10 | import subprocess |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 11 | import textwrap |
Hugo van Kemenade | f3a6b33 | 2020-10-04 09:09:52 | [diff] [blame] | 12 | import warnings |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 13 | import builtins |
Charles Harris | 9a37cd9 | 2021-05-25 19:35:42 | [diff] [blame] | 14 | import re |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 15 | |
Ralf Gommers | f66d5db | 2020-12-22 20:11:50 | [diff] [blame] | 16 | |
| 17 | # Python supported version checks. Keep right after stdlib imports to ensure we |
| 18 | # get a sensible error for older Python versions |
Sebastian Berg | 3dcbecc | 2021-11-07 17:42:47 | [diff] [blame] | 19 | if sys.version_info[:2] < (3, 8): |
Charles Harris | 9a176d0 | 2021-08-13 15:53:41 | [diff] [blame] | 20 | raise RuntimeError("Python version >= 3.8 required.") |
Ralf Gommers | f66d5db | 2020-12-22 20:11:50 | [diff] [blame] | 21 | |
| 22 | |
| 23 | import versioneer |
| 24 | |
| 25 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 26 | # This is a bit hackish: we are setting a global variable so that the main |
| 27 | # numpy __init__ can detect if it is being loaded by the setup routine, to |
| 28 | # avoid attempting to load components that aren't built yet. While ugly, it's |
| 29 | # a lot more robust than what was previously being used. |
| 30 | builtins.__NUMPY_SETUP__ = True |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 31 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 32 | # Needed for backwards code compatibility below and in some CI scripts. |
| 33 | # The version components are changed from ints to strings, but only VERSION |
| 34 | # seems to matter outside of this module and it was already a str. |
| 35 | FULLVERSION = versioneer.get_version() |
Charles Harris | 9a37cd9 | 2021-05-25 19:35:42 | [diff] [blame] | 36 | |
| 37 | # Capture the version string: |
| 38 | # 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0 |
| 39 | # 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0 |
| 40 | # 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0 |
| 41 | # 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0 |
| 42 | ISRELEASED = re.search(r'(dev|\+)', FULLVERSION) is None |
Matthew Brett | 9db73b5 | 2021-10-23 11:05:31 | [diff] [blame] | 43 | _V_MATCH = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION) |
| 44 | if _V_MATCH is None: |
| 45 | raise RuntimeError(f'Cannot parse version {FULLVERSION}') |
| 46 | MAJOR, MINOR, MICRO = _V_MATCH.groups() |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 47 | VERSION = '{}.{}.{}'.format(MAJOR, MINOR, MICRO) |
| 48 | |
Dimitri Papadopoulos Orfanos | 3cf2ca1 | 2022-10-07 19:34:47 | [diff] [blame] | 49 | # The first version not in the `Programming Language :: Python :: ...` classifiers below |
Charles Harris | f06a315 | 2022-08-17 14:36:04 | [diff] [blame] | 50 | if sys.version_info >= (3, 12): |
Charles Harris | ca11e4e | 2020-12-12 15:17:01 | [diff] [blame] | 51 | fmt = "NumPy {} may not yet support Python {}.{}." |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 52 | warnings.warn( |
Charles Harris | ca11e4e | 2020-12-12 15:17:01 | [diff] [blame] | 53 | fmt.format(VERSION, *sys.version_info[:2]), |
| 54 | RuntimeWarning) |
| 55 | del fmt |
David Cournapeau | 2b51769 | 2009-12-03 15:53:29 | [diff] [blame] | 56 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 57 | # BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be |
| 58 | # properly updated when the contents of directories change (true for distutils, |
| 59 | # not sure about setuptools). |
| 60 | if os.path.exists('MANIFEST'): |
| 61 | os.remove('MANIFEST') |
| 62 | |
| 63 | # 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] | 64 | # Its presence/absence is used in subclassing setup in numpy/distutils/core.py. |
| 65 | # However, we need to run the distutils version of sdist, so import that first |
| 66 | # so that it is in sys.modules |
| 67 | import numpy.distutils.command.sdist |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 68 | import setuptools |
Charles Harris | c62e1db | 2022-01-06 23:51:20 | [diff] [blame] | 69 | if int(setuptools.__version__.split('.')[0]) >= 60: |
Andrew J. Hesford | dedc095 | 2022-02-01 15:34:26 | [diff] [blame] | 70 | # setuptools >= 60 switches to vendored distutils by default; this |
| 71 | # may break the numpy build, so make sure the stdlib version is used |
| 72 | try: |
| 73 | setuptools_use_distutils = os.environ['SETUPTOOLS_USE_DISTUTILS'] |
| 74 | except KeyError: |
| 75 | os.environ['SETUPTOOLS_USE_DISTUTILS'] = "stdlib" |
| 76 | else: |
| 77 | if setuptools_use_distutils != "stdlib": |
| 78 | raise RuntimeError("setuptools versions >= '60.0.0' require " |
| 79 | "SETUPTOOLS_USE_DISTUTILS=stdlib in the environment") |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 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 |
Grzegorz Bokota | c861a36 | 2019-10-24 18:29:09 | [diff] [blame] | 93 | Programming Language :: Python :: 3.8 |
Hugo van Kemenade | 79a8e16 | 2020-10-04 11:59:53 | [diff] [blame] | 94 | Programming Language :: Python :: 3.9 |
Charles Harris | 9a176d0 | 2021-08-13 15:53:41 | [diff] [blame] | 95 | Programming Language :: Python :: 3.10 |
Charles Harris | f06a315 | 2022-08-17 14:36:04 | [diff] [blame] | 96 | Programming Language :: Python :: 3.11 |
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 |
Charles Harris | df8d1fd | 2022-02-04 23:21:58 | [diff] [blame] | 192 | from numpy.compat import _pep440 |
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' |
Mike Taves | 69a3946 | 2022-10-26 21:19:42 | [diff] [blame] | 203 | out = subprocess.run([cc, '-dumpversion'], |
| 204 | capture_output=True, text=True) |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 205 | # -std=c99 is default from this version on |
Charles Harris | df8d1fd | 2022-02-04 23:21:58 | [diff] [blame] | 206 | if _pep440.parse(out.stdout) >= _pep440.Version('5.0'): |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 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): |
serge-sans-paille | 91a3e3a | 2022-04-29 11:53:23 | [diff] [blame] | 212 | from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS |
mattip | 10dcfb0 | 2020-07-28 08:56:35 | [diff] [blame] | 213 | if _needs_gcc_c99_flag(self): |
serge-sans-paille | 2ae7aeb | 2021-08-19 07:28:09 | [diff] [blame] | 214 | build_info['extra_cflags'] = ['-std=c99'] |
serge-sans-paille | 91a3e3a | 2022-04-29 11:53:23 | [diff] [blame] | 215 | build_info['extra_cxxflags'] = NPY_CXX_FLAGS |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 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(): |
Charles Harris | df8d1fd | 2022-02-04 23:21:58 | [diff] [blame] | 228 | # Check Cython version |
| 229 | from numpy.compat import _pep440 |
| 230 | try: |
| 231 | # try the cython in the installed python first (somewhat related to |
| 232 | # scipy/scipy#2397) |
| 233 | import Cython |
| 234 | from Cython.Compiler.Version import version as cython_version |
| 235 | except ImportError as e: |
| 236 | # The `cython` command need not point to the version installed in the |
| 237 | # Python running this script, so raise an error to avoid the chance of |
| 238 | # using the wrong version of Cython. |
| 239 | msg = 'Cython needs to be installed in Python as a module' |
| 240 | raise OSError(msg) from e |
| 241 | else: |
| 242 | # Note: keep in sync with that in pyproject.toml |
Mariusz Felisiak | 73a9e8e | 2022-05-16 11:43:33 | [diff] [blame] | 243 | # Update for Python 3.11 |
Mariusz Felisiak | c0696c5f2 | 2022-05-18 05:19:02 | [diff] [blame] | 244 | required_version = '0.29.30' |
Charles Harris | df8d1fd | 2022-02-04 23:21:58 | [diff] [blame] | 245 | |
| 246 | if _pep440.parse(cython_version) < _pep440.Version(required_version): |
| 247 | cython_path = Cython.__file__ |
| 248 | msg = 'Building NumPy requires Cython >= {}, found {} at {}' |
| 249 | msg = msg.format(required_version, cython_version, cython_path) |
| 250 | raise RuntimeError(msg) |
| 251 | |
| 252 | # Process files |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 253 | cwd = os.path.abspath(os.path.dirname(__file__)) |
| 254 | print("Cythonizing sources") |
mattip | 4e6a812 | 2019-05-23 04:54:47 | [diff] [blame] | 255 | for d in ('random',): |
mattip | fa8af41 | 2019-03-20 10:39:53 | [diff] [blame] | 256 | p = subprocess.call([sys.executable, |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 257 | os.path.join(cwd, 'tools', 'cythonize.py'), |
| 258 | 'numpy/{0}'.format(d)], |
| 259 | cwd=cwd) |
mattip | fa8af41 | 2019-03-20 10:39:53 | [diff] [blame] | 260 | if p != 0: |
| 261 | raise RuntimeError("Running cythonize failed!") |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 262 | |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 263 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 264 | def parse_setuppy_commands(): |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 265 | """Check the commands and respond appropriately. Disable broken commands. |
| 266 | |
| 267 | Return a boolean value for whether or not to run the build or not (avoid |
| 268 | parsing Cython and template files if False). |
| 269 | """ |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 270 | args = sys.argv[1:] |
| 271 | |
| 272 | if not args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 273 | # User forgot to give an argument probably, let setuptools handle that. |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 274 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 275 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 276 | info_commands = ['--help-commands', '--name', '--version', '-V', |
| 277 | '--fullname', '--author', '--author-email', |
| 278 | '--maintainer', '--maintainer-email', '--contact', |
| 279 | '--contact-email', '--url', '--license', '--description', |
| 280 | '--long-description', '--platforms', '--classifiers', |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 281 | '--keywords', '--provides', '--requires', '--obsoletes', |
| 282 | 'version',] |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 283 | |
| 284 | for command in info_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 285 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 286 | return False |
| 287 | |
| 288 | # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work |
| 289 | # fine as they are, but are usually used together with one of the commands |
| 290 | # below and not standalone. Hence they're not added to good_commands. |
| 291 | good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py', |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 292 | 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm', |
Ralf Gommers | 491d26b | 2021-01-27 21:48:58 | [diff] [blame] | 293 | 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src', |
| 294 | 'bdist_egg') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 295 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 296 | for command in good_commands: |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 297 | if command in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 298 | return True |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 299 | |
Ralf Gommers | ab5c6d0 | 2016-01-16 14:21:23 | [diff] [blame] | 300 | # The following commands are supported, but we need to show more |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 301 | # useful messages to the user |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 302 | if 'install' in args: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 303 | print(textwrap.dedent(""" |
| 304 | Note: if you need reliable uninstall behavior, then install |
| 305 | with pip instead of using `setup.py install`: |
| 306 | |
| 307 | - `pip install .` (from a git repo or downloaded source |
| 308 | release) |
Nihaal Sangha | 5ab126b | 2022-01-20 16:58:11 | [diff] [blame] | 309 | - `pip install numpy` (last NumPy release on PyPI) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 310 | |
| 311 | """)) |
| 312 | return True |
| 313 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 314 | if '--help' in args or '-h' in sys.argv[1]: |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 315 | print(textwrap.dedent(""" |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 316 | NumPy-specific help |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 317 | ------------------- |
| 318 | |
Pierre de Buyl | 3f6672a | 2016-09-06 12:54:08 | [diff] [blame] | 319 | To install NumPy from here with reliable uninstall, we recommend |
| 320 | that you use `pip install .`. To install the latest NumPy release |
Nihaal Sangha | 5ab126b | 2022-01-20 16:58:11 | [diff] [blame] | 321 | from PyPI, use `pip install numpy`. |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 322 | |
| 323 | For help with build/installation issues, please ask on the |
| 324 | numpy-discussion mailing list. If you are sure that you have run |
| 325 | into a bug, please report it at https://github.com/numpy/numpy/issues. |
| 326 | |
| 327 | Setuptools commands help |
| 328 | ------------------------ |
| 329 | """)) |
| 330 | return False |
| 331 | |
| 332 | # The following commands aren't supported. They can only be executed when |
| 333 | # the user explicitly adds a --force command-line argument. |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 334 | bad_commands = dict( |
| 335 | test=""" |
| 336 | `setup.py test` is not supported. Use one of the following |
| 337 | instead: |
| 338 | |
| 339 | - `python runtests.py` (to build and test) |
| 340 | - `python runtests.py --no-build` (to test installed numpy) |
| 341 | - `>>> numpy.test()` (run tests for installed numpy |
| 342 | from within an interpreter) |
| 343 | """, |
| 344 | upload=""" |
| 345 | `setup.py upload` is not supported, because it's insecure. |
| 346 | Instead, build what you want to upload and upload those files |
| 347 | with `twine upload -s <filenames>` instead. |
| 348 | """, |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 349 | clean=""" |
| 350 | `setup.py clean` is not supported, use one of the following instead: |
| 351 | |
| 352 | - `git clean -xdf` (cleans all files) |
| 353 | - `git clean -Xdf` (cleans all versioned files, doesn't touch |
| 354 | files that aren't checked into the git repo) |
| 355 | """, |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 356 | build_sphinx=""" |
| 357 | `setup.py build_sphinx` is not supported, use the |
| 358 | Makefile under doc/""", |
| 359 | flake8="`setup.py flake8` is not supported, use flake8 standalone", |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 360 | ) |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 361 | bad_commands['nosetests'] = bad_commands['test'] |
Luca Mussi | 69d2cc8 | 2016-04-07 11:24:49 | [diff] [blame] | 362 | for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb', |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 363 | 'register', 'check', 'install_data', 'install_headers', |
| 364 | 'install_lib', 'install_scripts', ): |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 365 | bad_commands[command] = "`setup.py %s` is not supported" % command |
| 366 | |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 367 | for command in bad_commands.keys(): |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 368 | if command in args: |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 369 | print(textwrap.dedent(bad_commands[command]) + |
| 370 | "\nAdd `--force` to your command to use it anyway if you " |
| 371 | "must (unsupported).\n") |
| 372 | sys.exit(1) |
| 373 | |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 374 | # Commands that do more than print info, but also don't need Cython and |
| 375 | # template parsing. |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 376 | other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info'] |
Eric Wieser | b8b2a0e | 2018-03-12 08:29:52 | [diff] [blame] | 377 | for command in other_commands: |
| 378 | if command in args: |
| 379 | return False |
| 380 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 381 | # 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] | 382 | raise RuntimeError("Unrecognized setuptools command: {}".format(args)) |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 383 | |
| 384 | |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 385 | def get_docs_url(): |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 386 | if 'dev' in VERSION: |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 387 | return "https://numpy.org/devdocs" |
| 388 | else: |
Nihaal Sangha | 5ab126b | 2022-01-20 16:58:11 | [diff] [blame] | 389 | # For releases, this URL ends up on PyPI. |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 390 | # By pinning the version, users looking at old PyPI releases can get |
| 391 | # to the associated docs easily. |
| 392 | return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR) |
| 393 | |
| 394 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 395 | def setup_package(): |
mattip | 8b26655 | 2019-07-03 22:24:42 | [diff] [blame] | 396 | src_path = os.path.dirname(os.path.abspath(__file__)) |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 397 | old_path = os.getcwd() |
| 398 | os.chdir(src_path) |
| 399 | sys.path.insert(0, src_path) |
| 400 | |
Charles Harris | f22a33b | 2018-08-22 17:57:48 | [diff] [blame] | 401 | # The f2py scripts that will be installed |
| 402 | if sys.platform == 'win32': |
| 403 | f2py_cmds = [ |
| 404 | 'f2py = numpy.f2py.f2py2e:main', |
| 405 | ] |
| 406 | else: |
| 407 | f2py_cmds = [ |
| 408 | 'f2py = numpy.f2py.f2py2e:main', |
| 409 | 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1], |
| 410 | 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2], |
| 411 | ] |
| 412 | |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 413 | cmdclass["sdist"] = sdist_checked |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 414 | metadata = dict( |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 415 | name='numpy', |
| 416 | maintainer="NumPy Developers", |
| 417 | maintainer_email="numpy-discussion@python.org", |
hannah | 6c2fa30 | 2022-11-01 16:28:36 | [diff] [blame] | 418 | description="Fundamental package for array computing in Python", |
| 419 | long_description=Path("README.md").read_text(encoding="utf-8"), |
hannah | ce57eea | 2022-10-31 03:00:03 | [diff] [blame] | 420 | long_description_content_type="text/markdown", |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 421 | url="https://www.numpy.org", |
| 422 | author="Travis E. Oliphant et al.", |
| 423 | download_url="https://pypi.python.org/pypi/numpy", |
Jarrod Millman | 0486b6d | 2019-04-12 01:11:21 | [diff] [blame] | 424 | project_urls={ |
| 425 | "Bug Tracker": "https://github.com/numpy/numpy/issues", |
Eric Wieser | fb47ba6 | 2020-06-20 16:28:51 | [diff] [blame] | 426 | "Documentation": get_docs_url(), |
Jarrod Millman | 0486b6d | 2019-04-12 01:11:21 | [diff] [blame] | 427 | "Source Code": "https://github.com/numpy/numpy", |
| 428 | }, |
Frazer McLean | 033503c | 2022-10-28 16:53:09 | [diff] [blame] | 429 | license='BSD-3-Clause', |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 430 | classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 431 | platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], |
Charles Harris | b3b6cc0 | 2020-05-18 22:26:10 | [diff] [blame] | 432 | test_suite='pytest', |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 433 | version=versioneer.get_version(), |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 434 | cmdclass=cmdclass, |
Charles Harris | 9a176d0 | 2021-08-13 15:53:41 | [diff] [blame] | 435 | python_requires='>=3.8', |
Nathaniel J. Smith | f46e716 | 2018-01-23 08:02:04 | [diff] [blame] | 436 | zip_safe=False, |
Charles Harris | f22a33b | 2018-08-22 17:57:48 | [diff] [blame] | 437 | entry_points={ |
Matthew Barber | df6d285 | 2021-08-31 09:23:14 | [diff] [blame] | 438 | 'console_scripts': f2py_cmds, |
| 439 | 'array_api': ['numpy = numpy.array_api'], |
bwoodsend | bac9d0e | 2022-01-06 00:55:16 | [diff] [blame] | 440 | 'pyinstaller40': ['hook-dirs = numpy:_pyinstaller_hooks_dir'], |
Charles Harris | f22a33b | 2018-08-22 17:57:48 | [diff] [blame] | 441 | }, |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 442 | ) |
| 443 | |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 444 | if "--force" in sys.argv: |
| 445 | run_build = True |
Ralf Gommers | 20c3c2a | 2017-06-20 10:09:40 | [diff] [blame] | 446 | sys.argv.remove('--force') |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 447 | else: |
| 448 | # Raise errors for unsupported commands, improve help output, etc. |
| 449 | run_build = parse_setuppy_commands() |
Ralf Gommers | b9f4809 | 2015-12-29 11:05:30 | [diff] [blame] | 450 | |
Charles Harris | 9b3f650 | 2020-12-20 23:35:37 | [diff] [blame] | 451 | if run_build: |
Mike Taves | 07bf33f | 2020-02-04 19:21:51 | [diff] [blame] | 452 | # patches distutils, even though we don't use it |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 453 | #from setuptools import setup |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 454 | from numpy.distutils.core import setup |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 455 | |
Hugo van Kemenade | 2ebb453 | 2020-10-04 09:41:47 | [diff] [blame] | 456 | if 'sdist' not in sys.argv: |
Ralf Gommers | d630d96 | 2019-09-08 05:01:41 | [diff] [blame] | 457 | # Generate Cython sources, unless we're generating an sdist |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 458 | generate_cython() |
Ralf Gommers | 4b0ed79 | 2015-12-29 10:29:38 | [diff] [blame] | 459 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 460 | metadata['configuration'] = configuration |
mattip | 18af8e0 | 2020-01-04 20:47:47 | [diff] [blame] | 461 | # Customize extension building |
| 462 | cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides() |
Ralf Gommers | 99e99e9 | 2015-12-29 14:24:22 | [diff] [blame] | 463 | else: |
Charles Harris | 40fd17e | 2020-12-02 20:06:51 | [diff] [blame] | 464 | #from numpy.distutils.core import setup |
Mike Taves | 07bf33f | 2020-02-04 19:21:51 | [diff] [blame] | 465 | from setuptools import setup |
Charles Harris | 8b94271 | 2022-12-19 01:17:51 | [diff] [blame] | 466 | # workaround for broken --no-build-isolation with newer setuptools, |
| 467 | # see gh-21288 |
Ralf Gommers | 5b0bc0d | 2022-11-29 11:04:04 | [diff] [blame] | 468 | metadata["packages"] = [] |
Pauli Virtanen | 6815943 | 2009-12-06 11:56:18 | [diff] [blame] | 469 | |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 470 | try: |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 471 | setup(**metadata) |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 472 | finally: |
| 473 | del sys.path[0] |
| 474 | os.chdir(old_path) |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 475 | return |
Pearu Peterson | c415fd1 | 2002-11-18 22:39:31 | [diff] [blame] | 476 | |
Ralf Gommers | 17716d7 | 2013-12-06 19:45:40 | [diff] [blame] | 477 | |
Travis Oliphant | 14db419 | 2005-09-14 22:08:46 | [diff] [blame] | 478 | if __name__ == '__main__': |
Pearu Peterson | e8fa013 | 2003-03-07 18:08:28 | [diff] [blame] | 479 | setup_package() |
Ralf Gommers | bbee747 | 2016-08-21 05:23:35 | [diff] [blame] | 480 | # This may avoid problems where numpy is installed via ``*_requires`` by |
| 481 | # setuptools, the global namespace isn't reset properly, and then numpy is |
| 482 | # imported later (which will then fail to load numpy extension modules). |
| 483 | # See gh-7956 for details |
| 484 | del builtins.__NUMPY_SETUP__ |