blob: 139a355800aaeb63451c47fd0c6d53f6b5bf75d7 [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
Travis Oliphantda9c6da2006-01-04 17:31:0719"""
David Sanders922442f2015-10-19 20:03:3420DOCLINES = (__doc__ or '').split("\n")
Pearu Petersonc415fd12002-11-18 22:39:3121
Pearu Petersone8fa0132003-03-07 18:08:2822import os
23import sys
David Cournapeau5623a7c2009-04-02 16:21:3024import subprocess
Ralf Gommers99e99e92015-12-29 14:24:2225import textwrap
Hugo van Kemenade595af822020-10-04 09:41:4726import sysconfig
Hugo van Kemenade53393312020-10-04 09:09:5227import warnings
Pearu Petersonc415fd12002-11-18 22:39:3128
Ralf Gommers17716d72013-12-06 19:45:4029
Hugo van Kemenade595af822020-10-04 09:41:4730
Charles Harrisfbcb58c2019-12-03 23:45:0931if sys.version_info[:2] < (3, 6):
32 raise RuntimeError("Python version >= 3.6 required.")
Charles Harris28eadc02013-07-11 18:08:4933
Charles Harrisbadf2902018-12-07 21:16:2634import builtins
David Cournapeau2b517692009-12-03 15:53:2935
Ralf Gommers17716d72013-12-06 19:45:4036
Travis Oliphantda9c6da2006-01-04 17:31:0737CLASSIFIERS = """\
Robert Kern19da9712008-06-18 22:53:4438Development Status :: 5 - Production/Stable
Travis Oliphantda9c6da2006-01-04 17:31:0739Intended Audience :: Science/Research
40Intended Audience :: Developers
41License :: OSI Approved
42Programming Language :: C
43Programming Language :: Python
rgommerscdac1202011-01-25 14:02:4044Programming Language :: Python :: 3
Charles Harrisb33a5ee2016-11-05 19:48:3045Programming Language :: Python :: 3.6
Ralf Gommers943695b2018-06-28 02:26:1946Programming Language :: Python :: 3.7
Grzegorz Bokotac861a362019-10-24 18:29:0947Programming Language :: Python :: 3.8
Hugo van Kemenade53393312020-10-04 09:09:5248Programming Language :: Python :: 3.9
Jon Dufresne334201d2019-08-27 04:18:3549Programming Language :: Python :: 3 :: Only
Alex Willmer193668a2015-08-05 09:29:3950Programming Language :: Python :: Implementation :: CPython
Travis Oliphantda9c6da2006-01-04 17:31:0751Topic :: Software Development
52Topic :: Scientific/Engineering
53Operating System :: Microsoft :: Windows
54Operating System :: POSIX
55Operating System :: Unix
56Operating System :: MacOS
57"""
58
Ralf Gommers58c1bf72012-11-05 19:47:2359MAJOR = 1
Charles Harrisfbcb58c2019-12-03 23:45:0960MINOR = 19
Charles Harris06a646e2020-09-10 17:37:1261MICRO = 3
Charles Harris50101772020-10-28 21:27:0562ISRELEASED = True
Charles Harris1b5d0d12020-05-31 23:04:5863VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Stefan van der Waltb9a22d72009-06-17 14:28:0364
Hugo van Kemenade53393312020-10-04 09:09:5265# The first version not in the `Programming Language :: Python :: ...` classifiers above
66if sys.version_info >= (3, 10):
67 warnings.warn(
68 f"NumPy {VERSION} may not yet support Python "
69 f"{sys.version_info.major}.{sys.version_info.minor}.",
70 RuntimeWarning,
71 )
72
Ralf Gommers17716d72013-12-06 19:45:4073
Scott Sinclair58e63602010-11-09 15:09:1574# Return the git revision as a string
75def git_version():
David Cournapeau44d92ec2009-06-01 05:43:1676 def _minimal_ext_cmd(cmd):
77 # construct minimal environment
78 env = {}
Robert Kernc0be9952017-03-09 00:38:5479 for k in ['SYSTEMROOT', 'PATH', 'HOME']:
David Cournapeau5032b522009-09-18 10:10:3980 v = os.environ.get(k)
81 if v is not None:
82 env[k] = v
David Cournapeau44d92ec2009-06-01 05:43:1683 # LANGUAGE is used on win32
84 env['LANGUAGE'] = 'C'
85 env['LANG'] = 'C'
86 env['LC_ALL'] = 'C'
mattip6424fee2019-04-25 12:51:5587 out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
David Cournapeau44d92ec2009-06-01 05:43:1688 return out
89
David Cournapeau5623a7c2009-04-02 16:21:3090 try:
Scott Sinclair58e63602010-11-09 15:09:1591 out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
Pauli Virtanend1a184c2010-11-15 01:00:0692 GIT_REVISION = out.strip().decode('ascii')
mattip1f1e8f92019-05-02 02:53:5493 except (subprocess.SubprocessError, OSError):
Scott Sinclaird5ed7442010-11-10 05:19:1594 GIT_REVISION = "Unknown"
David Cournapeau5e041cb2009-03-27 11:16:0195
Seth Troisi0498afe2019-09-23 19:30:4496 if not GIT_REVISION:
97 # this shouldn't happen but apparently can (see gh-8512)
98 GIT_REVISION = "Unknown"
99
Scott Sinclair58e63602010-11-09 15:09:15100 return GIT_REVISION
David Cournapeau5e041cb2009-03-27 11:16:01101
Hugo van Kemenade595af822020-10-04 09:41:47102
Ralf Gommers4b0ed792015-12-29 10:29:38103# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be
104# properly updated when the contents of directories change (true for distutils,
105# not sure about setuptools).
106if os.path.exists('MANIFEST'):
107 os.remove('MANIFEST')
David Cournapeau5bb1aa52009-03-27 16:39:01108
109# This is a bit hackish: we are setting a global variable so that the main
110# numpy __init__ can detect if it is being loaded by the setup routine, to
111# avoid attempting to load components that aren't built yet. While ugly, it's
112# a lot more robust than what was previously being used.
David Cournapeau2b517692009-12-03 15:53:29113builtins.__NUMPY_SETUP__ = True
David Cournapeau5bb1aa52009-03-27 16:39:01114
rgommers13212a52011-03-03 16:13:08115
Ralf Gommers17716d72013-12-06 19:45:40116def get_version_info():
Ralf Gommers87e12c12011-03-24 15:30:06117 # Adding the git rev number needs to be done inside write_version_py(),
118 # otherwise the import of numpy.version messes up the build under Python 3.
119 FULLVERSION = VERSION
120 if os.path.exists('.git'):
121 GIT_REVISION = git_version()
122 elif os.path.exists('numpy/version.py'):
123 # must be a source distribution, use existing version file
Ralf Gommerscd6d53f2011-04-17 14:04:11124 try:
125 from numpy.version import git_revision as GIT_REVISION
126 except ImportError:
MSeifert0478d269d2019-07-01 18:51:40127 raise ImportError("Unable to import git_revision. Try removing "
128 "numpy/version.py and the build directory "
Ralf Gommerscd6d53f2011-04-17 14:04:11129 "before building.")
Ralf Gommers87e12c12011-03-24 15:30:06130 else:
131 GIT_REVISION = "Unknown"
132
133 if not ISRELEASED:
Ã…smund Hjulstade15f2922015-02-10 17:07:55134 FULLVERSION += '.dev0+' + GIT_REVISION[:7]
Ralf Gommers87e12c12011-03-24 15:30:06135
Ralf Gommers17716d72013-12-06 19:45:40136 return FULLVERSION, GIT_REVISION
137
138
139def write_version_py(filename='numpy/version.py'):
140 cnt = """
141# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
Ralf Gommers105a4982015-12-29 20:58:36142#
143# To compare versions robustly, use `numpy.lib.NumpyVersion`
Ralf Gommers17716d72013-12-06 19:45:40144short_version = '%(version)s'
145version = '%(version)s'
146full_version = '%(full_version)s'
147git_revision = '%(git_revision)s'
148release = %(isrelease)s
149
150if not release:
151 version = full_version
152"""
153 FULLVERSION, GIT_REVISION = get_version_info()
154
David Cournapeaua2ac9852009-03-27 11:15:36155 a = open(filename, 'w')
156 try:
Scott Sinclair58e63602010-11-09 15:09:15157 a.write(cnt % {'version': VERSION,
Charles Harris054d93a2017-11-29 18:53:21158 'full_version': FULLVERSION,
159 'git_revision': GIT_REVISION,
Scott Sinclair58e63602010-11-09 15:09:15160 'isrelease': str(ISRELEASED)})
David Cournapeaua2ac9852009-03-27 11:15:36161 finally:
162 a.close()
163
Ralf Gommers17716d72013-12-06 19:45:40164
Hugo van Kemenade595af822020-10-04 09:41:47165def configuration(parent_package='', top_path=None):
Pearu Peterson471196b2006-03-31 08:59:36166 from numpy.distutils.misc_util import Configuration
167
Pearu Peterson17d7cfe2006-04-04 12:26:14168 config = Configuration(None, parent_package, top_path)
Pearu Peterson471196b2006-03-31 08:59:36169 config.set_options(ignore_setup_xxx_py=True,
170 assume_default_configuration=True,
171 delegate_options_to_subpackages=True,
172 quiet=True)
Jarrod Millman0b77f0e2007-10-29 14:58:18173
Pearu Peterson471196b2006-03-31 08:59:36174 config.add_subpackage('numpy')
Charles Harris054d93a2017-11-29 18:53:21175 config.add_data_files(('numpy', 'LICENSE.txt'))
scoderf4c6fb12020-08-05 04:28:30176 config.add_data_files(('numpy', 'numpy/*.pxd'))
Jarrod Millman0b77f0e2007-10-29 14:58:18177
Hugo van Kemenade595af822020-10-04 09:41:47178 config.get_version('numpy/version.py') # sets config.version
Travis Oliphant00a35872007-05-31 04:57:01179
Pearu Peterson471196b2006-03-31 08:59:36180 return config
181
Ralf Gommers4b0ed792015-12-29 10:29:38182
Julian Taylor4cd72742014-01-29 21:59:19183def check_submodules():
184 """ verify that the submodules are checked out and clean
185 use `git submodule update --init`; on failure
186 """
187 if not os.path.exists('.git'):
188 return
189 with open('.gitmodules') as f:
Hugo van Kemenade595af822020-10-04 09:41:47190 for line in f:
191 if 'path' in line:
192 p = line.split('=')[-1].strip()
Julian Taylor4cd72742014-01-29 21:59:19193 if not os.path.exists(p):
Wojciech Rzadkowskic3c4ec92020-05-22 15:43:08194 raise ValueError('Submodule {} missing'.format(p))
Julian Taylor4cd72742014-01-29 21:59:19195
Julian Taylor4cd72742014-01-29 21:59:19196 proc = subprocess.Popen(['git', 'submodule', 'status'],
197 stdout=subprocess.PIPE)
198 status, _ = proc.communicate()
199 status = status.decode("ascii", "replace")
200 for line in status.splitlines():
201 if line.startswith('-') or line.startswith('+'):
Wojciech Rzadkowskic3c4ec92020-05-22 15:43:08202 raise ValueError('Submodule not clean: {}'.format(line))
Charles Harris13661ac2020-07-21 17:57:15203
Julian Taylor4cd72742014-01-29 21:59:19204
Ralf Gommers4b0ed792015-12-29 10:29:38205
Ralf Gommersa08fb602019-05-03 14:44:23206class concat_license_files():
Ralf Gommers33415902019-05-07 09:00:50207 """Merge LICENSE.txt and LICENSES_bundled.txt for sdist creation
Ralf Gommersa08fb602019-05-03 14:44:23208
209 Done this way to keep LICENSE.txt in repo as exact BSD 3-clause (see
210 gh-13447). This makes GitHub state correctly how NumPy is licensed.
211 """
212 def __init__(self):
213 self.f1 = 'LICENSE.txt'
Ralf Gommers33415902019-05-07 09:00:50214 self.f2 = 'LICENSES_bundled.txt'
Ralf Gommersa08fb602019-05-03 14:44:23215
216 def __enter__(self):
Ralf Gommers33415902019-05-07 09:00:50217 """Concatenate files and remove LICENSES_bundled.txt"""
Ralf Gommersa08fb602019-05-03 14:44:23218 with open(self.f1, 'r') as f1:
219 self.bsd_text = f1.read()
220
221 with open(self.f1, 'a') as f1:
222 with open(self.f2, 'r') as f2:
223 self.bundled_text = f2.read()
224 f1.write('\n\n')
225 f1.write(self.bundled_text)
226
Ralf Gommersa08fb602019-05-03 14:44:23227 def __exit__(self, exception_type, exception_value, traceback):
228 """Restore content of both files"""
229 with open(self.f1, 'w') as f:
230 f.write(self.bsd_text)
231
Ralf Gommersa08fb602019-05-03 14:44:23232
Ralf Gommers6770f982016-01-27 20:34:28233from distutils.command.sdist import sdist
Julian Taylor4cd72742014-01-29 21:59:19234class sdist_checked(sdist):
235 """ check submodules on sdist to prevent incomplete tarballs """
236 def run(self):
237 check_submodules()
Ralf Gommersa08fb602019-05-03 14:44:23238 with concat_license_files():
239 sdist.run(self)
Travis Oliphant14db4192005-09-14 22:08:46240
Ralf Gommers4b0ed792015-12-29 10:29:38241
mattip18af8e02020-01-04 20:47:47242def get_build_overrides():
243 """
mattipc2f93002020-01-05 15:00:30244 Custom build commands to add `-std=c99` to compilation
mattip18af8e02020-01-04 20:47:47245 """
246 from numpy.distutils.command.build_clib import build_clib
247 from numpy.distutils.command.build_ext import build_ext
248
249 def _is_using_gcc(obj):
250 is_gcc = False
251 if obj.compiler.compiler_type == 'unix':
252 cc = sysconfig.get_config_var("CC")
253 if not cc:
254 cc = ""
255 compiler_name = os.path.basename(cc)
256 is_gcc = "gcc" in compiler_name
257 return is_gcc
258
259 class new_build_clib(build_clib):
260 def build_a_library(self, build_info, lib_name, libraries):
261 if _is_using_gcc(self):
262 args = build_info.get('extra_compiler_args') or []
mattipc2f93002020-01-05 15:00:30263 args.append('-std=c99')
mattip18af8e02020-01-04 20:47:47264 build_info['extra_compiler_args'] = args
265 build_clib.build_a_library(self, build_info, lib_name, libraries)
266
267 class new_build_ext(build_ext):
268 def build_extension(self, ext):
269 if _is_using_gcc(self):
mattipc2f93002020-01-05 15:00:30270 if '-std=c99' not in ext.extra_compile_args:
271 ext.extra_compile_args.append('-std=c99')
mattip18af8e02020-01-04 20:47:47272 build_ext.build_extension(self, ext)
273 return new_build_clib, new_build_ext
274
275
Julian Taylorc9fd6342014-04-05 11:13:13276def generate_cython():
277 cwd = os.path.abspath(os.path.dirname(__file__))
278 print("Cythonizing sources")
mattip4e6a8122019-05-23 04:54:47279 for d in ('random',):
mattipfa8af412019-03-20 10:39:53280 p = subprocess.call([sys.executable,
Hugo van Kemenade595af822020-10-04 09:41:47281 os.path.join(cwd, 'tools', 'cythonize.py'),
282 'numpy/{0}'.format(d)],
283 cwd=cwd)
mattipfa8af412019-03-20 10:39:53284 if p != 0:
285 raise RuntimeError("Running cythonize failed!")
Julian Taylorc9fd6342014-04-05 11:13:13286
Ralf Gommers4b0ed792015-12-29 10:29:38287
Ralf Gommersb9f48092015-12-29 11:05:30288def parse_setuppy_commands():
Ralf Gommers99e99e92015-12-29 14:24:22289 """Check the commands and respond appropriately. Disable broken commands.
290
291 Return a boolean value for whether or not to run the build or not (avoid
292 parsing Cython and template files if False).
293 """
Eric Wieserb8b2a0e2018-03-12 08:29:52294 args = sys.argv[1:]
295
296 if not args:
Ralf Gommersb9f48092015-12-29 11:05:30297 # User forgot to give an argument probably, let setuptools handle that.
Ralf Gommers99e99e92015-12-29 14:24:22298 return True
Ralf Gommersb9f48092015-12-29 11:05:30299
Ralf Gommers99e99e92015-12-29 14:24:22300 info_commands = ['--help-commands', '--name', '--version', '-V',
301 '--fullname', '--author', '--author-email',
302 '--maintainer', '--maintainer-email', '--contact',
303 '--contact-email', '--url', '--license', '--description',
304 '--long-description', '--platforms', '--classifiers',
305 '--keywords', '--provides', '--requires', '--obsoletes']
Ralf Gommers99e99e92015-12-29 14:24:22306
307 for command in info_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52308 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22309 return False
310
311 # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work
312 # fine as they are, but are usually used together with one of the commands
313 # below and not standalone. Hence they're not added to good_commands.
314 good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py',
Ralf Gommersab5c6d02016-01-16 14:21:23315 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm',
mattip2e4af962019-09-19 20:47:29316 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src')
Ralf Gommers99e99e92015-12-29 14:24:22317
Ralf Gommersb9f48092015-12-29 11:05:30318 for command in good_commands:
Eric Wieserb8b2a0e2018-03-12 08:29:52319 if command in args:
Ralf Gommers99e99e92015-12-29 14:24:22320 return True
Ralf Gommersb9f48092015-12-29 11:05:30321
Ralf Gommersab5c6d02016-01-16 14:21:23322 # The following commands are supported, but we need to show more
Ralf Gommers99e99e92015-12-29 14:24:22323 # useful messages to the user
Eric Wieserb8b2a0e2018-03-12 08:29:52324 if 'install' in args:
Ralf Gommers99e99e92015-12-29 14:24:22325 print(textwrap.dedent("""
326 Note: if you need reliable uninstall behavior, then install
327 with pip instead of using `setup.py install`:
328
329 - `pip install .` (from a git repo or downloaded source
330 release)
Pierre de Buyl3f6672a2016-09-06 12:54:08331 - `pip install numpy` (last NumPy release on PyPi)
Ralf Gommers99e99e92015-12-29 14:24:22332
333 """))
334 return True
335
Eric Wieserb8b2a0e2018-03-12 08:29:52336 if '--help' in args or '-h' in sys.argv[1]:
Ralf Gommers99e99e92015-12-29 14:24:22337 print(textwrap.dedent("""
Pierre de Buyl3f6672a2016-09-06 12:54:08338 NumPy-specific help
Ralf Gommers99e99e92015-12-29 14:24:22339 -------------------
340
Pierre de Buyl3f6672a2016-09-06 12:54:08341 To install NumPy from here with reliable uninstall, we recommend
342 that you use `pip install .`. To install the latest NumPy release
Ralf Gommers99e99e92015-12-29 14:24:22343 from PyPi, use `pip install numpy`.
344
345 For help with build/installation issues, please ask on the
346 numpy-discussion mailing list. If you are sure that you have run
347 into a bug, please report it at https://github.com/numpy/numpy/issues.
348
349 Setuptools commands help
350 ------------------------
351 """))
352 return False
353
Ralf Gommers99e99e92015-12-29 14:24:22354 # The following commands aren't supported. They can only be executed when
355 # the user explicitly adds a --force command-line argument.
Ralf Gommersb9f48092015-12-29 11:05:30356 bad_commands = dict(
357 test="""
358 `setup.py test` is not supported. Use one of the following
359 instead:
360
361 - `python runtests.py` (to build and test)
362 - `python runtests.py --no-build` (to test installed numpy)
363 - `>>> numpy.test()` (run tests for installed numpy
364 from within an interpreter)
365 """,
366 upload="""
367 `setup.py upload` is not supported, because it's insecure.
368 Instead, build what you want to upload and upload those files
369 with `twine upload -s <filenames>` instead.
370 """,
371 upload_docs="`setup.py upload_docs` is not supported",
372 easy_install="`setup.py easy_install` is not supported",
373 clean="""
374 `setup.py clean` is not supported, use one of the following instead:
375
376 - `git clean -xdf` (cleans all files)
377 - `git clean -Xdf` (cleans all versioned files, doesn't touch
378 files that aren't checked into the git repo)
379 """,
380 check="`setup.py check` is not supported",
381 register="`setup.py register` is not supported",
382 bdist_dumb="`setup.py bdist_dumb` is not supported",
Ralf Gommers99e99e92015-12-29 14:24:22383 bdist="`setup.py bdist` is not supported",
384 build_sphinx="""
385 `setup.py build_sphinx` is not supported, use the
386 Makefile under doc/""",
387 flake8="`setup.py flake8` is not supported, use flake8 standalone",
Ralf Gommersb9f48092015-12-29 11:05:30388 )
Ralf Gommers99e99e92015-12-29 14:24:22389 bad_commands['nosetests'] = bad_commands['test']
Luca Mussi69d2cc82016-04-07 11:24:49390 for command in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb',
Hugo van Kemenade595af822020-10-04 09:41:47391 'register', 'check', 'install_data', 'install_headers',
392 'install_lib', 'install_scripts', ):
Ralf Gommers99e99e92015-12-29 14:24:22393 bad_commands[command] = "`setup.py %s` is not supported" % command
394
Ralf Gommersb9f48092015-12-29 11:05:30395 for command in bad_commands.keys():
Eric Wieserb8b2a0e2018-03-12 08:29:52396 if command in args:
Ralf Gommersb9f48092015-12-29 11:05:30397 print(textwrap.dedent(bad_commands[command]) +
398 "\nAdd `--force` to your command to use it anyway if you "
399 "must (unsupported).\n")
400 sys.exit(1)
401
Eric Wieserb8b2a0e2018-03-12 08:29:52402 # Commands that do more than print info, but also don't need Cython and
403 # template parsing.
404 other_commands = ['egg_info', 'install_egg_info', 'rotate']
405 for command in other_commands:
406 if command in args:
407 return False
408
Ralf Gommers99e99e92015-12-29 14:24:22409 # If we got here, we didn't detect what setup.py command was given
410 import warnings
411 warnings.warn("Unrecognized setuptools command, proceeding with "
Hugo van Kemenade595af822020-10-04 09:41:47412 "generating Cython sources and expanding templates",
413 stacklevel=2)
Ralf Gommers99e99e92015-12-29 14:24:22414 return True
Ralf Gommersb9f48092015-12-29 11:05:30415
416
Eric Wieserbe0d7ab2020-06-20 16:28:51417def get_docs_url():
418 if not ISRELEASED:
419 return "https://numpy.org/devdocs"
420 else:
421 # For releaeses, this URL ends up on pypi.
422 # By pinning the version, users looking at old PyPI releases can get
423 # to the associated docs easily.
424 return "https://numpy.org/doc/{}.{}".format(MAJOR, MINOR)
425
426
Ralf Gommers17716d72013-12-06 19:45:40427def setup_package():
mattip8b266552019-07-03 22:24:42428 src_path = os.path.dirname(os.path.abspath(__file__))
Pauli Virtanen68159432009-12-06 11:56:18429 old_path = os.getcwd()
430 os.chdir(src_path)
431 sys.path.insert(0, src_path)
432
Brian Wignallb485da12020-01-14 12:27:33433 # Rewrite the version file every time
Pauli Virtanen01312182010-11-23 16:50:54434 write_version_py()
435
Charles Harrisf22a33b2018-08-22 17:57:48436 # The f2py scripts that will be installed
437 if sys.platform == 'win32':
438 f2py_cmds = [
439 'f2py = numpy.f2py.f2py2e:main',
440 ]
441 else:
442 f2py_cmds = [
443 'f2py = numpy.f2py.f2py2e:main',
444 'f2py%s = numpy.f2py.f2py2e:main' % sys.version_info[:1],
445 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2],
446 ]
447
Hugo van Kemenade595af822020-10-04 09:41:47448 cmdclass = {"sdist": sdist_checked, }
Ralf Gommers17716d72013-12-06 19:45:40449 metadata = dict(
Hugo van Kemenade595af822020-10-04 09:41:47450 name='numpy',
451 maintainer="NumPy Developers",
452 maintainer_email="numpy-discussion@python.org",
453 description=DOCLINES[0],
454 long_description="\n".join(DOCLINES[2:]),
455 url="https://www.numpy.org",
456 author="Travis E. Oliphant et al.",
457 download_url="https://pypi.python.org/pypi/numpy",
Jarrod Millman0486b6d2019-04-12 01:11:21458 project_urls={
459 "Bug Tracker": "https://github.com/numpy/numpy/issues",
Eric Wieserbe0d7ab2020-06-20 16:28:51460 "Documentation": get_docs_url(),
Jarrod Millman0486b6d2019-04-12 01:11:21461 "Source Code": "https://github.com/numpy/numpy",
462 },
Hugo van Kemenade595af822020-10-04 09:41:47463 license='BSD',
Ralf Gommers17716d72013-12-06 19:45:40464 classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
Hugo van Kemenade595af822020-10-04 09:41:47465 platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
Charles Harris67d29b12020-05-18 22:26:10466 test_suite='pytest',
mattip18af8e02020-01-04 20:47:47467 cmdclass=cmdclass,
Charles Harris67d29b12020-05-18 22:26:10468 python_requires='>=3.6',
Nathaniel J. Smithf46e7162018-01-23 08:02:04469 zip_safe=False,
Charles Harrisf22a33b2018-08-22 17:57:48470 entry_points={
471 'console_scripts': f2py_cmds
472 },
Ralf Gommers17716d72013-12-06 19:45:40473 )
474
Ralf Gommers99e99e92015-12-29 14:24:22475 if "--force" in sys.argv:
476 run_build = True
Ralf Gommers20c3c2a2017-06-20 10:09:40477 sys.argv.remove('--force')
Ralf Gommers99e99e92015-12-29 14:24:22478 else:
479 # Raise errors for unsupported commands, improve help output, etc.
480 run_build = parse_setuppy_commands()
Ralf Gommersb9f48092015-12-29 11:05:30481
Ralf Gommers99e99e92015-12-29 14:24:22482 if run_build:
Mike Taves07bf33f2020-02-04 19:21:51483 # patches distutils, even though we don't use it
484 import setuptools # noqa: F401
Ralf Gommers17716d72013-12-06 19:45:40485 from numpy.distutils.core import setup
Hugo van Kemenade595af822020-10-04 09:41:47486 if 'sdist' not in sys.argv:
Ralf Gommersd630d962019-09-08 05:01:41487 # Generate Cython sources, unless we're generating an sdist
Julian Taylorc9fd6342014-04-05 11:13:13488 generate_cython()
Ralf Gommers4b0ed792015-12-29 10:29:38489
Ralf Gommers17716d72013-12-06 19:45:40490 metadata['configuration'] = configuration
mattip18af8e02020-01-04 20:47:47491 # Customize extension building
492 cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides()
Ralf Gommers99e99e92015-12-29 14:24:22493 else:
Mike Taves07bf33f2020-02-04 19:21:51494 from setuptools import setup
Ralf Gommers99e99e92015-12-29 14:24:22495 # Version number is added to metadata inside configuration() if build
496 # is run.
497 metadata['version'] = get_version_info()[0]
Pauli Virtanen68159432009-12-06 11:56:18498
Pearu Petersone8fa0132003-03-07 18:08:28499 try:
Ralf Gommers17716d72013-12-06 19:45:40500 setup(**metadata)
Pearu Petersone8fa0132003-03-07 18:08:28501 finally:
502 del sys.path[0]
503 os.chdir(old_path)
Travis Oliphant14db4192005-09-14 22:08:46504 return
Pearu Petersonc415fd12002-11-18 22:39:31505
Ralf Gommers17716d72013-12-06 19:45:40506
Travis Oliphant14db4192005-09-14 22:08:46507if __name__ == '__main__':
Pearu Petersone8fa0132003-03-07 18:08:28508 setup_package()
Ralf Gommersbbee7472016-08-21 05:23:35509 # This may avoid problems where numpy is installed via ``*_requires`` by
510 # setuptools, the global namespace isn't reset properly, and then numpy is
511 # imported later (which will then fail to load numpy extension modules).
512 # See gh-7956 for details
513 del builtins.__NUMPY_SETUP__