From 7085054dc4c4e936eb3305c6d6141216d88cbf6f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 9 Nov 2021 14:15:23 -0800 Subject: [PATCH 01/14] tox.ini (testenv): passenv SETUPTOOLS_USE_DISTUTILS --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 8a48a1cdb3..ab993608af 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ commands = usedevelop = True extras = testing passenv = + SETUPTOOLS_USE_DISTUTILS windir # required for test_pkg_resources [testenv:docs] From 88dd936918f4eeaa61e010b481bbc22b0f58844e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 9 Nov 2021 14:15:45 -0800 Subject: [PATCH 02/14] .github/workflows/main.yml: Test SETUPTOOLS_USE_DISTUTILS = stdlib, local --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a82b6fd299..265be8497c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,6 +6,9 @@ jobs: test: strategy: matrix: + distutils: + - stdlib + - local python: - pypy3 - 3.6 @@ -16,6 +19,8 @@ jobs: - macos-latest - windows-latest runs-on: ${{ matrix.platform }} + env: + SETUPTOOLS_USE_DISTUTILS: ${{ matrix.distutils }} steps: - uses: actions/checkout@v2 - name: Setup Python From 822463194a4720288a2df8c9573d0a1f9726764b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 9 Nov 2021 14:30:40 -0800 Subject: [PATCH 03/14] tox.ini (testenv): Add deps = pytest --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index ab993608af..8940a18251 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,7 @@ toxworkdir={env:TOX_WORK_DIR:.tox} [testenv] deps = + pytest # workaround for sphinx-doc/sphinx#9562 # TODO: remove after Sphinx>4.1.2 is available. sphinx@git+https://github.com/sphinx-doc/sphinx; python_version>="3.10" From 802d8723cb8623b0bed230d0e117a372e040fe8e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 9 Nov 2021 14:53:40 -0800 Subject: [PATCH 04/14] tox.ini (testenv): Make sure to import setuptools before distutils when invoking pytest --- tox.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 8940a18251..21fdd86652 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,11 @@ deps = # TODO: remove after Sphinx>4.1.2 is available. sphinx@git+https://github.com/sphinx-doc/sphinx; python_version>="3.10" commands = - pytest {posargs} + # We invoke pytest like this to avoid the warning: + # UserWarning: Distutils was imported before Setuptools, + # but importing Setuptools also replaces the `distutils` + # module in `sys.modules`. + pytest -c 'import setuptools; import pytest; pytest.main("{posargs}".split())' usedevelop = True extras = testing passenv = From 5d21da70b7d9f75866d0f9f10f4ea54af74a95b1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 9 Nov 2021 14:59:17 -0800 Subject: [PATCH 05/14] .github/workflows/main.yml: fail-fast = false --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 265be8497c..6751c52cdb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: - ubuntu-latest - macos-latest - windows-latest + fail-fast: false runs-on: ${{ matrix.platform }} env: SETUPTOOLS_USE_DISTUTILS: ${{ matrix.distutils }} From d97e83e34d712330cf82427222cd141159e1f7f2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 14:45:56 -0500 Subject: [PATCH 06/14] Get pytest-virtualenv from the pull request with distutils dependency removed. --- setup.cfg | 2 +- tox.ini | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index fdaf6c04ae..66cad330a2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,7 +55,7 @@ testing = mock flake8-2020 virtualenv>=13.0.0 - pytest-virtualenv>=1.2.7 + pytest-virtualenv @ git+https://github.com/jaraco/pytest-plugins@distutils-deprecated#subdirectory=pytest-virtualenv wheel paver pip>=19.1 # For proper file:// URLs support. diff --git a/tox.ini b/tox.ini index 21fdd86652..8940a18251 100644 --- a/tox.ini +++ b/tox.ini @@ -12,11 +12,7 @@ deps = # TODO: remove after Sphinx>4.1.2 is available. sphinx@git+https://github.com/sphinx-doc/sphinx; python_version>="3.10" commands = - # We invoke pytest like this to avoid the warning: - # UserWarning: Distutils was imported before Setuptools, - # but importing Setuptools also replaces the `distutils` - # module in `sys.modules`. - pytest -c 'import setuptools; import pytest; pytest.main("{posargs}".split())' + pytest {posargs} usedevelop = True extras = testing passenv = From ec1c3f34c67c001843a92d9f81febb3c3dc12846 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 14:48:08 -0500 Subject: [PATCH 07/14] Fail fast again. --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6751c52cdb..265be8497c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,6 @@ jobs: - ubuntu-latest - macos-latest - windows-latest - fail-fast: false runs-on: ${{ matrix.platform }} env: SETUPTOOLS_USE_DISTUTILS: ${{ matrix.distutils }} From 4f3c3a1a1e754f5b253262e8112292ae9f7881a1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 16:20:36 -0500 Subject: [PATCH 08/14] Filter known deprecation warnings when stdlib distutils is used and imports sysconfig. --- conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conftest.py b/conftest.py index d5e851fe50..3f80b495cc 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ import sys +import warnings pytest_plugins = 'setuptools.tests.fixtures' @@ -27,3 +28,11 @@ def pytest_addoption(parser): if sys.version_info < (3, 6): collect_ignore.append('docs/conf.py') # uses f-strings collect_ignore.append('pavement.py') + + +if sys.version_info > (3, 10): + # https://github.com/pypa/setuptools/pull/2865#issuecomment-965700112 + warnings.filterwarnings( + 'ignore', + 'The distutils.sysconfig module is deprecated, use sysconfig instead', + ) From 65fab2fade018f404b323f66fa492d5aadf55001 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 16:27:34 -0500 Subject: [PATCH 09/14] Suppress 'Distutils was imported before Setuptools' warning on PyPy due to pypa/setuptools#2868. --- conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/conftest.py b/conftest.py index 3f80b495cc..f82b939bd9 100644 --- a/conftest.py +++ b/conftest.py @@ -36,3 +36,16 @@ def pytest_addoption(parser): 'ignore', 'The distutils.sysconfig module is deprecated, use sysconfig instead', ) + + +is_pypy = '__pypy__' in sys.builtin_module_names +if is_pypy: + # Workaround for pypa/setuptools#2868 + warnings.filterwarnings( + 'ignore', + 'Distutils was imported before setuptools', + ) + warnings.filterwarnings( + 'ignore', + 'Setuptools is replacing distutils', + ) From 2ceec37662b7b053ca6ffc328d95ba838bf26a2b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 17:17:18 -0500 Subject: [PATCH 10/14] Move warning suppression to pytest.ini so it occurs after 'error'. --- conftest.py | 22 ---------------------- pytest.ini | 12 ++++++++++++ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/conftest.py b/conftest.py index f82b939bd9..d5e851fe50 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,4 @@ import sys -import warnings pytest_plugins = 'setuptools.tests.fixtures' @@ -28,24 +27,3 @@ def pytest_addoption(parser): if sys.version_info < (3, 6): collect_ignore.append('docs/conf.py') # uses f-strings collect_ignore.append('pavement.py') - - -if sys.version_info > (3, 10): - # https://github.com/pypa/setuptools/pull/2865#issuecomment-965700112 - warnings.filterwarnings( - 'ignore', - 'The distutils.sysconfig module is deprecated, use sysconfig instead', - ) - - -is_pypy = '__pypy__' in sys.builtin_module_names -if is_pypy: - # Workaround for pypa/setuptools#2868 - warnings.filterwarnings( - 'ignore', - 'Distutils was imported before setuptools', - ) - warnings.filterwarnings( - 'ignore', - 'Setuptools is replacing distutils', - ) diff --git a/pytest.ini b/pytest.ini index 2678afd846..df1c2af91d 100644 --- a/pytest.ini +++ b/pytest.ini @@ -34,3 +34,15 @@ filterwarnings= # https://github.com/pypa/setuptools/issues/2497 ignore:.* is an invalid version and will not be supported::pkg_resources + + # https://github.com/pypa/setuptools/pull/2865#issuecomment-965700112 + # ideally would apply to Python 3.10+ when + # SETUPTOOLS_USE_DISTUTILS=stdlib but for + # https://github.com/pytest-dev/pytest/discussions/9296 + ignore:The distutils.sysconfig module is deprecated, use sysconfig instead + + # Workaround for pypa/setuptools#2868 + # ideally would apply to PyPy only but for + # https://github.com/pytest-dev/pytest/discussions/9296 + ignore:Distutils was imported before setuptools + ignore:Setuptools is replacing distutils From c0f549533fe9a6d4d4cad157f2dcea860a34fd6e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 17:27:58 -0500 Subject: [PATCH 11/14] Remove superfluous dep. --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 8940a18251..ab993608af 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,6 @@ toxworkdir={env:TOX_WORK_DIR:.tox} [testenv] deps = - pytest # workaround for sphinx-doc/sphinx#9562 # TODO: remove after Sphinx>4.1.2 is available. sphinx@git+https://github.com/sphinx-doc/sphinx; python_version>="3.10" From 39e3806dc22c8e47eca12b80c57245615d45b6a2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 10 Nov 2021 21:41:02 -0500 Subject: [PATCH 12/14] Disable some virtualenv integration tests for PyPy. --- setuptools/tests/test_virtualenv.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setuptools/tests/test_virtualenv.py b/setuptools/tests/test_virtualenv.py index 2abedfc79d..5cd49a0f1b 100644 --- a/setuptools/tests/test_virtualenv.py +++ b/setuptools/tests/test_virtualenv.py @@ -89,6 +89,10 @@ def skip_network(param): return list(versions) +@pytest.mark.skipif( + 'platform.python_implementation() == "PyPy"', + reason="https://github.com/pypa/setuptools/pull/2865#issuecomment-965834995", +) @pytest.mark.parametrize('pip_version', _get_pip_versions()) def test_pip_upgrade_from_source(pip_version, tmp_src, virtualenv): """ From 354208206b2146eee0c9117de969d98c9aa8447b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 11 Nov 2021 09:02:31 -0500 Subject: [PATCH 13/14] Avoid upgrading setuptools when creating the venv for distutils_adoption tests. Works around issue with upgrading on PyPy. --- setup.cfg | 2 +- setuptools/tests/test_distutils_adoption.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 66cad330a2..44b1af2b02 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,7 @@ testing = wheel paver pip>=19.1 # For proper file:// URLs support. - jaraco.envs + jaraco.envs>=2.2 pytest-xdist sphinx jaraco.path>=3.2.0 diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py index 0e89921c90..006480dde5 100644 --- a/setuptools/tests/test_distutils_adoption.py +++ b/setuptools/tests/test_distutils_adoption.py @@ -9,11 +9,13 @@ import path -IS_PYPY = '__pypy__' in sys.builtin_module_names - - class VirtualEnv(jaraco.envs.VirtualEnv): name = '.env' + # Some version of PyPy will import distutils on startup, implicitly + # importing setuptools, and thus leading to BackendInvalid errors + # when upgrading Setuptools. Bypass this behavior by avoiding the + # early availability and need to upgrade. + create_opts = ['--no-setuptools'] def run(self, cmd, *args, **kwargs): cmd = [self.exe(cmd[0])] + cmd[1:] @@ -61,7 +63,6 @@ def test_distutils_local_with_setuptools(venv): assert venv.name in loc.split(os.sep) -@pytest.mark.xfail('IS_PYPY', reason='pypy imports distutils on startup') def test_distutils_local(venv): """ Even without importing, the setuptools-local copy of distutils is From ba6aa7cc011db953ad388a37c482cb00f4fb978d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 11 Nov 2021 21:39:23 -0500 Subject: [PATCH 14/14] Bring back the xfail as it appears to be needed at least on macOS. --- setuptools/tests/test_distutils_adoption.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py index 006480dde5..b6b9c00eaf 100644 --- a/setuptools/tests/test_distutils_adoption.py +++ b/setuptools/tests/test_distutils_adoption.py @@ -9,6 +9,9 @@ import path +IS_PYPY = '__pypy__' in sys.builtin_module_names + + class VirtualEnv(jaraco.envs.VirtualEnv): name = '.env' # Some version of PyPy will import distutils on startup, implicitly @@ -63,6 +66,7 @@ def test_distutils_local_with_setuptools(venv): assert venv.name in loc.split(os.sep) +@pytest.mark.xfail('IS_PYPY', reason='pypy imports distutils on startup') def test_distutils_local(venv): """ Even without importing, the setuptools-local copy of distutils is