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