diff options
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 209 |
1 files changed, 70 insertions, 139 deletions
@@ -24,13 +24,63 @@ import sys import subprocess import textwrap import warnings +import builtins +import re -if sys.version_info[:2] < (3, 6): - raise RuntimeError("Python version >= 3.6 required.") +# Python supported version checks. Keep right after stdlib imports to ensure we +# get a sensible error for older Python versions +if sys.version_info[:2] < (3, 7): + raise RuntimeError("Python version >= 3.7 required.") -import builtins +import versioneer + + +# This is a bit hackish: we are setting a global variable so that the main +# numpy __init__ can detect if it is being loaded by the setup routine, to +# avoid attempting to load components that aren't built yet. While ugly, it's +# a lot more robust than what was previously being used. +builtins.__NUMPY_SETUP__ = True + +# Needed for backwards code compatibility below and in some CI scripts. +# The version components are changed from ints to strings, but only VERSION +# seems to matter outside of this module and it was already a str. +FULLVERSION = versioneer.get_version() + +# Capture the version string: +# 1.22.0.dev0+ ... -> ISRELEASED == False, VERSION == 1.22.0 +# 1.22.0rc1+ ... -> ISRELEASED == False, VERSION == 1.22.0 +# 1.22.0 ... -> ISRELEASED == True, VERSION == 1.22.0 +# 1.22.0rc1 ... -> ISRELEASED == True, VERSION == 1.22.0 +ISRELEASED = re.search(r'(dev|\+)', FULLVERSION) is None +MAJOR, MINOR, MICRO = re.match(r'(\d+)\.(\d+)\.(\d+)', FULLVERSION).groups() +VERSION = '{}.{}.{}'.format(MAJOR, MINOR, MICRO) + +# The first version not in the `Programming Language :: Python :: ...` classifiers above +if sys.version_info >= (3, 10): + fmt = "NumPy {} may not yet support Python {}.{}." + warnings.warn( + fmt.format(VERSION, *sys.version_info[:2]), + RuntimeWarning) + del fmt + +# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be +# properly updated when the contents of directories change (true for distutils, +# not sure about setuptools). +if os.path.exists('MANIFEST'): + os.remove('MANIFEST') + +# We need to import setuptools here in order for it to persist in sys.modules. +# Its presence/absence is used in subclassing setup in numpy/distutils/core.py. +# However, we need to run the distutils version of sdist, so import that first +# so that it is in sys.modules +import numpy.distutils.command.sdist +import setuptools + +# Initialize cmdclass from versioneer +from numpy.distutils.core import numpy_cmdclass +cmdclass = versioneer.get_cmdclass(numpy_cmdclass) CLASSIFIERS = """\ Development Status :: 5 - Production/Stable @@ -40,7 +90,6 @@ License :: OSI Approved :: BSD License Programming Language :: C Programming Language :: Python Programming Language :: Python :: 3 -Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 @@ -55,114 +104,6 @@ Operating System :: Unix Operating System :: MacOS """ -MAJOR = 1 -MINOR = 21 -MICRO = 0 -ISRELEASED = False -VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) - -# The first version not in the `Programming Language :: Python :: ...` classifiers above -if sys.version_info >= (3, 10): - warnings.warn( - f"NumPy {VERSION} may not yet support Python " - f"{sys.version_info.major}.{sys.version_info.minor}.", - RuntimeWarning, - ) - - -# Return the git revision as a string -def git_version(): - def _minimal_ext_cmd(cmd): - # construct minimal environment - env = {} - for k in ['SYSTEMROOT', 'PATH', 'HOME']: - v = os.environ.get(k) - if v is not None: - env[k] = v - # LANGUAGE is used on win32 - env['LANGUAGE'] = 'C' - env['LANG'] = 'C' - env['LC_ALL'] = 'C' - out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) - return out - - try: - out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) - GIT_REVISION = out.strip().decode('ascii') - except (subprocess.SubprocessError, OSError): - GIT_REVISION = "Unknown" - - if not GIT_REVISION: - # this shouldn't happen but apparently can (see gh-8512) - GIT_REVISION = "Unknown" - - return GIT_REVISION - - -# BEFORE importing setuptools, remove MANIFEST. Otherwise it may not be -# properly updated when the contents of directories change (true for distutils, -# not sure about setuptools). -if os.path.exists('MANIFEST'): - os.remove('MANIFEST') - -# This is a bit hackish: we are setting a global variable so that the main -# numpy __init__ can detect if it is being loaded by the setup routine, to -# avoid attempting to load components that aren't built yet. While ugly, it's -# a lot more robust than what was previously being used. -builtins.__NUMPY_SETUP__ = True - - -def get_version_info(): - # Adding the git rev number needs to be done inside write_version_py(), - # otherwise the import of numpy.version messes up the build under Python 3. - FULLVERSION = VERSION - if os.path.exists('.git'): - GIT_REVISION = git_version() - elif os.path.exists('numpy/version.py'): - # must be a source distribution, use existing version file - try: - from numpy.version import git_revision as GIT_REVISION - except ImportError: - raise ImportError("Unable to import git_revision. Try removing " - "numpy/version.py and the build directory " - "before building.") - else: - GIT_REVISION = "Unknown" - - if not ISRELEASED: - import time - - time_stamp = time.strftime("%Y%m%d%H%M%S", time.localtime()) - FULLVERSION += f'.dev0+{time_stamp}_{GIT_REVISION[:7]}' - - return FULLVERSION, GIT_REVISION - - -def write_version_py(filename='numpy/version.py'): - cnt = """ -# THIS FILE IS GENERATED FROM NUMPY SETUP.PY -# -# To compare versions robustly, use `numpy.lib.NumpyVersion` -short_version: str = '%(version)s' -version: str = '%(version)s' -full_version: str = '%(full_version)s' -git_revision: str = '%(git_revision)s' -release: bool = %(isrelease)s - -if not release: - version = full_version -""" - FULLVERSION, GIT_REVISION = get_version_info() - - a = open(filename, 'w') - try: - a.write(cnt % {'version': VERSION, - 'full_version': FULLVERSION, - 'git_revision': GIT_REVISION, - 'isrelease': str(ISRELEASED)}) - finally: - a.close() - def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration @@ -231,13 +172,14 @@ class concat_license_files(): f.write(self.bsd_text) -from distutils.command.sdist import sdist -class sdist_checked(sdist): +# Need to inherit from versioneer version of sdist to get the encoded +# version information. +class sdist_checked(cmdclass['sdist']): """ check submodules on sdist to prevent incomplete tarballs """ def run(self): check_submodules() with concat_license_files(): - sdist.run(self) + super().run() def get_build_overrides(): @@ -310,7 +252,8 @@ def parse_setuppy_commands(): '--maintainer', '--maintainer-email', '--contact', '--contact-email', '--url', '--license', '--description', '--long-description', '--platforms', '--classifiers', - '--keywords', '--provides', '--requires', '--obsoletes'] + '--keywords', '--provides', '--requires', '--obsoletes', + 'version',] for command in info_commands: if command in args: @@ -321,7 +264,8 @@ def parse_setuppy_commands(): # below and not standalone. Hence they're not added to good_commands. good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py', 'build_clib', 'build_scripts', 'bdist_wheel', 'bdist_rpm', - 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src') + 'bdist_wininst', 'bdist_msi', 'bdist_mpkg', 'build_src', + 'bdist_egg') for command in good_commands: if command in args: @@ -376,8 +320,6 @@ def parse_setuppy_commands(): Instead, build what you want to upload and upload those files with `twine upload -s <filenames>` instead. """, - upload_docs="`setup.py upload_docs` is not supported", - easy_install="`setup.py easy_install` is not supported", clean=""" `setup.py clean` is not supported, use one of the following instead: @@ -385,10 +327,6 @@ def parse_setuppy_commands(): - `git clean -Xdf` (cleans all versioned files, doesn't touch files that aren't checked into the git repo) """, - check="`setup.py check` is not supported", - register="`setup.py register` is not supported", - bdist_dumb="`setup.py bdist_dumb` is not supported", - bdist="`setup.py bdist` is not supported", build_sphinx=""" `setup.py build_sphinx` is not supported, use the Makefile under doc/""", @@ -409,21 +347,17 @@ def parse_setuppy_commands(): # Commands that do more than print info, but also don't need Cython and # template parsing. - other_commands = ['egg_info', 'install_egg_info', 'rotate'] + other_commands = ['egg_info', 'install_egg_info', 'rotate', 'dist_info'] for command in other_commands: if command in args: return False # If we got here, we didn't detect what setup.py command was given - import warnings - warnings.warn("Unrecognized setuptools command, proceeding with " - "generating Cython sources and expanding templates", - stacklevel=2) - return True + raise RuntimeError("Unrecognized setuptools command: {}".format(args)) def get_docs_url(): - if not ISRELEASED: + if 'dev' in VERSION: return "https://numpy.org/devdocs" else: # For releases, this URL ends up on pypi. @@ -438,9 +372,6 @@ def setup_package(): os.chdir(src_path) sys.path.insert(0, src_path) - # Rewrite the version file every time - write_version_py() - # The f2py scripts that will be installed if sys.platform == 'win32': f2py_cmds = [ @@ -453,7 +384,7 @@ def setup_package(): 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2], ] - cmdclass = {"sdist": sdist_checked, } + cmdclass["sdist"] = sdist_checked metadata = dict( name='numpy', maintainer="NumPy Developers", @@ -472,8 +403,9 @@ def setup_package(): classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], test_suite='pytest', + version=versioneer.get_version(), cmdclass=cmdclass, - python_requires='>=3.6', + python_requires='>=3.7', zip_safe=False, entry_points={ 'console_scripts': f2py_cmds @@ -489,8 +421,9 @@ def setup_package(): if run_build: # patches distutils, even though we don't use it - import setuptools # noqa: F401 + #from setuptools import setup from numpy.distutils.core import setup + if 'sdist' not in sys.argv: # Generate Cython sources, unless we're generating an sdist generate_cython() @@ -499,10 +432,8 @@ def setup_package(): # Customize extension building cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides() else: + #from numpy.distutils.core import setup from setuptools import setup - # Version number is added to metadata inside configuration() if build - # is run. - metadata['version'] = get_version_info()[0] try: setup(**metadata) |