blob: 6bd2153d78353bf3691a30f200c5d0fa596ecdba [file] [log] [blame]
Changqing Li583901a2020-03-04 08:22:401#!/usr/bin/env python3
Travis Oliphantda9c6da2006-01-04 17:31:072"""
Sebastian Bergdab75722022-11-25 12:43:093Numpy build options can be modified with a site.cfg file.
hannah6c2fa302022-11-01 16:28:364See site.cfg.example for a template and more information.
5"""
Pearu Petersonc415fd12002-11-18 22:39:316
Pearu Petersone8fa0132003-03-07 18:08:287import os
hannahce57eea2022-10-31 03:00:038from pathlib import Path
Pearu Petersone8fa0132003-03-07 18:08:289import sys
David Cournapeau5623a7c2009-04-02 16:21:3010import subprocess
Ralf Gommers99e99e92015-12-29 14:24:2211import textwrap
Hugo van Kemenadef3a6b332020-10-04 09:09:5212import warnings
Charles Harris40fd17e2020-12-02 20:06:5113import builtins
Charles Harris9a37cd92021-05-25 19:35:4214import re
Sayed Adeld183edf2023-03-15 19:24:0415import tempfile
Pearu Petersonc415fd12002-11-18 22:39:3116
Sayed Adeld183edf2023-03-15 19:24:0417from distutils.errors import CompileError
Ralf Gommersf66d5db2020-12-22 20:11:5018
19# Python supported version checks. Keep right after stdlib imports to ensure we
20# get a sensible error for older Python versions
mattip40a920d2023-01-26 06:18:2021if sys.version_info[:2] < (3, 9):
22 raise RuntimeError("Python version >= 3.9 required.")
Ralf Gommersf66d5db2020-12-22 20:11:5023
24
Charles Harris40fd17e2020-12-02 20:06:5125# This is a bit hackish: we are setting a global variable so that the main
26# numpy __init__ can detect if it is being loaded by the setup routine, to
27# avoid attempting to load components that aren't built yet. While ugly, it's
28# a lot more robust than what was previously being used.
29builtins.__NUMPY_SETUP__ = True
Ralf Gommers17716d72013-12-06 19:45:4030
Charles Harris40fd17e2020-12-02 20:06:5131# Needed for backwards code compatibility below and in some CI scripts.
32# The version components are changed from ints to strings, but only VERSION
33# seems to matter outside of this module and it was already a str.
Stefan van der Walt7eb8cd92023-08-11 20:40:1634FULLVERSION = subprocess.check_output([
35 sys.executable,
36 'numpy/_build_utils/gitversion.py'
37]).strip().decode('ascii')
38
39# Write git version to disk
40subprocess.check_output([
41 sys.executable,
42 'numpy/_build_utils/gitversion.py', '--write', 'numpy/version.py'
43])
Charles Harris9a37cd92021-05-25 19:35:4244
45# Capture the version string:
46# 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0
47# 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0
48# 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0
49# 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0
50ISRELEASED = re.search(r'(dev|\+)', FULLVERSION) is None
Matthew Brett9db73b52021-10-23 11:05:3151_V_MATCH = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION)
52if _V_MATCH is None:
53 raise RuntimeError(f'Cannot parse version {FULLVERSION}')
54MAJOR, MINOR, MICRO = _V_MATCH.groups()
Charles Harris40fd17e2020-12-02 20:06:5155VERSION = '{}.{}.{}'.format(MAJOR, MINOR, MICRO)
56
Dimitri Papadopoulos Orfanos3cf2ca12022-10-07 19:34:4757# The first version not in the `Programming Language :: Python :: ...` classifiers below
Charles Harrisf06a3152022-08-17 14:36:0458if sys.version_info >= (3, 12):
Charles Harrisca11e4e2020-12-12 15:17:0159 fmt = "NumPy {} may not yet support Python {}.{}."
Charles Harris40fd17e2020-12-02 20:06:5160 warnings.warn(
Charles Harrisca11e4e2020-12-12 15:17:0161 fmt.format(VERSION, *sys.version_info[:2]),
62 RuntimeWarning)
63 del fmt
David Cournapeau2b517692009-12-03 15:53:2964
Charles Harris40fd17e2020-12-02 20:06:5165# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
66# properly updated when the contents of directories change (true for distutils,
67# not sure about setuptools).
68if os.path.exists('MANIFEST'):
69 os.remove('MANIFEST')
70
71# We need to import setuptools here in order for it to persist in sys.modules.
Charles Harrisfed25092020-12-10 18:58:4772# Its presence/absence is used in subclassing setup in numpy/distutils/core.py.
73# However, we need to run the distutils version of sdist, so import that first
74# so that it is in sys.modules
75import numpy.distutils.command.sdist
Charles Harris40fd17e2020-12-02 20:06:5176import setuptools
Charles Harrisc62e1db2022-01-06 23:51:2077if int(setuptools.__version__.split('.')[0]) >= 60:
Andrew J. Hesforddedc0952022-02-01 15:34:2678 # setuptools >= 60 switches to vendored distutils by default; this
79 # may break the numpy build, so make sure the stdlib version is used
80 try:
81 setuptools_use_distutils = os.environ['SETUPTOOLS_USE_DISTUTILS']
82 except KeyError:
83 os.environ['SETUPTOOLS_USE_DISTUTILS'] = "stdlib"
84 else:
85 if setuptools_use_distutils != "stdlib":
86 raise RuntimeError("setuptools versions >= '60.0.0' require "
87 "SETUPTOOLS_USE_DISTUTILS=stdlib in the environment")
Charles Harris40fd17e2020-12-02 20:06:5188
Travis Oliphantda9c6da2006-01-04 17:31:0789CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4490Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0791Intended Audience :: Science/Research
92Intended Audience :: Developers
johnthagen5cb80d62020-10-22 12:43:0393License :: OSI Approved :: BSD License
Travis Oliphantda9c6da2006-01-04 17:31:0794Programming Language :: C
95Programming Language :: Python
rgommerscdac1202011-01-25 14:02:4096Programming Language :: Python :: 3
Hugo van Kemenade79a8e162020-10-04 11:59:5397Programming Language :: Python :: 3.9
Charles Harris9a176d02021-08-13 15:53:4198Programming Language :: Python :: 3.10
Charles Harrisf06a3152022-08-17 14:36:0499Programming Language :: Python :: 3.11
Jon Dufresne334201d2019-08-27 04:18:35100Programming Language :: Python :: 3 :: Only
Alex Willmer193668a2015-08-05 09:29:39101Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:07102Topic :: Software Development
103Topic :: Scientific/Engineering
Bas van Beeke592c272020-10-04 13:10:42104Typing :: Typed
Travis Oliphantda9c6da2006-01-04 17:31:07105Operating System :: Microsoft :: Windows
106Operating System :: POSIX
107Operating System :: Unix
108Operating System :: MacOS
109"""
110
Hugo van Kemenade2ebb4532020-10-04 09:41:47111def configuration(parent_package='', top_path=None):
Pearu Peterson471196b2006-03-31 08:59:36112 from numpy.distutils.misc_util import Configuration
113
Pearu Peterson17d7cfe2006-04-04 12:26:14114 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36115 config.set_options(ignore_setup_xxx_py=True,
116 assume_default_configuration=True,
117 delegate_options_to_subpackages=True,
118 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18119
Pearu Peterson471196b2006-03-31 08:59:36120 config.add_subpackage('numpy')
Charles Harris054d93a2017-11-29 18:53:21121 config.add_data_files(('numpy', 'LICENSE.txt'))
scodere1211b82020-08-05 04:28:30122 config.add_data_files(('numpy', 'numpy/*.pxd'))
Jarrod Millman0b77f0e2007-10-29 14:58:18123
Hugo van Kemenade2ebb4532020-10-04 09:41:47124 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01125
Pearu Peterson471196b2006-03-31 08:59:36126 return config
127
Ralf Gommers4b0ed792015-12-29 10:29:38128
Julian Taylor4cd72742014-01-29 21:59:19129def check_submodules():
130 """ verify that the submodules are checked out and clean
131 use `git submodule update --init`; on failure
132 """
133 if not os.path.exists('.git'):
134 return
135 with open('.gitmodules') as f:
Hugo van Kemenade2ebb4532020-10-04 09:41:47136 for line in f:
137 if 'path' in line:
138 p = line.split('=')[-1].strip()
Julian Taylor4cd72742014-01-29 21:59:19139 if not os.path.exists(p):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08140 raise ValueError('Submodule {} missing'.format(p))
Julian Taylor4cd72742014-01-29 21:59:19141
Julian Taylor4cd72742014-01-29 21:59:19142 proc = subprocess.Popen(['git', 'submodule', 'status'],
143 stdout=subprocess.PIPE)
144 status, _ = proc.communicate()
145 status = status.decode("ascii", "replace")
146 for line in status.splitlines():
147 if line.startswith('-') or line.startswith('+'):
Wojciech Rzadkowskidabf31c2020-05-22 15:43:08148 raise ValueError('Submodule not clean: {}'.format(line))
Julian Taylor4cd72742014-01-29 21:59:19149
Ralf Gommers4b0ed792015-12-29 10:29:38150
Ralf Gommersa08fb602019-05-03 14:44:23151class concat_license_files():
Ralf Gommers33415902019-05-07 09:00:50152 """Merge LICENSE.txt and LICENSES_bundled.txt for sdist creation
Ralf Gommersa08fb602019-05-03 14:44:23153
154 Done this way to keep LICENSE.txt in repo as exact BSD 3-clause (see
155 gh-13447). This makes GitHub state correctly how NumPy is licensed.
156 """
157 def __init__(self):
158 self.f1 = 'LICENSE.txt'
Ralf Gommers33415902019-05-07 09:00:50159 self.f2 = 'LICENSES_bundled.txt'
Ralf Gommersa08fb602019-05-03 14:44:23160
161 def __enter__(self):
Ralf Gommers33415902019-05-07 09:00:50162 """Concatenate files and remove LICENSES_bundled.txt"""
Mike Taves080cf822022-10-28 09:37:29163 with open(self.f1) as f1:
Ralf Gommersa08fb602019-05-03 14:44:23164 self.bsd_text = f1.read()
165
166 with open(self.f1, 'a') as f1:
Mike Taves080cf822022-10-28 09:37:29167 with open(self.f2) as f2:
Ralf Gommersa08fb602019-05-03 14:44:23168 self.bundled_text = f2.read()
169 f1.write('\n\n')
170 f1.write(self.bundled_text)
171
Ralf Gommersa08fb602019-05-03 14:44:23172 def __exit__(self, exception_type, exception_value, traceback):
173 """Restore content of both files"""
174 with open(self.f1, 'w') as f:
175 f.write(self.bsd_text)
176
Charles Harrisfed25092020-12-10 18:58:47177# Need to inherit from versioneer version of sdist to get the encoded
178# version information.
Stefan van der Walt7eb8cd92023-08-11 20:40:16179class sdist_checked:
Julian Taylor4cd72742014-01-29 21:59:19180 """ check submodules on sdist to prevent incomplete tarballs """
181 def run(self):
182 check_submodules()
Ralf Gommersa08fb602019-05-03 14:44:23183 with concat_license_files():
Charles Harrisfed25092020-12-10 18:58:47184 super().run()
Travis Oliphant14db4192005-09-14 22:08:46185
Ralf Gommers4b0ed792015-12-29 10:29:38186
mattip18af8e02020-01-04 20:47:47187def get_build_overrides():
188 """
Sayed Adeld183edf2023-03-15 19:24:04189 Custom build commands to add std flags if required to compilation
mattip18af8e02020-01-04 20:47:47190 """
191 from numpy.distutils.command.build_clib import build_clib
192 from numpy.distutils.command.build_ext import build_ext
Sebastian Bergdab75722022-11-25 12:43:09193 from numpy._utils import _pep440
mattip18af8e02020-01-04 20:47:47194
Sayed Adeld183edf2023-03-15 19:24:04195 def try_compile(compiler, file, flags = [], verbose=False):
Sayed Adeld183edf2023-03-15 19:24:04196 bk_ver = getattr(compiler, 'verbose', False)
197 compiler.verbose = verbose
198 try:
199 compiler.compile([file], extra_postargs=flags)
200 return True, ''
201 except CompileError as e:
202 return False, str(e)
203 finally:
204 compiler.verbose = bk_ver
mattip10dcfb02020-07-28 08:56:35205
Sayed Adeld183edf2023-03-15 19:24:04206 def flags_is_required(compiler, is_cpp, flags, code):
207 if is_cpp:
208 compiler = compiler.cxx_compiler()
209 suf = '.cpp'
210 else:
211 suf = '.c'
212 with tempfile.TemporaryDirectory() as temp_dir:
213 tmp_file = os.path.join(temp_dir, "test" + suf)
214 with open(tmp_file, "w+") as f:
215 f.write(code)
216 # without specify any flags in case of the required
217 # standard already supported by default, then there's
218 # no need for passing the flags
219 comp = try_compile(compiler, tmp_file)
220 if not comp[0]:
221 comp = try_compile(compiler, tmp_file, flags)
222 if not comp[0]:
223 # rerun to verbose the error
224 try_compile(compiler, tmp_file, flags, True)
225 if is_cpp:
226 raise RuntimeError(
227 "Broken toolchain during testing C++ compiler. \n"
228 "A compiler with support for C++17 language "
229 "features is required.\n"
230 f"Triggered the following error: {comp[1]}."
231 )
232 else:
233 raise RuntimeError(
234 "Broken toolchain during testing C compiler. \n"
235 "A compiler with support for C99 language "
236 "features is required.\n"
237 f"Triggered the following error: {comp[1]}."
238 )
239 return True
240 return False
mattip10dcfb02020-07-28 08:56:35241
Sayed Adeld183edf2023-03-15 19:24:04242 def std_cxx_flags(cmd):
243 compiler = cmd.compiler
244 flags = getattr(compiler, '__np_cache_cpp_flags', None)
245 if flags is not None:
246 return flags
247 flags = dict(
248 msvc = ['/std:c++17']
249 ).get(compiler.compiler_type, ['-std=c++17'])
250 # These flags are used to compile any C++ source within Numpy.
251 # They are chosen to have very few runtime dependencies.
252 extra_flags = dict(
253 # to update #def __cplusplus with enabled C++ version
254 msvc = ['/Zc:__cplusplus']
255 ).get(compiler.compiler_type, [
256 # The following flag is used to avoid emit any extra code
257 # from STL since extensions are build by C linker and
258 # without C++ runtime dependencies.
259 '-fno-threadsafe-statics',
260 '-D__STDC_VERSION__=0', # for compatibility with C headers
261 '-fno-exceptions', # no exception support
262 '-fno-rtti' # no runtime type information
263 ])
264 if not flags_is_required(compiler, True, flags, textwrap.dedent('''
265 #include <type_traits>
266 template<typename ...T>
267 constexpr bool test_fold = (... && std::is_const_v<T>);
268 int main()
269 {
Sayed Adelbcc9c512023-04-24 09:24:03270 if (test_fold<int, const int>) {
Sayed Adeld183edf2023-03-15 19:24:04271 return 0;
272 }
273 else {
274 return -1;
275 }
276 }
277 ''')):
278 flags.clear()
279 flags += extra_flags
280 setattr(compiler, '__np_cache_cpp_flags', flags)
281 return flags
282
283 def std_c_flags(cmd):
284 compiler = cmd.compiler
285 flags = getattr(compiler, '__np_cache_c_flags', None)
286 if flags is not None:
287 return flags
288 flags = dict(
289 msvc = []
290 ).get(compiler.compiler_type, ['-std=c99'])
291
292 if not flags_is_required(compiler, False, flags, textwrap.dedent('''
Andrew Nelsonc9229a32023-04-07 23:53:26293 inline static int test_inline() { return 0; }
Sayed Adeld183edf2023-03-15 19:24:04294 int main(void)
295 { return test_inline(); }
296 ''')):
297 flags.clear()
298
299 setattr(compiler, '__np_cache_c_flags', flags)
300 return flags
mattip18af8e02020-01-04 20:47:47301
302 class new_build_clib(build_clib):
303 def build_a_library(self, build_info, lib_name, libraries):
Sayed Adeld183edf2023-03-15 19:24:04304 build_info['extra_cflags'] = std_c_flags(self)
305 build_info['extra_cxxflags'] = std_cxx_flags(self)
mattip18af8e02020-01-04 20:47:47306 build_clib.build_a_library(self, build_info, lib_name, libraries)
307
308 class new_build_ext(build_ext):
309 def build_extension(self, ext):
Sayed Adeld183edf2023-03-15 19:24:04310 ext.extra_c_compile_args += std_c_flags(self)
311 ext.extra_cxx_compile_args += std_cxx_flags(self)
mattip18af8e02020-01-04 20:47:47312 build_ext.build_extension(self, ext)
313 return new_build_clib, new_build_ext
314
Julian Taylorc9fd6342014-04-05 11:13:13315def generate_cython():
Charles Harrisdf8d1fd2022-02-04 23:21:58316 # Check Cython version
Sebastian Bergdab75722022-11-25 12:43:09317 from numpy._utils import _pep440
Charles Harrisdf8d1fd2022-02-04 23:21:58318 try:
319 # try the cython in the installed python first (somewhat related to
320 # scipy/scipy#2397)
321 import Cython
322 from Cython.Compiler.Version import version as cython_version
323 except ImportError as e:
324 # The `cython` command need not point to the version installed in the
325 # Python running this script, so raise an error to avoid the chance of
326 # using the wrong version of Cython.
327 msg = 'Cython needs to be installed in Python as a module'
328 raise OSError(msg) from e
329 else:
330 # Note: keep in sync with that in pyproject.toml
Mariusz Felisiak73a9e8e2022-05-16 11:43:33331 # Update for Python 3.11
Mariusz Felisiakc0696c5f22022-05-18 05:19:02332 required_version = '0.29.30'
Charles Harrisdf8d1fd2022-02-04 23:21:58333
334 if _pep440.parse(cython_version) < _pep440.Version(required_version):
335 cython_path = Cython.__file__
336 msg = 'Building NumPy requires Cython >= {}, found {} at {}'
337 msg = msg.format(required_version, cython_version, cython_path)
338 raise RuntimeError(msg)
339
340 # Process files
Julian Taylorc9fd6342014-04-05 11:13:13341 cwd = os.path.abspath(os.path.dirname(__file__))
342 print("Cythonizing sources")
mattip4e6a8122019-05-23 04:54:47343 for d in ('random',):
mattipfa8af412019-03-20 10:39:53344 p = subprocess.call([sys.executable,
Hugo van Kemenade2ebb4532020-10-04 09:41:47345 os.path.join(cwd, 'tools', 'cythonize.py'),
346 'numpy/{0}'.format(d)],
347 cwd=cwd)
mattipfa8af412019-03-20 10:39:53348 if p != 0:
349 raise RuntimeError("Running cythonize failed!")
Julian Taylorc9fd6342014-04-05 11:13:13350
Ralf Gommers4b0ed792015-12-29 10:29:38351
Ralf Gommersb9f48092015-12-29 11:05:30352def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22353 """Check the commands and respond appropriately. Disable broken commands.
354
355 Return a boolean value for whether or not to run the build or not (avoid
356 parsing Cython and template files if False).
357 """
Eric Wieserb8b2a0e2018-03-12 08:29:52358 args = sys.argv[1:]
359
360 if not args:
Ralf Gommersb9f48092015-12-29 11:05:30361 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22362 return True
Ralf Gommersb9f48092015-12-29 11:05:30363
Ralf Gommers99e99e92015-12-29 14:24:22364 info_commands = ['--help-commands', '--name', '--version', '-V',
365 '--fullname', '--author', '--author-email',
366 '--maintainer', '--maintainer-email', '--contact',
367 '--contact-email', '--url', '--license', '--description',
368 '--long-description', '--platforms', '--classifiers',
Charles Harris9b3f6502020-12-20 23:35:37369 '--keywords', '--provides', '--requires', '--obsoletes',
370 'version',]
Ralf Gommers99e99e92015-12-29 14:24:22371
372 for command in info_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52373 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22374 return False
375
376 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
377 # fine as they are, but are usually used together with one of the commands
378 # below and not standalone. Hence they're not added to good_commands.
379 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23380 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
Ralf Gommers491d26b2021-01-27 21:48:58381 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src',
382 'bdist_egg')
Ralf Gommers99e99e92015-12-29 14:24:22383
Ralf Gommersb9f48092015-12-29 11:05:30384 for command in good_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52385 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22386 return True
Ralf Gommersb9f48092015-12-29 11:05:30387
Ralf Gommersab5c6d02016-01-16 14:21:23388 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22389 # useful messages to the user
Eric Wieserb8b2a0e2018-03-12 08:29:52390 if 'install' in args:
Ralf Gommers99e99e92015-12-29 14:24:22391 print(textwrap.dedent("""
392 Note: if you need reliable uninstall behavior, then install
393 with pip instead of using `setup.py install`:
394
395 - `pip install .` (from a git repo or downloaded source
396 release)
Nihaal Sangha5ab126b2022-01-20 16:58:11397 - `pip install numpy` (last NumPy release on PyPI)
Ralf Gommers99e99e92015-12-29 14:24:22398
399 """))
400 return True
401
Eric Wieserb8b2a0e2018-03-12 08:29:52402 if '--help' in args or '-h' in sys.argv[1]:
Ralf Gommers99e99e92015-12-29 14:24:22403 print(textwrap.dedent("""
Pierre de Buyl3f6672a2016-09-06 12:54:08404 NumPy-specific help
Ralf Gommers99e99e92015-12-29 14:24:22405 -------------------
406
Pierre de Buyl3f6672a2016-09-06 12:54:08407 To install NumPy from here with reliable uninstall, we recommend
408 that you use `pip install .`. To install the latest NumPy release
Nihaal Sangha5ab126b2022-01-20 16:58:11409 from PyPI, use `pip install numpy`.
Ralf Gommers99e99e92015-12-29 14:24:22410
411 For help with build/installation issues, please ask on the
412 numpy-discussion mailing list. If you are sure that you have run
413 into a bug, please report it at https://github.com/numpy/numpy/issues.
414
415 Setuptools commands help
416 ------------------------
417 """))
418 return False
419
420 # The following commands aren't supported. They can only be executed when
421 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30422 bad_commands = dict(
423 test="""
424 `setup.py test` is not supported. Use one of the following
425 instead:
426
427 - `python runtests.py` (to build and test)
428 - `python runtests.py --no-build` (to test installed numpy)
429 - `>>> numpy.test()` (run tests for installed numpy
430 from within an interpreter)
431 """,
432 upload="""
433 `setup.py upload` is not supported, because it's insecure.
434 Instead, build what you want to upload and upload those files
435 with `twine upload -s <filenames>` instead.
436 """,
Ralf Gommersb9f48092015-12-29 11:05:30437 clean="""
438 `setup.py clean` is not supported, use one of the following instead:
439
440 - `git clean -xdf` (cleans all files)
441 - `git clean -Xdf` (cleans all versioned files, doesn't touch
442 files that aren't checked into the git repo)
443 """,
Ralf Gommers99e99e92015-12-29 14:24:22444 build_sphinx="""
445 `setup.py build_sphinx` is not supported, use the
446 Makefile under doc/""",
447 flake8="`setup.py flake8` is not supported, use flake8 standalone",
Ralf Gommersb9f48092015-12-29 11:05:30448 )
Ralf Gommers99e99e92015-12-29 14:24:22449 bad_commands['nosetests'] = bad_commands['test']
Luca Mussi69d2cc82016-04-07 11:24:49450 for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
Hugo van Kemenade2ebb4532020-10-04 09:41:47451 'register', 'check', 'install_data', 'install_headers',
452 'install_lib', 'install_scripts', ):
Ralf Gommers99e99e92015-12-29 14:24:22453 bad_commands[command] = "`setup.py %s` is not supported" % command
454
Ralf Gommersb9f48092015-12-29 11:05:30455 for command in bad_commands.keys():
Eric Wieserb8b2a0e2018-03-12 08:29:52456 if command in args:
Ralf Gommersb9f48092015-12-29 11:05:30457 print(textwrap.dedent(bad_commands[command]) +
458 "\nAdd `--force` to your command to use it anyway if you "
459 "must (unsupported).\n")
460 sys.exit(1)
461
Eric Wieserb8b2a0e2018-03-12 08:29:52462 # Commands that do more than print info, but also don't need Cython and
463 # template parsing.
Charles Harris9b3f6502020-12-20 23:35:37464 other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info']
Eric Wieserb8b2a0e2018-03-12 08:29:52465 for command in other_commands:
466 if command in args:
467 return False
468
Ralf Gommers99e99e92015-12-29 14:24:22469 # If we got here, we didn't detect what setup.py command was given
Charles Harris9b3f6502020-12-20 23:35:37470 raise RuntimeError("Unrecognized setuptools command: {}".format(args))
Ralf Gommersb9f48092015-12-29 11:05:30471
472
Eric Wieserfb47ba62020-06-20 16:28:51473def get_docs_url():
Charles Harris40fd17e2020-12-02 20:06:51474 if 'dev' in VERSION:
Eric Wieserfb47ba62020-06-20 16:28:51475 return "https://numpy.org/devdocs"
476 else:
Nihaal Sangha5ab126b2022-01-20 16:58:11477 # For releases, this URL ends up on PyPI.
Eric Wieserfb47ba62020-06-20 16:28:51478 # By pinning the version, users looking at old PyPI releases can get
479 # to the associated docs easily.
480 return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR)
481
482
Stefan van der Walt7eb8cd92023-08-11 20:40:16483from numpy.distutils.core import numpy_cmdclass as cmdclass
484
Ralf Gommers17716d72013-12-06 19:45:40485def setup_package():
mattip8b266552019-07-03 22:24:42486 src_path = os.path.dirname(os.path.abspath(__file__))
Pauli Virtanen68159432009-12-06 11:56:18487 old_path = os.getcwd()
488 os.chdir(src_path)
489 sys.path.insert(0, src_path)
490
Charles Harrisf22a33b2018-08-22 17:57:48491 # The f2py scripts that will be installed
492 if sys.platform == 'win32':
493 f2py_cmds = [
494 'f2py = numpy.f2py.f2py2e:main',
495 ]
496 else:
497 f2py_cmds = [
498 'f2py = numpy.f2py.f2py2e:main',
499 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1],
500 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2],
501 ]
502
Ralf Gommers17716d72013-12-06 19:45:40503 metadata = dict(
Hugo van Kemenade2ebb4532020-10-04 09:41:47504 name='numpy',
505 maintainer="NumPy Developers",
506 maintainer_email="numpy-discussion@python.org",
hannah6c2fa302022-11-01 16:28:36507 description="Fundamental package for array computing in Python",
508 long_description=Path("README.md").read_text(encoding="utf-8"),
hannahce57eea2022-10-31 03:00:03509 long_description_content_type="text/markdown",
Hugo van Kemenade2ebb4532020-10-04 09:41:47510 url="https://www.numpy.org",
511 author="Travis E. Oliphant et al.",
512 download_url="https://pypi.python.org/pypi/numpy",
Jarrod Millman0486b6d2019-04-12 01:11:21513 project_urls={
514 "Bug Tracker": "https://github.com/numpy/numpy/issues",
Eric Wieserfb47ba62020-06-20 16:28:51515 "Documentation": get_docs_url(),
Jarrod Millman0486b6d2019-04-12 01:11:21516 "Source Code": "https://github.com/numpy/numpy",
517 },
Frazer McLean033503c2022-10-28 16:53:09518 license='BSD-3-Clause',
Ralf Gommers17716d72013-12-06 19:45:40519 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
Hugo van Kemenade2ebb4532020-10-04 09:41:47520 platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
Charles Harrisb3b6cc02020-05-18 22:26:10521 test_suite='pytest',
Stefan van der Walt7eb8cd92023-08-11 20:40:16522 version=VERSION,
mattip18af8e02020-01-04 20:47:47523 cmdclass=cmdclass,
Clément Roberte570c6f2023-03-14 10:24:19524 python_requires='>=3.9',
Nathaniel J. Smithf46e7162018-01-23 08:02:04525 zip_safe=False,
Charles Harrisf22a33b2018-08-22 17:57:48526 entry_points={
Matthew Barberdf6d2852021-08-31 09:23:14527 'console_scripts': f2py_cmds,
528 'array_api': ['numpy = numpy.array_api'],
bwoodsendbac9d0e2022-01-06 00:55:16529 'pyinstaller40': ['hook-dirs = numpy:_pyinstaller_hooks_dir'],
Charles Harrisf22a33b2018-08-22 17:57:48530 },
Ralf Gommers17716d72013-12-06 19:45:40531 )
532
Ralf Gommers99e99e92015-12-29 14:24:22533 if "--force" in sys.argv:
534 run_build = True
Ralf Gommers20c3c2a2017-06-20 10:09:40535 sys.argv.remove('--force')
Ralf Gommers99e99e92015-12-29 14:24:22536 else:
537 # Raise errors for unsupported commands, improve help output, etc.
538 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30539
Charles Harris9b3f6502020-12-20 23:35:37540 if run_build:
Mike Taves07bf33f2020-02-04 19:21:51541 # patches distutils, even though we don't use it
Charles Harris40fd17e2020-12-02 20:06:51542 #from setuptools import setup
Ralf Gommers17716d72013-12-06 19:45:40543 from numpy.distutils.core import setup
Charles Harris40fd17e2020-12-02 20:06:51544
Hugo van Kemenade2ebb4532020-10-04 09:41:47545 if 'sdist' not in sys.argv:
Ralf Gommersd630d962019-09-08 05:01:41546 # Generate Cython sources, unless we're generating an sdist
Julian Taylorc9fd6342014-04-05 11:13:13547 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38548
Ralf Gommers17716d72013-12-06 19:45:40549 metadata['configuration'] = configuration
mattip18af8e02020-01-04 20:47:47550 # Customize extension building
551 cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
Ralf Gommers99e99e92015-12-29 14:24:22552 else:
Charles Harris40fd17e2020-12-02 20:06:51553 #from numpy.distutils.core import setup
Mike Taves07bf33f2020-02-04 19:21:51554 from setuptools import setup
Stefan van der Waltfe31f6b2022-11-29 18:38:53555 # workaround for broken --no-build-isolation with newer setuptools,
556 # see gh-21288
Ralf Gommersbf148bf2022-11-29 11:04:04557 metadata["packages"] = []
Pauli Virtanen68159432009-12-06 11:56:18558
Pearu Petersone8fa0132003-03-07 18:08:28559 try:
Ralf Gommers17716d72013-12-06 19:45:40560 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28561 finally:
562 del sys.path[0]
563 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46564 return
Pearu Petersonc415fd12002-11-18 22:39:31565
Ralf Gommers17716d72013-12-06 19:45:40566
Travis Oliphant14db4192005-09-14 22:08:46567if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28568 setup_package()
Ralf Gommersbbee7472016-08-21 05:23:35569 # This may avoid problems where numpy is installed via ``*_requires`` by
570 # setuptools, the global namespace isn't reset properly, and then numpy is
571 # imported later (which will then fail to load numpy extension modules).
572 # See gh-7956 for details
573 del builtins.__NUMPY_SETUP__