Skip to content

Setuptools compatibility with cli_run #1771

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

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/1771.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Importing setuptools before cli_run could cause our python information query to fail due to setuptools patching
``distutils.dist.Distribution`` - by :user:`gaborbernat`.
5 changes: 3 additions & 2 deletions src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import sys
import sysconfig
from collections import OrderedDict, namedtuple
from distutils import dist
from distutils.command.install import SCHEME_KEYS
from distutils.dist import Distribution
from string import digits

VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"])
Expand Down Expand Up @@ -110,7 +110,8 @@ def _fast_get_system_executable(self):
@staticmethod
def _distutils_install():
# follow https://github.com./pypa/pip/blob/master/src/pip/_internal/locations.py#L95
d = Distribution({"script_args": "--no-user-cfg"}) # configuration files not parsed so they do not hijack paths
# note here we don't import Distribution directly to allow setuptools to patch it
d = dist.Distribution({"script_args": "--no-user-cfg"}) # conf files not parsed so they do not hijack paths
if hasattr(sys, "_framework"):
sys._framework = None # disable macOS static paths for framework
i = d.get_command_obj("install", create=True)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/discovery/py_info/test_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,10 @@ def test_discover_exe_on_path_non_spec_name_not_match(mocker):
CURRENT, "original_executable", str(Path(CURRENT.executable).parent / "e{}".format(suffixed_name))
)
assert CURRENT.satisfies(spec, impl_must_match=True) is False


def test_py_info_setuptools():
from setuptools.dist import Distribution

assert Distribution
PythonInfo()