diff options
| -rw-r--r-- | changelog.d/3043.change.rst | 1 | ||||
| -rw-r--r-- | changelog.d/3054.misc.rst | 1 | ||||
| -rw-r--r-- | changelog.d/3056.docs.rst | 2 | ||||
| -rw-r--r-- | docs/build_meta.rst | 33 | ||||
| -rw-r--r-- | docs/deprecated/distutils-legacy.rst | 2 | ||||
| -rw-r--r-- | docs/deprecated/functionalities.rst | 2 | ||||
| -rw-r--r-- | docs/userguide/declarative_config.rst | 4 | ||||
| -rw-r--r-- | docs/userguide/dependency_management.rst | 2 | ||||
| -rw-r--r-- | docs/userguide/distribution.rst | 2 | ||||
| -rw-r--r-- | docs/userguide/quickstart.rst | 10 | ||||
| -rw-r--r-- | pkg_resources/__init__.py | 4 | ||||
| -rw-r--r-- | setuptools/__init__.py | 4 | ||||
| -rw-r--r-- | setuptools/_distutils/spawn.py | 2 | ||||
| -rw-r--r-- | setuptools/_distutils/tests/test_util.py | 125 | ||||
| -rw-r--r-- | setuptools/_distutils/util.py | 98 | ||||
| -rw-r--r-- | setuptools/command/easy_install.py | 2 | ||||
| -rw-r--r-- | setuptools/extension.py | 2 | ||||
| -rw-r--r-- | setuptools/logging.py | 6 | ||||
| -rw-r--r-- | setuptools/package_index.py | 4 | ||||
| -rw-r--r-- | setuptools/tests/test_logging.py | 36 |
20 files changed, 126 insertions, 216 deletions
diff --git a/changelog.d/3043.change.rst b/changelog.d/3043.change.rst new file mode 100644 index 00000000..d52705f9 --- /dev/null +++ b/changelog.d/3043.change.rst @@ -0,0 +1 @@ +Merge with pypa/distutils@bb018f1ac3 including consolidated behavior in sysconfig.get_platform (pypa/distutils#104). diff --git a/changelog.d/3054.misc.rst b/changelog.d/3054.misc.rst new file mode 100644 index 00000000..7166f837 --- /dev/null +++ b/changelog.d/3054.misc.rst @@ -0,0 +1 @@ +Used Py3 syntax ``super().__init__()`` -- by :user:`imba-tjd` diff --git a/changelog.d/3056.docs.rst b/changelog.d/3056.docs.rst new file mode 100644 index 00000000..c3de4e99 --- /dev/null +++ b/changelog.d/3056.docs.rst @@ -0,0 +1,2 @@ +The documentation has stopped suggesting to add ``wheel`` to +:pep:`517` requirements -- by :user:`webknjaz` diff --git a/docs/build_meta.rst b/docs/build_meta.rst index 27df70a2..a14a5843 100644 --- a/docs/build_meta.rst +++ b/docs/build_meta.rst @@ -9,29 +9,29 @@ Python packaging has come `a long way <https://bernat.tech/posts/pep-517-518/>`_ The traditional ``setuptools`` way of packaging Python modules uses a ``setup()`` function within the ``setup.py`` script. Commands such as -``python setup.py bdist`` or ``python setup.py bdist_wheel`` generate a -distribution bundle and ``python setup.py install`` installs the distribution. -This interface makes it difficult to choose other packaging tools without an +``python setup.py bdist`` or ``python setup.py bdist_wheel`` generate a +distribution bundle and ``python setup.py install`` installs the distribution. +This interface makes it difficult to choose other packaging tools without an overhaul. Because ``setup.py`` scripts allowed for arbitrary execution, it proved difficult to provide a reliable user experience across environments and history. `PEP 517 <https://www.python.org/dev/peps/pep-0517/>`_ therefore came to -rescue and specified a new standard to +rescue and specified a new standard to package and distribute Python modules. Under PEP 517: a ``pyproject.toml`` file is used to specify what program to use - for generating distribution. + for generating distribution. - Then, two functions provided by the program, ``build_wheel(directory: str)`` - and ``build_sdist(directory: str)`` create the distribution bundle at the - specified ``directory``. The program is free to use its own configuration - script or extend the ``.toml`` file. + Then, two functions provided by the program, ``build_wheel(directory: str)`` + and ``build_sdist(directory: str)`` create the distribution bundle at the + specified ``directory``. The program is free to use its own configuration + script or extend the ``.toml`` file. Lastly, ``pip install *.whl`` or ``pip install *.tar.gz`` does the actual installation. If ``*.whl`` is available, ``pip`` will go ahead and copy the files into ``site-packages`` directory. If not, ``pip`` will look at - ``pyproject.toml`` and decide what program to use to 'build from source' + ``pyproject.toml`` and decide what program to use to 'build from source' (the default is ``setuptools``) With this standard, switching between packaging tools becomes a lot easier. ``build_meta`` @@ -48,17 +48,18 @@ scripts, a ``pyproject.toml`` file and a ``setup.cfg`` file:: setup.cfg meowpkg/__init__.py -The pyproject.toml file is required to specify the build system (i.e. what is -being used to package your scripts and install from source). To use it with +The pyproject.toml file is required to specify the build system (i.e. what is +being used to package your scripts and install from source). To use it with setuptools, the content would be:: [build-system] - requires = ["setuptools", "wheel"] + requires = ["setuptools"] build-backend = "setuptools.build_meta" The ``setuptools`` package implements the ``build_sdist`` command and the ``wheel`` package implements the ``build_wheel`` -command; both are required to be compliant with PEP 517. +command; the latter is a dependency of the former +exposed via :pep:`517` hooks. Use ``setuptools``' :ref:`declarative config <declarative config>` to specify the package information:: @@ -67,7 +68,7 @@ specify the package information:: name = meowpkg version = 0.0.1 description = a package that meows - + [options] packages = find: @@ -77,7 +78,7 @@ Now generate the distribution. To build the package, use $ pip install -q build $ python -m build -And now it's done! The ``.whl`` file and ``.tar.gz`` can then be distributed +And now it's done! The ``.whl`` file and ``.tar.gz`` can then be distributed and installed:: dist/ diff --git a/docs/deprecated/distutils-legacy.rst b/docs/deprecated/distutils-legacy.rst index 94104fe8..148dc259 100644 --- a/docs/deprecated/distutils-legacy.rst +++ b/docs/deprecated/distutils-legacy.rst @@ -5,7 +5,7 @@ Setuptools and the PyPA have a `stated goal <https://github.com/pypa/packaging-p Since the 49.1.2 release, Setuptools includes a local, vendored copy of distutils (from late copies of CPython) that is disabled by default. To enable the use of this copy of distutils when invoking setuptools, set the enviroment variable: - SETUPTOOLS_USE_DISTUTILS=local + SETUPTOOLS_USE_DISTUTILS=local This behavior is planned to become the default. diff --git a/docs/deprecated/functionalities.rst b/docs/deprecated/functionalities.rst index c6ea83b3..7213c5d6 100644 --- a/docs/deprecated/functionalities.rst +++ b/docs/deprecated/functionalities.rst @@ -30,4 +30,4 @@ invoked via symlinks. They *must* be invoked using their original filename, in order to ensure that, once running, ``pkg_resources`` will know what project and version is in use. The header script will check this and exit with an error if the ``.egg`` file has been renamed or is invoked via a symlink that -changes its base name.
\ No newline at end of file +changes its base name. diff --git a/docs/userguide/declarative_config.rst b/docs/userguide/declarative_config.rst index d1c25df1..6f41d92b 100644 --- a/docs/userguide/declarative_config.rst +++ b/docs/userguide/declarative_config.rst @@ -222,10 +222,10 @@ data_files section 40.6.0 [# .. [#opt-1] In the ``package_data`` section, a key named with a single asterisk (``*``) refers to all packages, in lieu of the empty string used in ``setup.py``. - + .. [#opt-2] In the ``extras_require`` section, values are parsed as ``list-semi``. This implies that in order to include markers, they **must** be *dangling*: - + .. code-block:: ini [options.extras_require] diff --git a/docs/userguide/dependency_management.rst b/docs/userguide/dependency_management.rst index 9c29dbd5..ea2fc556 100644 --- a/docs/userguide/dependency_management.rst +++ b/docs/userguide/dependency_management.rst @@ -28,7 +28,7 @@ other two types of dependency keyword, this one is specified in your .. code-block:: ini [build-system] - requires = ["setuptools", "wheel"] + requires = ["setuptools"] #... .. note:: diff --git a/docs/userguide/distribution.rst b/docs/userguide/distribution.rst index 2872dacd..db0f1a5f 100644 --- a/docs/userguide/distribution.rst +++ b/docs/userguide/distribution.rst @@ -162,7 +162,7 @@ Specifying Your Project's Version --------------------------------- Setuptools can work well with most versioning schemes. Over the years, -setuptools has tried to closely follow the +setuptools has tried to closely follow the `PEP 440 <https://www.python.org/dev/peps/pep-0440/>`_ scheme, but it also supports legacy versions. There are, however, a few special things to watch out for, in order to ensure that setuptools and diff --git a/docs/userguide/quickstart.rst b/docs/userguide/quickstart.rst index 4c62c6df..203d6204 100644 --- a/docs/userguide/quickstart.rst +++ b/docs/userguide/quickstart.rst @@ -32,7 +32,7 @@ package your project: .. code-block:: toml [build-system] - requires = ["setuptools", "wheel"] + requires = ["setuptools"] build-backend = "setuptools.build_meta" Then, you will need a ``setup.cfg`` or ``setup.py`` to specify your package @@ -96,7 +96,7 @@ to specify to properly package your project. Automatic package discovery =========================== For simple projects, it's usually easy enough to manually add packages to -the ``packages`` keyword in ``setup.cfg``. However, for very large projects, +the ``packages`` keyword in ``setup.cfg``. However, for very large projects, it can be a big burden to keep the package list updated. ``setuptools`` therefore provides two convenient tools to ease the burden: :literal:`find:\ ` and :literal:`find_namespace:\ `. To use it in your project: @@ -189,9 +189,9 @@ Development mode .. tip:: - Prior to :ref:`pip v21.1 <pip:v21-1>`, a ``setup.py`` script was - required to be compatible with development mode. With late - versions of pip, any project may be installed in this mode. + Prior to :ref:`pip v21.1 <pip:v21-1>`, a ``setup.py`` script was + required to be compatible with development mode. With late + versions of pip, any project may be installed in this mode. ``setuptools`` allows you to install a package without copying any files to your interpreter directory (e.g. the ``site-packages`` directory). diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index b0704965..93db52d2 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1581,7 +1581,7 @@ class EggProvider(NullProvider): """Provider based on a virtual filesystem""" def __init__(self, module): - NullProvider.__init__(self, module) + super().__init__(module) self._setup_prefix() def _setup_prefix(self): @@ -1701,7 +1701,7 @@ class ZipProvider(EggProvider): _zip_manifests = MemoizedZipManifests() def __init__(self, module): - EggProvider.__init__(self, module) + super().__init__(module) self.zip_pre = self.loader.archive + os.sep def _zipinfo_name(self, fspath): diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 43d1c96e..06991b65 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -132,7 +132,7 @@ def _install_setup_requires(attrs): def __init__(self, attrs): _incl = 'dependency_links', 'setup_requires' filtered = {k: attrs[k] for k in set(_incl) & set(attrs)} - distutils.core.Distribution.__init__(self, filtered) + super().__init__(filtered) def finalize_options(self): """ @@ -171,7 +171,7 @@ class Command(_Command): Construct the command for dist, updating vars(self) with any keyword parameters. """ - _Command.__init__(self, dist) + super().__init__(dist) vars(self).update(kw) def _ensure_stringlike(self, option, what, default=None): diff --git a/setuptools/_distutils/spawn.py b/setuptools/_distutils/spawn.py index 6e1c89f1..b2d10e39 100644 --- a/setuptools/_distutils/spawn.py +++ b/setuptools/_distutils/spawn.py @@ -10,7 +10,7 @@ import sys import os import subprocess -from distutils.errors import DistutilsPlatformError, DistutilsExecError +from distutils.errors import DistutilsExecError from distutils.debug import DEBUG from distutils import log diff --git a/setuptools/_distutils/tests/test_util.py b/setuptools/_distutils/tests/test_util.py index 12469e3d..2738388e 100644 --- a/setuptools/_distutils/tests/test_util.py +++ b/setuptools/_distutils/tests/test_util.py @@ -2,6 +2,7 @@ import os import sys import unittest +import sysconfig as stdlib_sysconfig from copy import copy from test.support import run_unittest from unittest import mock @@ -10,12 +11,10 @@ from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError from distutils.util import (get_platform, convert_path, change_root, check_environ, split_quoted, strtobool, rfc822_escape, byte_compile, - grok_environment_error) + grok_environment_error, get_host_platform) from distutils import util # used to patch _environ_checked -from distutils.sysconfig import get_config_vars from distutils import sysconfig from distutils.tests import support -import _osx_support class UtilTestCase(support.EnvironGuard, unittest.TestCase): @@ -63,110 +62,26 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): def _get_uname(self): return self._uname - def test_get_platform(self): - - # windows XP, 32bits - os.name = 'nt' - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' - '[MSC v.1310 32 bit (Intel)]') - sys.platform = 'win32' - self.assertEqual(get_platform(), 'win32') - - # windows XP, amd64 - os.name = 'nt' - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' - '[MSC v.1310 32 bit (Amd64)]') - sys.platform = 'win32' - self.assertEqual(get_platform(), 'win-amd64') - - # macbook - os.name = 'posix' - sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) ' - '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]') - sys.platform = 'darwin' - self._set_uname(('Darwin', 'macziade', '8.11.1', - ('Darwin Kernel Version 8.11.1: ' - 'Wed Oct 10 18:23:28 PDT 2007; ' - 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386')) - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3' - - get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g ' - '-fwrapv -O3 -Wall -Wstrict-prototypes') - - cursize = sys.maxsize - sys.maxsize = (2 ** 31)-1 - try: - self.assertEqual(get_platform(), 'macosx-10.3-i386') - finally: - sys.maxsize = cursize - - # macbook with fat binaries (fat, universal or fat64) - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4' - get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - - self.assertEqual(get_platform(), 'macosx-10.4-fat') - - _osx_support._remove_original_values(get_config_vars()) - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.1' - self.assertEqual(get_platform(), 'macosx-10.4-fat') - + def test_get_host_platform(self): + with unittest.mock.patch('os.name', 'nt'): + with unittest.mock.patch('sys.version', '... [... (ARM64)]'): + self.assertEqual(get_host_platform(), 'win-arm64') + with unittest.mock.patch('sys.version', '... [... (ARM)]'): + self.assertEqual(get_host_platform(), 'win-arm32') - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') + with unittest.mock.patch('sys.version_info', (3, 9, 0, 'final', 0)): + self.assertEqual(get_host_platform(), stdlib_sysconfig.get_platform()) - self.assertEqual(get_platform(), 'macosx-10.4-intel') - - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - self.assertEqual(get_platform(), 'macosx-10.4-fat3') - - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - self.assertEqual(get_platform(), 'macosx-10.4-universal') - - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - - self.assertEqual(get_platform(), 'macosx-10.4-fat64') - - for arch in ('ppc', 'i386', 'x86_64', 'ppc64'): - _osx_support._remove_original_values(get_config_vars()) - get_config_vars()['CFLAGS'] = ('-arch %s -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3'%(arch,)) - - self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,)) - - - # linux debian sarge - os.name = 'posix' - sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) ' - '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]') - sys.platform = 'linux2' - self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7', - '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686')) - - self.assertEqual(get_platform(), 'linux-i686') - - # XXX more platforms to tests here + def test_get_platform(self): + with unittest.mock.patch('os.name', 'nt'): + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x86'}): + self.assertEqual(get_platform(), 'win32') + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x64'}): + self.assertEqual(get_platform(), 'win-amd64') + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm'}): + self.assertEqual(get_platform(), 'win-arm32') + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}): + self.assertEqual(get_platform(), 'win-arm64') def test_convert_path(self): # linux/mac diff --git a/setuptools/_distutils/util.py b/setuptools/_distutils/util.py index ac6d446d..6d506d7e 100644 --- a/setuptools/_distutils/util.py +++ b/setuptools/_distutils/util.py @@ -9,6 +9,7 @@ import re import importlib.util import string import sys +import sysconfig from distutils.errors import DistutilsPlatformError from distutils.dep_util import newer from distutils.spawn import spawn @@ -20,82 +21,29 @@ from .py35compat import _optim_args_from_interpreter_flags def get_host_platform(): """Return a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built - distributions. Typically includes the OS name and version and the - architecture (as supplied by 'os.uname()'), although the exact information - included depends on the OS; eg. on Linux, the kernel version isn't - particularly important. - - Examples of returned values: - linux-i586 - linux-alpha (?) - solaris-2.6-sun4u - - Windows will return one of: - win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) - win32 (all others - specifically, sys.platform is returned) - - For other non-POSIX platforms, currently just returns 'sys.platform'. - + distributions. """ - if os.name == 'nt': - if 'amd64' in sys.version.lower(): - return 'win-amd64' - if '(arm)' in sys.version.lower(): - return 'win-arm32' - if '(arm64)' in sys.version.lower(): - return 'win-arm64' - return sys.platform - - # Set for cross builds explicitly - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] - - if os.name != "posix" or not hasattr(os, 'uname'): - # XXX what about the architecture? NT is Intel or Alpha, - # Mac OS is M68k or PPC, etc. - return sys.platform - - # Try to distinguish various flavours of Unix - - (osname, host, release, version, machine) = os.uname() - - # Convert the OS name to lowercase, remove '/' characters, and translate - # spaces (for "Power Macintosh") - osname = osname.lower().replace('/', '') - machine = machine.replace(' ', '_') - machine = machine.replace('/', '-') - - if osname[:5] == "linux": - # At least on Linux/Intel, 'machine' is the processor -- - # i386, etc. - # XXX what about Alpha, SPARC, etc? - return "%s-%s" % (osname, machine) - elif osname[:5] == "sunos": - if release[0] >= "5": # SunOS 5 == Solaris 2 - osname = "solaris" - release = "%d.%s" % (int(release[0]) - 3, release[2:]) - # We can't use "platform.architecture()[0]" because a - # bootstrap problem. We use a dict to get an error - # if some suspicious happens. - bitness = {2147483647:"32bit", 9223372036854775807:"64bit"} - machine += ".%s" % bitness[sys.maxsize] - # fall through to standard osname-release-machine representation - elif osname[:3] == "aix": - from .py38compat import aix_platform - return aix_platform(osname, version, release) - elif osname[:6] == "cygwin": - osname = "cygwin" - rel_re = re.compile (r'[\d.]+', re.ASCII) - m = rel_re.match(release) - if m: - release = m.group() - elif osname[:6] == "darwin": - import _osx_support, distutils.sysconfig - osname, release, machine = _osx_support.get_platform_osx( - distutils.sysconfig.get_config_vars(), - osname, release, machine) - - return "%s-%s-%s" % (osname, release, machine) + + # We initially exposed platforms as defined in Python 3.9 + # even with older Python versions when distutils was split out. + # Now that we delegate to stdlib sysconfig we need to restore this + # in case anyone has started to depend on it. + + if sys.version_info < (3, 8): + if os.name == 'nt': + if '(arm)' in sys.version.lower(): + return 'win-arm32' + if '(arm64)' in sys.version.lower(): + return 'win-arm64' + + if sys.version_info < (3, 9): + if os.name == "posix" and hasattr(os, 'uname'): + osname, host, release, version, machine = os.uname() + if osname[:3] == "aix": + from .py38compat import aix_platform + return aix_platform(osname, version, release) + + return sysconfig.get_platform() def get_platform(): if os.name == 'nt': diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 514719de..5fab0fdb 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1577,7 +1577,7 @@ class PthDistributions(Environment): self.sitedirs = list(map(normalize_path, sitedirs)) self.basedir = normalize_path(os.path.dirname(self.filename)) self._load() - Environment.__init__(self, [], None, None) + super().__init__([], None, None) for path in yield_lines(self.paths): list(map(self.add, find_distributions(path, True))) diff --git a/setuptools/extension.py b/setuptools/extension.py index 1820722a..f696c9c1 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -34,7 +34,7 @@ class Extension(_Extension): # The *args is needed for compatibility as calls may use positional # arguments. py_limited_api may be set only via keyword. self.py_limited_api = kw.pop("py_limited_api", False) - _Extension.__init__(self, name, sources, *args, **kw) + super().__init__(name, sources, *args, **kw) def _convert_pyx_sources_to_lang(self): """ diff --git a/setuptools/logging.py b/setuptools/logging.py index dbead6e6..15b57613 100644 --- a/setuptools/logging.py +++ b/setuptools/logging.py @@ -24,6 +24,12 @@ def configure(): format="{message}", style='{', handlers=handlers, level=logging.DEBUG) monkey.patch_func(set_threshold, distutils.log, 'set_threshold') + # For some reason `distutils.log` module is getting cached in `distutils.dist` + # and then loaded again when patched, + # implying: id(distutils.log) != id(distutils.dist.log). + # Make sure the same module object is used everywhere: + distutils.dist.log = distutils.log + def set_threshold(level): logging.root.setLevel(level*10) diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 270e7f3c..051e523a 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -285,7 +285,7 @@ class PackageIndex(Environment): self, index_url="https://pypi.org/simple/", hosts=('*',), ca_bundle=None, verify_ssl=True, *args, **kw ): - Environment.__init__(self, *args, **kw) + super().__init__(*args, **kw) self.index_url = index_url + "/" [:not index_url.endswith('/')] self.scanned_urls = {} self.fetched_urls = {} @@ -1002,7 +1002,7 @@ class PyPIConfig(configparser.RawConfigParser): Load from ~/.pypirc """ defaults = dict.fromkeys(['username', 'password', 'repository'], '') - configparser.RawConfigParser.__init__(self, defaults) + super().__init__(defaults) rc = os.path.join(os.path.expanduser('~'), '.pypirc') if os.path.exists(rc): diff --git a/setuptools/tests/test_logging.py b/setuptools/tests/test_logging.py new file mode 100644 index 00000000..a5ddd56d --- /dev/null +++ b/setuptools/tests/test_logging.py @@ -0,0 +1,36 @@ +import logging + +import pytest + + +setup_py = """\ +from setuptools import setup + +setup( + name="test_logging", + version="0.0" +) +""" + + +@pytest.mark.parametrize( + "flag, expected_level", [("--dry-run", "INFO"), ("--verbose", "DEBUG")] +) +def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level): + """Make sure the correct verbosity level is set (issue #3038)""" + import setuptools # noqa: Import setuptools to monkeypatch distutils + import distutils # <- load distutils after all the patches take place + + logger = logging.Logger(__name__) + monkeypatch.setattr(logging, "root", logger) + unset_log_level = logger.getEffectiveLevel() + assert logging.getLevelName(unset_log_level) == "NOTSET" + + setup_script = tmp_path / "setup.py" + setup_script.write_text(setup_py) + dist = distutils.core.run_setup(setup_script, stop_after="init") + dist.script_args = [flag, "sdist"] + dist.parse_command_line() # <- where the log level is set + log_level = logger.getEffectiveLevel() + log_level_name = logging.getLevelName(log_level) + assert log_level_name == expected_level |
