blob: 3aa7504b05cb91f67daf3b01c80b367d7bffb391 [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
Charles Harrisa6894ab2022-08-17 14:36:0469if sys.version_info >= (3, 12):
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
Charles Harrisa6894ab2022-08-17 14:36:04115Programming Language :: Python :: 3.11
Jon Dufresne334201d2019-08-27 04:18:35116Programming Language :: Python :: 3 :: Only
Alex Willmer193668a2015-08-05 09:29:39117Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:07118Topic :: Software Development
119Topic :: Scientific/Engineering
Bas van Beeke592c272020-10-04 13:10:42120Typing :: Typed
Travis Oliphantda9c6da2006-01-04 17:31:07121Operating System :: Microsoft :: Windows
122Operating System :: POSIX
123Operating System :: Unix
124Operating System :: MacOS
125"""
126
Ralf Gommers17716d72013-12-06 19:45:40127
Hugo van Kemenade2ebb4532020-10-04 09:41:47128def configuration(parent_package='', top_path=None):
Pearu Peterson471196b2006-03-31 08:59:36129 from numpy.distutils.misc_util import Configuration
130
Pearu Peterson17d7cfe2006-04-04 12:26:14131 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36132 config.set_options(ignore_setup_xxx_py=True,
133 assume_default_configuration=True,
134 delegate_options_to_subpackages=True,
135 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18136
Pearu Peterson471196b2006-03-31 08:59:36137 config.add_subpackage('numpy')
Charles Harris054d93a2017-11-29 18:53:21138 config.add_data_files(('numpy', 'LICENSE.txt'))
scodere1211b82020-08-05 04:28:30139 config.add_data_files(('numpy', 'numpy/*.pxd'))
Jarrod Millman0b77f0e2007-10-29 14:58:18140
Hugo van Kemenade2ebb4532020-10-04 09:41:47141 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01142
Pearu Peterson471196b2006-03-31 08:59:36143 return config
144
Ralf Gommers4b0ed792015-12-29 10:29:38145
Julian Taylor4cd72742014-01-29 21:59:19146def check_submodules():
147 """ verify that the submodules are checked out and clean
148 use `git submodule update --init`; on failure
149 """
150 if not os.path.exists('.git'):
151 return
152 with open('.gitmodules') as f:
Hugo van Kemenade2ebb4532020-10-04 09:41:47153 for line in f:
154 if 'path' in line:
155 p = line.split('=')[-1].strip()
Julian Taylor4cd72742014-01-29 21:59:19156 if not os.path.exists(p):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08157 raise ValueError('Submodule {} missing'.format(p))
Julian Taylor4cd72742014-01-29 21:59:19158
Julian Taylor4cd72742014-01-29 21:59:19159 proc = subprocess.Popen(['git', 'submodule', 'status'],
160 stdout=subprocess.PIPE)
161 status, _ = proc.communicate()
162 status = status.decode("ascii", "replace")
163 for line in status.splitlines():
164 if line.startswith('-') or line.startswith('+'):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08165 raise ValueError('Submodule not clean: {}'.format(line))
Julian Taylor4cd72742014-01-29 21:59:19166
Ralf Gommers4b0ed792015-12-29 10:29:38167
Ralf Gommersa08fb602019-05-03 14:44:23168class concat_license_files():
Ralf Gommers33415902019-05-07 09:00:50169 """Merge LICENSE.txt and LICENSES_bundled.txt for sdist creation
Ralf Gommersa08fb602019-05-03 14:44:23170
171 Done this way to keep LICENSE.txt in repo as exact BSD 3-clause (see
172 gh-13447). This makes GitHub state correctly how NumPy is licensed.
173 """
174 def __init__(self):
175 self.f1 = 'LICENSE.txt'
Ralf Gommers33415902019-05-07 09:00:50176 self.f2 = 'LICENSES_bundled.txt'
Ralf Gommersa08fb602019-05-03 14:44:23177
178 def __enter__(self):
Ralf Gommers33415902019-05-07 09:00:50179 """Concatenate files and remove LICENSES_bundled.txt"""
Ralf Gommersa08fb602019-05-03 14:44:23180 with open(self.f1, 'r') as f1:
181 self.bsd_text = f1.read()
182
183 with open(self.f1, 'a') as f1:
184 with open(self.f2, 'r') as f2:
185 self.bundled_text = f2.read()
186 f1.write('\n\n')
187 f1.write(self.bundled_text)
188
Ralf Gommersa08fb602019-05-03 14:44:23189 def __exit__(self, exception_type, exception_value, traceback):
190 """Restore content of both files"""
191 with open(self.f1, 'w') as f:
192 f.write(self.bsd_text)
193
Ralf Gommersa08fb602019-05-03 14:44:23194
Charles Harrisfed25092020-12-10 18:58:47195# Need to inherit from versioneer version of sdist to get the encoded
196# version information.
197class sdist_checked(cmdclass['sdist']):
Julian Taylor4cd72742014-01-29 21:59:19198 """ check submodules on sdist to prevent incomplete tarballs """
199 def run(self):
200 check_submodules()
Ralf Gommersa08fb602019-05-03 14:44:23201 with concat_license_files():
Charles Harrisfed25092020-12-10 18:58:47202 super().run()
Travis Oliphant14db4192005-09-14 22:08:46203
Ralf Gommers4b0ed792015-12-29 10:29:38204
mattip18af8e02020-01-04 20:47:47205def get_build_overrides():
206 """
mattipc2f93002020-01-05 15:00:30207 Custom build commands to add `-std=c99` to compilation
mattip18af8e02020-01-04 20:47:47208 """
209 from numpy.distutils.command.build_clib import build_clib
210 from numpy.distutils.command.build_ext import build_ext
Charles Harrisdf8d1fd2022-02-04 23:21:58211 from numpy.compat import _pep440
mattip18af8e02020-01-04 20:47:47212
mattip10dcfb02020-07-28 08:56:35213 def _needs_gcc_c99_flag(obj):
214 if obj.compiler.compiler_type != 'unix':
215 return False
216
217 cc = obj.compiler.compiler[0]
218 if "gcc" not in cc:
219 return False
220
221 # will print something like '4.2.1\n'
222 out = subprocess.run([cc, '-dumpversion'], stdout=subprocess.PIPE,
223 stderr=subprocess.PIPE, universal_newlines=True)
224 # -std=c99 is default from this version on
Charles Harrisdf8d1fd2022-02-04 23:21:58225 if _pep440.parse(out.stdout) >= _pep440.Version('5.0'):
mattip10dcfb02020-07-28 08:56:35226 return False
227 return True
mattip18af8e02020-01-04 20:47:47228
229 class new_build_clib(build_clib):
230 def build_a_library(self, build_info, lib_name, libraries):
serge-sans-paille91a3e3a2022-04-29 11:53:23231 from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS
mattip10dcfb02020-07-28 08:56:35232 if _needs_gcc_c99_flag(self):
serge-sans-paille2ae7aeb2021-08-19 07:28:09233 build_info['extra_cflags'] = ['-std=c99']
serge-sans-paille91a3e3a2022-04-29 11:53:23234 build_info['extra_cxxflags'] = NPY_CXX_FLAGS
mattip18af8e02020-01-04 20:47:47235 build_clib.build_a_library(self, build_info, lib_name, libraries)
236
237 class new_build_ext(build_ext):
238 def build_extension(self, ext):
mattip10dcfb02020-07-28 08:56:35239 if _needs_gcc_c99_flag(self):
mattipc2f93002020-01-05 15:00:30240 if '-std=c99' not in ext.extra_compile_args:
241 ext.extra_compile_args.append('-std=c99')
mattip18af8e02020-01-04 20:47:47242 build_ext.build_extension(self, ext)
243 return new_build_clib, new_build_ext
244
245
Julian Taylorc9fd6342014-04-05 11:13:13246def generate_cython():
Charles Harrisdf8d1fd2022-02-04 23:21:58247 # Check Cython version
248 from numpy.compat import _pep440
249 try:
250 # try the cython in the installed python first (somewhat related to
251 # scipy/scipy#2397)
252 import Cython
253 from Cython.Compiler.Version import version as cython_version
254 except ImportError as e:
255 # The `cython` command need not point to the version installed in the
256 # Python running this script, so raise an error to avoid the chance of
257 # using the wrong version of Cython.
258 msg = 'Cython needs to be installed in Python as a module'
259 raise OSError(msg) from e
260 else:
261 # Note: keep in sync with that in pyproject.toml
Mariusz Felisiak73a9e8e2022-05-16 11:43:33262 # Update for Python 3.11
Mariusz Felisiakc0696c5f22022-05-18 05:19:02263 required_version = '0.29.30'
Charles Harrisdf8d1fd2022-02-04 23:21:58264
265 if _pep440.parse(cython_version) < _pep440.Version(required_version):
266 cython_path = Cython.__file__
267 msg = 'Building NumPy requires Cython >= {}, found {} at {}'
268 msg = msg.format(required_version, cython_version, cython_path)
269 raise RuntimeError(msg)
270
271 # Process files
Julian Taylorc9fd6342014-04-05 11:13:13272 cwd = os.path.abspath(os.path.dirname(__file__))
273 print("Cythonizing sources")
mattip4e6a8122019-05-23 04:54:47274 for d in ('random',):
mattipfa8af412019-03-20 10:39:53275 p = subprocess.call([sys.executable,
Hugo van Kemenade2ebb4532020-10-04 09:41:47276 os.path.join(cwd, 'tools', 'cythonize.py'),
277 'numpy/{0}'.format(d)],
278 cwd=cwd)
mattipfa8af412019-03-20 10:39:53279 if p != 0:
280 raise RuntimeError("Running cythonize failed!")
Julian Taylorc9fd6342014-04-05 11:13:13281
Ralf Gommers4b0ed792015-12-29 10:29:38282
Ralf Gommersb9f48092015-12-29 11:05:30283def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22284 """Check the commands and respond appropriately. Disable broken commands.
285
286 Return a boolean value for whether or not to run the build or not (avoid
287 parsing Cython and template files if False).
288 """
Eric Wieserb8b2a0e2018-03-12 08:29:52289 args = sys.argv[1:]
290
291 if not args:
Ralf Gommersb9f48092015-12-29 11:05:30292 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22293 return True
Ralf Gommersb9f48092015-12-29 11:05:30294
Ralf Gommers99e99e92015-12-29 14:24:22295 info_commands = ['--help-commands', '--name', '--version', '-V',
296 '--fullname', '--author', '--author-email',
297 '--maintainer', '--maintainer-email', '--contact',
298 '--contact-email', '--url', '--license', '--description',
299 '--long-description', '--platforms', '--classifiers',
Charles Harris9b3f6502020-12-20 23:35:37300 '--keywords', '--provides', '--requires', '--obsoletes',
301 'version',]
Ralf Gommers99e99e92015-12-29 14:24:22302
303 for command in info_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52304 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22305 return False
306
307 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
308 # fine as they are, but are usually used together with one of the commands
309 # below and not standalone. Hence they're not added to good_commands.
310 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23311 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
Ralf Gommers491d26b2021-01-27 21:48:58312 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src',
313 'bdist_egg')
Ralf Gommers99e99e92015-12-29 14:24:22314
Ralf Gommersb9f48092015-12-29 11:05:30315 for command in good_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52316 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22317 return True
Ralf Gommersb9f48092015-12-29 11:05:30318
Ralf Gommersab5c6d02016-01-16 14:21:23319 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22320 # useful messages to the user
Eric Wieserb8b2a0e2018-03-12 08:29:52321 if 'install' in args:
Ralf Gommers99e99e92015-12-29 14:24:22322 print(textwrap.dedent("""
323 Note: if you need reliable uninstall behavior, then install
324 with pip instead of using `setup.py install`:
325
326 - `pip install .` (from a git repo or downloaded source
327 release)
Nihaal Sangha5ab126b2022-01-20 16:58:11328 - `pip install numpy` (last NumPy release on PyPI)
Ralf Gommers99e99e92015-12-29 14:24:22329
330 """))
331 return True
332
Eric Wieserb8b2a0e2018-03-12 08:29:52333 if '--help' in args or '-h' in sys.argv[1]:
Ralf Gommers99e99e92015-12-29 14:24:22334 print(textwrap.dedent("""
Pierre de Buyl3f6672a2016-09-06 12:54:08335 NumPy-specific help
Ralf Gommers99e99e92015-12-29 14:24:22336 -------------------
337
Pierre de Buyl3f6672a2016-09-06 12:54:08338 To install NumPy from here with reliable uninstall, we recommend
339 that you use `pip install .`. To install the latest NumPy release
Nihaal Sangha5ab126b2022-01-20 16:58:11340 from PyPI, use `pip install numpy`.
Ralf Gommers99e99e92015-12-29 14:24:22341
342 For help with build/installation issues, please ask on the
343 numpy-discussion mailing list. If you are sure that you have run
344 into a bug, please report it at https://github.com/numpy/numpy/issues.
345
346 Setuptools commands help
347 ------------------------
348 """))
349 return False
350
351 # The following commands aren't supported. They can only be executed when
352 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30353 bad_commands = dict(
354 test="""
355 `setup.py test` is not supported. Use one of the following
356 instead:
357
358 - `python runtests.py` (to build and test)
359 - `python runtests.py --no-build` (to test installed numpy)
360 - `>>> numpy.test()` (run tests for installed numpy
361 from within an interpreter)
362 """,
363 upload="""
364 `setup.py upload` is not supported, because it's insecure.
365 Instead, build what you want to upload and upload those files
366 with `twine upload -s <filenames>` instead.
367 """,
Ralf Gommersb9f48092015-12-29 11:05:30368 clean="""
369 `setup.py clean` is not supported, use one of the following instead:
370
371 - `git clean -xdf` (cleans all files)
372 - `git clean -Xdf` (cleans all versioned files, doesn't touch
373 files that aren't checked into the git repo)
374 """,
Ralf Gommers99e99e92015-12-29 14:24:22375 build_sphinx="""
376 `setup.py build_sphinx` is not supported, use the
377 Makefile under doc/""",
378 flake8="`setup.py flake8` is not supported, use flake8 standalone",
Ralf Gommersb9f48092015-12-29 11:05:30379 )
Ralf Gommers99e99e92015-12-29 14:24:22380 bad_commands['nosetests'] = bad_commands['test']
Luca Mussi69d2cc82016-04-07 11:24:49381 for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
Hugo van Kemenade2ebb4532020-10-04 09:41:47382 'register', 'check', 'install_data', 'install_headers',
383 'install_lib', 'install_scripts', ):
Ralf Gommers99e99e92015-12-29 14:24:22384 bad_commands[command] = "`setup.py %s` is not supported" % command
385
Ralf Gommersb9f48092015-12-29 11:05:30386 for command in bad_commands.keys():
Eric Wieserb8b2a0e2018-03-12 08:29:52387 if command in args:
Ralf Gommersb9f48092015-12-29 11:05:30388 print(textwrap.dedent(bad_commands[command]) +
389 "\nAdd `--force` to your command to use it anyway if you "
390 "must (unsupported).\n")
391 sys.exit(1)
392
Eric Wieserb8b2a0e2018-03-12 08:29:52393 # Commands that do more than print info, but also don't need Cython and
394 # template parsing.
Charles Harris9b3f6502020-12-20 23:35:37395 other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info']
Eric Wieserb8b2a0e2018-03-12 08:29:52396 for command in other_commands:
397 if command in args:
398 return False
399
Ralf Gommers99e99e92015-12-29 14:24:22400 # If we got here, we didn't detect what setup.py command was given
Charles Harris9b3f6502020-12-20 23:35:37401 raise RuntimeError("Unrecognized setuptools command: {}".format(args))
Ralf Gommersb9f48092015-12-29 11:05:30402
403
Eric Wieserfb47ba62020-06-20 16:28:51404def get_docs_url():
Charles Harris40fd17e2020-12-02 20:06:51405 if 'dev' in VERSION:
Eric Wieserfb47ba62020-06-20 16:28:51406 return "https://numpy.org/devdocs"
407 else:
Nihaal Sangha5ab126b2022-01-20 16:58:11408 # For releases, this URL ends up on PyPI.
Eric Wieserfb47ba62020-06-20 16:28:51409 # By pinning the version, users looking at old PyPI releases can get
410 # to the associated docs easily.
411 return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR)
412
413
Ralf Gommers17716d72013-12-06 19:45:40414def setup_package():
mattip8b266552019-07-03 22:24:42415 src_path = os.path.dirname(os.path.abspath(__file__))
Pauli Virtanen68159432009-12-06 11:56:18416 old_path = os.getcwd()
417 os.chdir(src_path)
418 sys.path.insert(0, src_path)
419
Charles Harrisf22a33b2018-08-22 17:57:48420 # The f2py scripts that will be installed
421 if sys.platform == 'win32':
422 f2py_cmds = [
423 'f2py = numpy.f2py.f2py2e:main',
424 ]
425 else:
426 f2py_cmds = [
427 'f2py = numpy.f2py.f2py2e:main',
428 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1],
429 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2],
430 ]
431
Charles Harris40fd17e2020-12-02 20:06:51432 cmdclass["sdist"] = sdist_checked
Ralf Gommers17716d72013-12-06 19:45:40433 metadata = dict(
Hugo van Kemenade2ebb4532020-10-04 09:41:47434 name='numpy',
435 maintainer="NumPy Developers",
436 maintainer_email="numpy-discussion@python.org",
437 description=DOCLINES[0],
438 long_description="\n".join(DOCLINES[2:]),
439 url="https://www.numpy.org",
440 author="Travis E. Oliphant et al.",
441 download_url="https://pypi.python.org/pypi/numpy",
Jarrod Millman0486b6d2019-04-12 01:11:21442 project_urls={
443 "Bug Tracker": "https://github.com/numpy/numpy/issues",
Eric Wieserfb47ba62020-06-20 16:28:51444 "Documentation": get_docs_url(),
Jarrod Millman0486b6d2019-04-12 01:11:21445 "Source Code": "https://github.com/numpy/numpy",
446 },
Hugo van Kemenade2ebb4532020-10-04 09:41:47447 license='BSD',
Ralf Gommers17716d72013-12-06 19:45:40448 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
Hugo van Kemenade2ebb4532020-10-04 09:41:47449 platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
Charles Harrisb3b6cc02020-05-18 22:26:10450 test_suite='pytest',
Charles Harris40fd17e2020-12-02 20:06:51451 version=versioneer.get_version(),
mattip18af8e02020-01-04 20:47:47452 cmdclass=cmdclass,
Charles Harris9a176d02021-08-13 15:53:41453 python_requires='>=3.8',
Nathaniel J. Smithf46e7162018-01-23 08:02:04454 zip_safe=False,
Charles Harrisf22a33b2018-08-22 17:57:48455 entry_points={
Matthew Barberdf6d2852021-08-31 09:23:14456 'console_scripts': f2py_cmds,
457 'array_api': ['numpy = numpy.array_api'],
bwoodsendbac9d0e2022-01-06 00:55:16458 'pyinstaller40': ['hook-dirs = numpy:_pyinstaller_hooks_dir'],
Charles Harrisf22a33b2018-08-22 17:57:48459 },
Ralf Gommers17716d72013-12-06 19:45:40460 )
461
Ralf Gommers99e99e92015-12-29 14:24:22462 if "--force" in sys.argv:
463 run_build = True
Ralf Gommers20c3c2a2017-06-20 10:09:40464 sys.argv.remove('--force')
Ralf Gommers99e99e92015-12-29 14:24:22465 else:
466 # Raise errors for unsupported commands, improve help output, etc.
467 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30468
Charles Harris9b3f6502020-12-20 23:35:37469 if run_build:
Mike Taves07bf33f2020-02-04 19:21:51470 # patches distutils, even though we don't use it
Charles Harris40fd17e2020-12-02 20:06:51471 #from setuptools import setup
Ralf Gommers17716d72013-12-06 19:45:40472 from numpy.distutils.core import setup
Charles Harris40fd17e2020-12-02 20:06:51473
Hugo van Kemenade2ebb4532020-10-04 09:41:47474 if 'sdist' not in sys.argv:
Ralf Gommersd630d962019-09-08 05:01:41475 # Generate Cython sources, unless we're generating an sdist
Julian Taylorc9fd6342014-04-05 11:13:13476 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38477
Ralf Gommers17716d72013-12-06 19:45:40478 metadata['configuration'] = configuration
mattip18af8e02020-01-04 20:47:47479 # Customize extension building
480 cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
Ralf Gommers99e99e92015-12-29 14:24:22481 else:
Charles Harris40fd17e2020-12-02 20:06:51482 #from numpy.distutils.core import setup
Mike Taves07bf33f2020-02-04 19:21:51483 from setuptools import setup
Pauli Virtanen68159432009-12-06 11:56:18484
Pearu Petersone8fa0132003-03-07 18:08:28485 try:
Ralf Gommers17716d72013-12-06 19:45:40486 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28487 finally:
488 del sys.path[0]
489 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46490 return
Pearu Petersonc415fd12002-11-18 22:39:31491
Ralf Gommers17716d72013-12-06 19:45:40492
Travis Oliphant14db4192005-09-14 22:08:46493if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28494 setup_package()
Ralf Gommersbbee7472016-08-21 05:23:35495 # This may avoid problems where numpy is installed via ``*_requires`` by
496 # setuptools, the global namespace isn't reset properly, and then numpy is
497 # imported later (which will then fail to load numpy extension modules).
498 # See gh-7956 for details
499 del builtins.__NUMPY_SETUP__