blob: 353b6c096930fc0820009755b44b5eaabe49c50f [file] [log] [blame]
Changqing Li583901a2020-03-04 08:22:401#!/usr/bin/env python3
Ralf Gommers759dd952018-08-23 17:11:582""" NumPy is the fundamental package for array computing with Python.
Travis Oliphantda9c6da2006-01-04 17:31:073
Ralf Gommers759dd952018-08-23 17:11:584It provides:
Travis Oliphantda9c6da2006-01-04 17:31:075
Ralf Gommers759dd952018-08-23 17:11:586- 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 Harris6aa264c2013-02-27 20:26:5811
Ralf Gommers759dd952018-08-23 17:11:5812Besides its obvious scientific uses, NumPy can also be used as an efficient
13multi-dimensional container of generic data. Arbitrary data-types can be
14defined. This allows NumPy to seamlessly and speedily integrate with a wide
15variety of databases.
Matthew Brettbe575d52016-03-07 20:52:0816
Ralf Gommers759dd952018-08-23 17:11:5817All NumPy wheels distributed on PyPI are BSD licensed.
Matthew Brettbe575d52016-03-07 20:52:0818
Ralf Gommersdfe82452021-12-28 19:49:0019NumPy requires ``pytest`` and ``hypothesis``. Tests can then be run after
20installation with::
21
22 python -c 'import numpy; numpy.test()'
23
Travis Oliphantda9c6da2006-01-04 17:31:0724"""
David Sanders922442f2015-10-19 20:03:3425DOCLINES = (__doc__ or '').split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3126
Pearu Petersone8fa0132003-03-07 18:08:2827import os
28import sys
David Cournapeau5623a7c2009-04-02 16:21:3029import subprocess
Ralf Gommers99e99e92015-12-29 14:24:2230import textwrap
Hugo van Kemenadef3a6b332020-10-04 09:09:5231import warnings
Charles Harris40fd17e2020-12-02 20:06:5132import builtins
Charles Harris9a37cd92021-05-25 19:35:4233import re
Pearu Petersonc415fd12002-11-18 22:39:3134
Ralf Gommersf66d5db2020-12-22 20:11:5035
36# Python supported version checks. Keep right after stdlib imports to ensure we
37# get a sensible error for older Python versions
Sebastian Berg3dcbecc2021-11-07 17:42:4738if sys.version_info[:2] < (3, 8):
Charles Harris9a176d02021-08-13 15:53:4139 raise RuntimeError("Python version >= 3.8 required.")
Ralf Gommersf66d5db2020-12-22 20:11:5040
41
42import versioneer
43
44
Charles Harris40fd17e2020-12-02 20:06:5145# This is a bit hackish: we are setting a global variable so that the main
46# numpy __init__ can detect if it is being loaded by the setup routine, to
47# avoid attempting to load components that aren't built yet. While ugly, it's
48# a lot more robust than what was previously being used.
49builtins.__NUMPY_SETUP__ = True
Ralf Gommers17716d72013-12-06 19:45:4050
Charles Harris40fd17e2020-12-02 20:06:5151# Needed for backwards code compatibility below and in some CI scripts.
52# The version components are changed from ints to strings, but only VERSION
53# seems to matter outside of this module and it was already a str.
54FULLVERSION = versioneer.get_version()
Charles Harris9a37cd92021-05-25 19:35:4255
56# Capture the version string:
57# 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0
58# 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0
59# 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0
60# 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0
61ISRELEASED = re.search(r'(dev|\+)', FULLVERSION) is None
Matthew Brett9db73b52021-10-23 11:05:3162_V_MATCH = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION)
63if _V_MATCH is None:
64 raise RuntimeError(f'Cannot parse version {FULLVERSION}')
65MAJOR, MINOR, MICRO = _V_MATCH.groups()
Charles Harris40fd17e2020-12-02 20:06:5166VERSION = '{}.{}.{}'.format(MAJOR, MINOR, MICRO)
67
Charles Harris40fd17e2020-12-02 20:06:5168# The first version not in the `Programming Language :: Python :: ...` classifiers above
Bas van Beek856d6d62021-10-05 15:49:0369if sys.version_info >= (3, 11):
Charles Harrisca11e4e2020-12-12 15:17:0170 fmt = "NumPy {} may not yet support Python {}.{}."
Charles Harris40fd17e2020-12-02 20:06:5171 warnings.warn(
Charles Harrisca11e4e2020-12-12 15:17:0172 fmt.format(VERSION, *sys.version_info[:2]),
73 RuntimeWarning)
74 del fmt
David Cournapeau2b517692009-12-03 15:53:2975
Charles Harris40fd17e2020-12-02 20:06:5176# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
77# properly updated when the contents of directories change (true for distutils,
78# not sure about setuptools).
79if os.path.exists('MANIFEST'):
80 os.remove('MANIFEST')
81
82# We need to import setuptools here in order for it to persist in sys.modules.
Charles Harrisfed25092020-12-10 18:58:4783# Its presence/absence is used in subclassing setup in numpy/distutils/core.py.
84# However, we need to run the distutils version of sdist, so import that first
85# so that it is in sys.modules
86import numpy.distutils.command.sdist
Charles Harris40fd17e2020-12-02 20:06:5187import setuptools
Charles Harrisc62e1db2022-01-06 23:51:2088if int(setuptools.__version__.split('.')[0]) >= 60:
Andrew J. Hesforddedc0952022-02-01 15:34:2689 # setuptools >= 60 switches to vendored distutils by default; this
90 # may break the numpy build, so make sure the stdlib version is used
91 try:
92 setuptools_use_distutils = os.environ['SETUPTOOLS_USE_DISTUTILS']
93 except KeyError:
94 os.environ['SETUPTOOLS_USE_DISTUTILS'] = "stdlib"
95 else:
96 if setuptools_use_distutils != "stdlib":
97 raise RuntimeError("setuptools versions >= '60.0.0' require "
98 "SETUPTOOLS_USE_DISTUTILS=stdlib in the environment")
Charles Harris40fd17e2020-12-02 20:06:5199
100# Initialize cmdclass from versioneer
101from numpy.distutils.core import numpy_cmdclass
102cmdclass = versioneer.get_cmdclass(numpy_cmdclass)
Ralf Gommers17716d72013-12-06 19:45:40103
Travis Oliphantda9c6da2006-01-04 17:31:07104CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:44105Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:07106Intended Audience :: Science/Research
107Intended Audience :: Developers
johnthagen5cb80d62020-10-22 12:43:03108License :: OSI Approved :: BSD License
Travis Oliphantda9c6da2006-01-04 17:31:07109Programming Language :: C
110Programming Language :: Python
rgommerscdac1202011-01-25 14:02:40111Programming Language :: Python :: 3
Grzegorz Bokotac861a362019-10-24 18:29:09112Programming Language :: Python :: 3.8
Hugo van Kemenade79a8e162020-10-04 11:59:53113Programming Language :: Python :: 3.9
Charles Harris9a176d02021-08-13 15:53:41114Programming Language :: Python :: 3.10
Jon Dufresne334201d2019-08-27 04:18:35115Programming Language :: Python :: 3 :: Only
Alex Willmer193668a2015-08-05 09:29:39116Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:07117Topic :: Software Development
118Topic :: Scientific/Engineering
Bas van Beeke592c272020-10-04 13:10:42119Typing :: Typed
Travis Oliphantda9c6da2006-01-04 17:31:07120Operating System :: Microsoft :: Windows
121Operating System :: POSIX
122Operating System :: Unix
123Operating System :: MacOS
124"""
125
Ralf Gommers17716d72013-12-06 19:45:40126
Hugo van Kemenade2ebb4532020-10-04 09:41:47127def configuration(parent_package='', top_path=None):
Pearu Peterson471196b2006-03-31 08:59:36128 from numpy.distutils.misc_util import Configuration
129
Pearu Peterson17d7cfe2006-04-04 12:26:14130 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36131 config.set_options(ignore_setup_xxx_py=True,
132 assume_default_configuration=True,
133 delegate_options_to_subpackages=True,
134 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18135
Pearu Peterson471196b2006-03-31 08:59:36136 config.add_subpackage('numpy')
Charles Harris054d93a2017-11-29 18:53:21137 config.add_data_files(('numpy', 'LICENSE.txt'))
scodere1211b82020-08-05 04:28:30138 config.add_data_files(('numpy', 'numpy/*.pxd'))
Jarrod Millman0b77f0e2007-10-29 14:58:18139
Hugo van Kemenade2ebb4532020-10-04 09:41:47140 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01141
Pearu Peterson471196b2006-03-31 08:59:36142 return config
143
Ralf Gommers4b0ed792015-12-29 10:29:38144
Julian Taylor4cd72742014-01-29 21:59:19145def check_submodules():
146 """ verify that the submodules are checked out and clean
147 use `git submodule update --init`; on failure
148 """
149 if not os.path.exists('.git'):
150 return
151 with open('.gitmodules') as f:
Hugo van Kemenade2ebb4532020-10-04 09:41:47152 for line in f:
153 if 'path' in line:
154 p = line.split('=')[-1].strip()
Julian Taylor4cd72742014-01-29 21:59:19155 if not os.path.exists(p):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08156 raise ValueError('Submodule {} missing'.format(p))
Julian Taylor4cd72742014-01-29 21:59:19157
Julian Taylor4cd72742014-01-29 21:59:19158 proc = subprocess.Popen(['git', 'submodule', 'status'],
159 stdout=subprocess.PIPE)
160 status, _ = proc.communicate()
161 status = status.decode("ascii", "replace")
162 for line in status.splitlines():
163 if line.startswith('-') or line.startswith('+'):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08164 raise ValueError('Submodule not clean: {}'.format(line))
Julian Taylor4cd72742014-01-29 21:59:19165
Ralf Gommers4b0ed792015-12-29 10:29:38166
Ralf Gommersa08fb602019-05-03 14:44:23167class concat_license_files():
Ralf Gommers33415902019-05-07 09:00:50168 """Merge LICENSE.txt and LICENSES_bundled.txt for sdist creation
Ralf Gommersa08fb602019-05-03 14:44:23169
170 Done this way to keep LICENSE.txt in repo as exact BSD 3-clause (see
171 gh-13447). This makes GitHub state correctly how NumPy is licensed.
172 """
173 def __init__(self):
174 self.f1 = 'LICENSE.txt'
Ralf Gommers33415902019-05-07 09:00:50175 self.f2 = 'LICENSES_bundled.txt'
Ralf Gommersa08fb602019-05-03 14:44:23176
177 def __enter__(self):
Ralf Gommers33415902019-05-07 09:00:50178 """Concatenate files and remove LICENSES_bundled.txt"""
Ralf Gommersa08fb602019-05-03 14:44:23179 with open(self.f1, 'r') as f1:
180 self.bsd_text = f1.read()
181
182 with open(self.f1, 'a') as f1:
183 with open(self.f2, 'r') as f2:
184 self.bundled_text = f2.read()
185 f1.write('\n\n')
186 f1.write(self.bundled_text)
187
Ralf Gommersa08fb602019-05-03 14:44:23188 def __exit__(self, exception_type, exception_value, traceback):
189 """Restore content of both files"""
190 with open(self.f1, 'w') as f:
191 f.write(self.bsd_text)
192
Ralf Gommersa08fb602019-05-03 14:44:23193
Charles Harrisfed25092020-12-10 18:58:47194# Need to inherit from versioneer version of sdist to get the encoded
195# version information.
196class sdist_checked(cmdclass['sdist']):
Julian Taylor4cd72742014-01-29 21:59:19197 """ check submodules on sdist to prevent incomplete tarballs """
198 def run(self):
199 check_submodules()
Ralf Gommersa08fb602019-05-03 14:44:23200 with concat_license_files():
Charles Harrisfed25092020-12-10 18:58:47201 super().run()
Travis Oliphant14db4192005-09-14 22:08:46202
Ralf Gommers4b0ed792015-12-29 10:29:38203
mattip18af8e02020-01-04 20:47:47204def get_build_overrides():
205 """
mattipc2f93002020-01-05 15:00:30206 Custom build commands to add `-std=c99` to compilation
mattip18af8e02020-01-04 20:47:47207 """
208 from numpy.distutils.command.build_clib import build_clib
209 from numpy.distutils.command.build_ext import build_ext
Charles Harrisdf8d1fd2022-02-04 23:21:58210 from numpy.compat import _pep440
mattip18af8e02020-01-04 20:47:47211
mattip10dcfb02020-07-28 08:56:35212 def _needs_gcc_c99_flag(obj):
213 if obj.compiler.compiler_type != 'unix':
214 return False
215
216 cc = obj.compiler.compiler[0]
217 if "gcc" not in cc:
218 return False
219
220 # will print something like '4.2.1\n'
221 out = subprocess.run([cc, '-dumpversion'], stdout=subprocess.PIPE,
222 stderr=subprocess.PIPE, universal_newlines=True)
223 # -std=c99 is default from this version on
Charles Harrisdf8d1fd2022-02-04 23:21:58224 if _pep440.parse(out.stdout) >= _pep440.Version('5.0'):
mattip10dcfb02020-07-28 08:56:35225 return False
226 return True
mattip18af8e02020-01-04 20:47:47227
228 class new_build_clib(build_clib):
229 def build_a_library(self, build_info, lib_name, libraries):
serge-sans-paille91a3e3a2022-04-29 11:53:23230 from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS
mattip10dcfb02020-07-28 08:56:35231 if _needs_gcc_c99_flag(self):
serge-sans-paille2ae7aeb2021-08-19 07:28:09232 build_info['extra_cflags'] = ['-std=c99']
serge-sans-paille91a3e3a2022-04-29 11:53:23233 build_info['extra_cxxflags'] = NPY_CXX_FLAGS
mattip18af8e02020-01-04 20:47:47234 build_clib.build_a_library(self, build_info, lib_name, libraries)
235
236 class new_build_ext(build_ext):
237 def build_extension(self, ext):
mattip10dcfb02020-07-28 08:56:35238 if _needs_gcc_c99_flag(self):
mattipc2f93002020-01-05 15:00:30239 if '-std=c99' not in ext.extra_compile_args:
240 ext.extra_compile_args.append('-std=c99')
mattip18af8e02020-01-04 20:47:47241 build_ext.build_extension(self, ext)
242 return new_build_clib, new_build_ext
243
244
Julian Taylorc9fd6342014-04-05 11:13:13245def generate_cython():
Charles Harrisdf8d1fd2022-02-04 23:21:58246 # Check Cython version
247 from numpy.compat import _pep440
248 try:
249 # try the cython in the installed python first (somewhat related to
250 # scipy/scipy#2397)
251 import Cython
252 from Cython.Compiler.Version import version as cython_version
253 except ImportError as e:
254 # The `cython` command need not point to the version installed in the
255 # Python running this script, so raise an error to avoid the chance of
256 # using the wrong version of Cython.
257 msg = 'Cython needs to be installed in Python as a module'
258 raise OSError(msg) from e
259 else:
260 # Note: keep in sync with that in pyproject.toml
Mariusz Felisiak73a9e8e2022-05-16 11:43:33261 # Update for Python 3.11
Mariusz Felisiakc0696c5f22022-05-18 05:19:02262 required_version = '0.29.30'
Charles Harrisdf8d1fd2022-02-04 23:21:58263
264 if _pep440.parse(cython_version) < _pep440.Version(required_version):
265 cython_path = Cython.__file__
266 msg = 'Building NumPy requires Cython >= {}, found {} at {}'
267 msg = msg.format(required_version, cython_version, cython_path)
268 raise RuntimeError(msg)
269
270 # Process files
Julian Taylorc9fd6342014-04-05 11:13:13271 cwd = os.path.abspath(os.path.dirname(__file__))
272 print("Cythonizing sources")
mattip4e6a8122019-05-23 04:54:47273 for d in ('random',):
mattipfa8af412019-03-20 10:39:53274 p = subprocess.call([sys.executable,
Hugo van Kemenade2ebb4532020-10-04 09:41:47275 os.path.join(cwd, 'tools', 'cythonize.py'),
276 'numpy/{0}'.format(d)],
277 cwd=cwd)
mattipfa8af412019-03-20 10:39:53278 if p != 0:
279 raise RuntimeError("Running cythonize failed!")
Julian Taylorc9fd6342014-04-05 11:13:13280
Ralf Gommers4b0ed792015-12-29 10:29:38281
Ralf Gommersb9f48092015-12-29 11:05:30282def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22283 """Check the commands and respond appropriately. Disable broken commands.
284
285 Return a boolean value for whether or not to run the build or not (avoid
286 parsing Cython and template files if False).
287 """
Eric Wieserb8b2a0e2018-03-12 08:29:52288 args = sys.argv[1:]
289
290 if not args:
Ralf Gommersb9f48092015-12-29 11:05:30291 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22292 return True
Ralf Gommersb9f48092015-12-29 11:05:30293
Ralf Gommers99e99e92015-12-29 14:24:22294 info_commands = ['--help-commands', '--name', '--version', '-V',
295 '--fullname', '--author', '--author-email',
296 '--maintainer', '--maintainer-email', '--contact',
297 '--contact-email', '--url', '--license', '--description',
298 '--long-description', '--platforms', '--classifiers',
Charles Harris9b3f6502020-12-20 23:35:37299 '--keywords', '--provides', '--requires', '--obsoletes',
300 'version',]
Ralf Gommers99e99e92015-12-29 14:24:22301
302 for command in info_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52303 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22304 return False
305
306 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
307 # fine as they are, but are usually used together with one of the commands
308 # below and not standalone. Hence they're not added to good_commands.
309 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23310 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
Ralf Gommers491d26b2021-01-27 21:48:58311 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src',
312 'bdist_egg')
Ralf Gommers99e99e92015-12-29 14:24:22313
Ralf Gommersb9f48092015-12-29 11:05:30314 for command in good_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52315 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22316 return True
Ralf Gommersb9f48092015-12-29 11:05:30317
Ralf Gommersab5c6d02016-01-16 14:21:23318 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22319 # useful messages to the user
Eric Wieserb8b2a0e2018-03-12 08:29:52320 if 'install' in args:
Ralf Gommers99e99e92015-12-29 14:24:22321 print(textwrap.dedent("""
322 Note: if you need reliable uninstall behavior, then install
323 with pip instead of using `setup.py install`:
324
325 - `pip install .` (from a git repo or downloaded source
326 release)
Nihaal Sangha5ab126b2022-01-20 16:58:11327 - `pip install numpy` (last NumPy release on PyPI)
Ralf Gommers99e99e92015-12-29 14:24:22328
329 """))
330 return True
331
Eric Wieserb8b2a0e2018-03-12 08:29:52332 if '--help' in args or '-h' in sys.argv[1]:
Ralf Gommers99e99e92015-12-29 14:24:22333 print(textwrap.dedent("""
Pierre de Buyl3f6672a2016-09-06 12:54:08334 NumPy-specific help
Ralf Gommers99e99e92015-12-29 14:24:22335 -------------------
336
Pierre de Buyl3f6672a2016-09-06 12:54:08337 To install NumPy from here with reliable uninstall, we recommend
338 that you use `pip install .`. To install the latest NumPy release
Nihaal Sangha5ab126b2022-01-20 16:58:11339 from PyPI, use `pip install numpy`.
Ralf Gommers99e99e92015-12-29 14:24:22340
341 For help with build/installation issues, please ask on the
342 numpy-discussion mailing list. If you are sure that you have run
343 into a bug, please report it at https://github.com/numpy/numpy/issues.
344
345 Setuptools commands help
346 ------------------------
347 """))
348 return False
349
350 # The following commands aren't supported. They can only be executed when
351 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30352 bad_commands = dict(
353 test="""
354 `setup.py test` is not supported. Use one of the following
355 instead:
356
357 - `python runtests.py` (to build and test)
358 - `python runtests.py --no-build` (to test installed numpy)
359 - `>>> numpy.test()` (run tests for installed numpy
360 from within an interpreter)
361 """,
362 upload="""
363 `setup.py upload` is not supported, because it's insecure.
364 Instead, build what you want to upload and upload those files
365 with `twine upload -s <filenames>` instead.
366 """,
Ralf Gommersb9f48092015-12-29 11:05:30367 clean="""
368 `setup.py clean` is not supported, use one of the following instead:
369
370 - `git clean -xdf` (cleans all files)
371 - `git clean -Xdf` (cleans all versioned files, doesn't touch
372 files that aren't checked into the git repo)
373 """,
Ralf Gommers99e99e92015-12-29 14:24:22374 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 Gommersb9f48092015-12-29 11:05:30378 )
Ralf Gommers99e99e92015-12-29 14:24:22379 bad_commands['nosetests'] = bad_commands['test']
Luca Mussi69d2cc82016-04-07 11:24:49380 for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
Hugo van Kemenade2ebb4532020-10-04 09:41:47381 'register', 'check', 'install_data', 'install_headers',
382 'install_lib', 'install_scripts', ):
Ralf Gommers99e99e92015-12-29 14:24:22383 bad_commands[command] = "`setup.py %s` is not supported" % command
384
Ralf Gommersb9f48092015-12-29 11:05:30385 for command in bad_commands.keys():
Eric Wieserb8b2a0e2018-03-12 08:29:52386 if command in args:
Ralf Gommersb9f48092015-12-29 11:05:30387 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 Wieserb8b2a0e2018-03-12 08:29:52392 # Commands that do more than print info, but also don't need Cython and
393 # template parsing.
Charles Harris9b3f6502020-12-20 23:35:37394 other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info']
Eric Wieserb8b2a0e2018-03-12 08:29:52395 for command in other_commands:
396 if command in args:
397 return False
398
Ralf Gommers99e99e92015-12-29 14:24:22399 # If we got here, we didn't detect what setup.py command was given
Charles Harris9b3f6502020-12-20 23:35:37400 raise RuntimeError("Unrecognized setuptools command: {}".format(args))
Ralf Gommersb9f48092015-12-29 11:05:30401
402
Eric Wieserfb47ba62020-06-20 16:28:51403def get_docs_url():
Charles Harris40fd17e2020-12-02 20:06:51404 if 'dev' in VERSION:
Eric Wieserfb47ba62020-06-20 16:28:51405 return "https://numpy.org/devdocs"
406 else:
Nihaal Sangha5ab126b2022-01-20 16:58:11407 # For releases, this URL ends up on PyPI.
Eric Wieserfb47ba62020-06-20 16:28:51408 # By pinning the version, users looking at old PyPI releases can get
409 # to the associated docs easily.
410 return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR)
411
412
Ralf Gommers17716d72013-12-06 19:45:40413def setup_package():
mattip8b266552019-07-03 22:24:42414 src_path = os.path.dirname(os.path.abspath(__file__))
Pauli Virtanen68159432009-12-06 11:56:18415 old_path = os.getcwd()
416 os.chdir(src_path)
417 sys.path.insert(0, src_path)
418
Charles Harrisf22a33b2018-08-22 17:57:48419 # The f2py scripts that will be installed
420 if sys.platform == 'win32':
421 f2py_cmds = [
422 'f2py = numpy.f2py.f2py2e:main',
423 ]
424 else:
425 f2py_cmds = [
426 'f2py = numpy.f2py.f2py2e:main',
427 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1],
428 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2],
429 ]
430
Charles Harris40fd17e2020-12-02 20:06:51431 cmdclass["sdist"] = sdist_checked
Ralf Gommers17716d72013-12-06 19:45:40432 metadata = dict(
Hugo van Kemenade2ebb4532020-10-04 09:41:47433 name='numpy',
434 maintainer="NumPy Developers",
435 maintainer_email="numpy-discussion@python.org",
436 description=DOCLINES[0],
437 long_description="\n".join(DOCLINES[2:]),
438 url="https://www.numpy.org",
439 author="Travis E. Oliphant et al.",
440 download_url="https://pypi.python.org/pypi/numpy",
Jarrod Millman0486b6d2019-04-12 01:11:21441 project_urls={
442 "Bug Tracker": "https://github.com/numpy/numpy/issues",
Eric Wieserfb47ba62020-06-20 16:28:51443 "Documentation": get_docs_url(),
Jarrod Millman0486b6d2019-04-12 01:11:21444 "Source Code": "https://github.com/numpy/numpy",
445 },
Hugo van Kemenade2ebb4532020-10-04 09:41:47446 license='BSD',
Ralf Gommers17716d72013-12-06 19:45:40447 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
Hugo van Kemenade2ebb4532020-10-04 09:41:47448 platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
Charles Harrisb3b6cc02020-05-18 22:26:10449 test_suite='pytest',
Charles Harris40fd17e2020-12-02 20:06:51450 version=versioneer.get_version(),
mattip18af8e02020-01-04 20:47:47451 cmdclass=cmdclass,
Charles Harris9a176d02021-08-13 15:53:41452 python_requires='>=3.8',
Nathaniel J. Smithf46e7162018-01-23 08:02:04453 zip_safe=False,
Charles Harrisf22a33b2018-08-22 17:57:48454 entry_points={
Matthew Barberdf6d2852021-08-31 09:23:14455 'console_scripts': f2py_cmds,
456 'array_api': ['numpy = numpy.array_api'],
bwoodsendbac9d0e2022-01-06 00:55:16457 'pyinstaller40': ['hook-dirs = numpy:_pyinstaller_hooks_dir'],
Charles Harrisf22a33b2018-08-22 17:57:48458 },
Ralf Gommers17716d72013-12-06 19:45:40459 )
460
Ralf Gommers99e99e92015-12-29 14:24:22461 if "--force" in sys.argv:
462 run_build = True
Ralf Gommers20c3c2a2017-06-20 10:09:40463 sys.argv.remove('--force')
Ralf Gommers99e99e92015-12-29 14:24:22464 else:
465 # Raise errors for unsupported commands, improve help output, etc.
466 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30467
Charles Harris9b3f6502020-12-20 23:35:37468 if run_build:
Mike Taves07bf33f2020-02-04 19:21:51469 # patches distutils, even though we don't use it
Charles Harris40fd17e2020-12-02 20:06:51470 #from setuptools import setup
Ralf Gommers17716d72013-12-06 19:45:40471 from numpy.distutils.core import setup
Charles Harris40fd17e2020-12-02 20:06:51472
Hugo van Kemenade2ebb4532020-10-04 09:41:47473 if 'sdist' not in sys.argv:
Ralf Gommersd630d962019-09-08 05:01:41474 # Generate Cython sources, unless we're generating an sdist
Julian Taylorc9fd6342014-04-05 11:13:13475 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38476
Ralf Gommers17716d72013-12-06 19:45:40477 metadata['configuration'] = configuration
mattip18af8e02020-01-04 20:47:47478 # Customize extension building
479 cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
Ralf Gommers99e99e92015-12-29 14:24:22480 else:
Charles Harris40fd17e2020-12-02 20:06:51481 #from numpy.distutils.core import setup
Mike Taves07bf33f2020-02-04 19:21:51482 from setuptools import setup
Pauli Virtanen68159432009-12-06 11:56:18483
Pearu Petersone8fa0132003-03-07 18:08:28484 try:
Ralf Gommers17716d72013-12-06 19:45:40485 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28486 finally:
487 del sys.path[0]
488 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46489 return
Pearu Petersonc415fd12002-11-18 22:39:31490
Ralf Gommers17716d72013-12-06 19:45:40491
Travis Oliphant14db4192005-09-14 22:08:46492if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28493 setup_package()
Ralf Gommersbbee7472016-08-21 05:23:35494 # This may avoid problems where numpy is installed via ``*_requires`` by
495 # setuptools, the global namespace isn't reset properly, and then numpy is
496 # imported later (which will then fail to load numpy extension modules).
497 # See gh-7956 for details
498 del builtins.__NUMPY_SETUP__