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 <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Apr 16, 2020
1 parent 1ed3db1 commit 93348be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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
16 changes: 16 additions & 0 deletions tests/unit/test_run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import absolute_import, unicode_literals

import subprocess
import sys

import pytest
import six

Expand Down Expand Up @@ -31,3 +34,16 @@ def test_version(capsys):
import virtualenv

assert virtualenv.__file__ in content


def test_cli_run_setuptools_compatible(capfd, tmp_path):
subprocess.check_call(
[
sys.executable,
"-c",
"from setuptools import find_packages;" "from virtualenv import cli_run; cli_run([r'{}'])".format(tmp_path),
]
)
out, err = capfd.readouterr()
assert out
assert not err

0 comments on commit 93348be

Please sign in to comment.