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