Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ensure_local_distutils, re-use DistutilsMetaFinder #2907

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Nov 26, 2021

Summary of changes

Closes #2906.

Pull Request Checklist

…ule. Avoids race conditions when _distutils_system_mod is employed and fixes #2906.
@jaraco
Copy link
Member Author

jaraco commented Nov 26, 2021

I'm unable to replicate the test failures on my local macOS machine. And when I try to test on a Linux machine, I'm stumbling on an issue failing to build pytest-virtualenv from source (oh, right, because it doesn't build under PEP 517 (man-group/pytest-plugins#190)). After getting the build to run, I'm still unable to replicate the failures happening in CI.

Maybe I'm unable to replicate the failures because I'm selectively running the tests. Nope, running the full test suite still passes for me on macOS and Linux. I'm unsure what factor is relevant to these failures.

I'm now attempting to troubleshoot the issue by pushing troubleshooting code to CI.

@jaraco
Copy link
Member Author

jaraco commented Nov 26, 2021

I put an assertion in the code and that assertion gives some hint as to what's going on:

__________________ ERROR at setup of test_tests_are_run_once ___________________
[gw0] linux -- Python 3.9.9 /home/runner/work/setuptools/setuptools/.tox/python/bin/python

    @pytest.fixture
    def quiet_log():
        # Running some of the other tests will automatically
        # change the log level to info, messing our output.
        import distutils
>       assert log is distutils.dist.log, \
            (log, distutils.dist.log)
E       AssertionError: (<module 'distutils.log' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/log.py'>, <module 'setuptools._distutils.log' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/log.py'>)
E       assert log is <module 'setuptools._distutils.log' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/log.py'>
E        +  where <module 'setuptools._distutils.log' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/log.py'> = <module 'distutils.dist' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/dist.py'>.log
E        +    where <module 'distutils.dist' from '/home/runner/work/setuptools/setuptools/setuptools/_distutils/dist.py'> = <module 'distutils' (<_distutils_hack.DistutilsMetaFinder.spec_for_distutils.<locals>.DistutilsLoader object at 0x7f8625e9ed60>)>.dist

/home/runner/work/setuptools/setuptools/setuptools/tests/test_test.py:17: AssertionError

It seems that indeed the distutils.log value is a mismatch. My guess is that in this CI environment, there's something that allows that value to bind early to a different object, likely due to

def hide_setuptools():
"""
Remove references to setuptools' modules from sys.modules to allow the
invocation to import the most appropriate setuptools. This technique is
necessary to avoid issues such as #315 where setuptools upgrading itself
would fail to find a function declared in the metadata.
"""
_distutils_hack = sys.modules.get('_distutils_hack', None)
if _distutils_hack is not None:
_distutils_hack.remove_shim()
modules = filter(_needs_hiding, sys.modules)
_clear_modules(modules)
.

@jaraco
Copy link
Member Author

jaraco commented Nov 26, 2021

Ultimately, I punted on the failing test. It's just one failing test in a deprecated part of the code (test command), so I've adapted the test to assuming that the output could change. Especially since the distutils hacks are temporary, it's more important to ensure compatibility and to unblock the platforms.

@jaraco jaraco merged commit e7a67a3 into main Nov 26, 2021
@jaraco jaraco deleted the bugfix/2906-distutils-race branch November 26, 2021 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distutils submodules being loaded from the stdlib
1 participant