Skip to content

Commit

Permalink
Setuptools compatibility with cli_run
Browse files Browse the repository at this point in the history
Signed-off-by: Bernat Gabor <[email protected]>
  • Loading branch information
gaborbernat committed Apr 16, 2020
1 parent 1ed3db1 commit fc40c7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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()

0 comments on commit fc40c7f

Please sign in to comment.