提交 f76014ef 编写于 作者: P Prabakaran Kumaresshan 提交者: Chris Jerdonek

Add global options and no user config args to make_setuptools_shim_args (#6706)

上级 2cd26a22
......@@ -616,9 +616,10 @@ class InstallRequirement(object):
'Running setup.py (path:%s) egg_info for package from %s',
self.setup_py_path, self.link,
)
base_cmd = make_setuptools_shim_args(self.setup_py_path)
if self.isolated:
base_cmd += ["--no-user-cfg"]
base_cmd = make_setuptools_shim_args(
self.setup_py_path,
no_user_config=self.isolated
)
egg_info_cmd = base_cmd + ['egg_info']
# We can't put the .egg-info files at the root, because then the
# source code will be mistaken for an installed egg, causing
......@@ -763,19 +764,19 @@ class InstallRequirement(object):
# type: (...) -> None
logger.info('Running setup.py develop for %s', self.name)
if self.isolated:
global_options = list(global_options) + ["--no-user-cfg"]
if prefix:
prefix_param = ['--prefix={}'.format(prefix)]
install_options = list(install_options) + prefix_param
base_cmd = make_setuptools_shim_args(
self.setup_py_path,
global_options=global_options,
no_user_config=self.isolated
)
with indent_log():
# FIXME: should we do --install-headers here too?
with self.build_env:
call_subprocess(
make_setuptools_shim_args(self.setup_py_path) +
list(global_options) +
base_cmd +
['develop', '--no-deps'] +
list(install_options),
......@@ -948,10 +949,6 @@ class InstallRequirement(object):
install_options = list(install_options) + \
self.options.get('install_options', [])
if self.isolated:
# https://github.com/python/mypy/issues/1174
global_options = global_options + ["--no-user-cfg"] # type: ignore
with TempDirectory(kind="record") as temp_dir:
record_filename = os.path.join(temp_dir.path, 'install-record.txt')
install_args = self.get_install_args(
......@@ -1018,10 +1015,13 @@ class InstallRequirement(object):
pycompile # type: bool
):
# type: (...) -> List[str]
install_args = make_setuptools_shim_args(self.setup_py_path,
unbuffered_output=True)
install_args += list(global_options) + \
['install', '--record', record_filename]
install_args = make_setuptools_shim_args(
self.setup_py_path,
global_options=global_options,
no_user_config=self.isolated,
unbuffered_output=True
)
install_args += ['install', '--record', record_filename]
install_args += ['--single-version-externally-managed']
if root is not None:
......
......@@ -3,7 +3,7 @@ import sys
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import List
from typing import List, Sequence
# Shim to wrap setup.py invocation with setuptools
#
......@@ -20,12 +20,19 @@ _SETUPTOOLS_SHIM = (
)
def make_setuptools_shim_args(setup_py_path, unbuffered_output=False):
# type: (str, bool) -> List[str]
def make_setuptools_shim_args(
setup_py_path, # type: str
global_options=None, # type: Sequence[str]
no_user_config=False, # type: bool
unbuffered_output=False # type: bool
):
# type: (...) -> List[str]
"""
Get setuptools command arguments with shim wrapped setup file invocation.
:param setup_py_path: The path to setup.py to be wrapped.
:param global_options: Additional global options.
:param no_user_config: If True, disables personal user configuration.
:param unbuffered_output: If True, adds the unbuffered switch to the
argument list.
"""
......@@ -33,4 +40,8 @@ def make_setuptools_shim_args(setup_py_path, unbuffered_output=False):
if unbuffered_output:
args.append('-u')
args.extend(['-c', _SETUPTOOLS_SHIM.format(setup_py_path)])
if global_options:
args.extend(global_options)
if no_user_config:
args.append('--no-user-cfg')
return args
......@@ -934,9 +934,11 @@ class WheelBuilder(object):
# isolating. Currently, it breaks Python in virtualenvs, because it
# relies on site.py to find parts of the standard library outside the
# virtualenv.
base_cmd = make_setuptools_shim_args(req.setup_py_path,
unbuffered_output=True)
return base_cmd + list(self.global_options)
return make_setuptools_shim_args(
req.setup_py_path,
global_options=self.global_options,
unbuffered_output=True
)
def _build_one_pep517(self, req, tempd, python_tag=None):
"""Build one InstallRequirement using the PEP 517 build process.
......
......@@ -1405,16 +1405,54 @@ def test_deprecated_message_reads_well():
)
@pytest.mark.parametrize("unbuffered_output", [False, True])
def test_make_setuptools_shim_args(unbuffered_output):
def test_make_setuptools_shim_args():
# Test all arguments at once, including the overall ordering.
args = make_setuptools_shim_args(
"/dir/path/setup.py",
unbuffered_output=unbuffered_output
'/dir/path/setup.py',
global_options=['--some', '--option'],
no_user_config=True,
unbuffered_output=True,
)
assert args[1:3] == ['-u', '-c']
# Spot-check key aspects of the command string.
assert "sys.argv[0] = '/dir/path/setup.py'" in args[3]
assert "__file__='/dir/path/setup.py'" in args[3]
assert args[4:] == ['--some', '--option', '--no-user-cfg']
@pytest.mark.parametrize('global_options', [
None,
[],
['--some', '--option']
])
def test_make_setuptools_shim_args__global_options(global_options):
args = make_setuptools_shim_args(
'/dir/path/setup.py',
global_options=global_options,
)
assert ("-u" in args) == unbuffered_output
if global_options:
assert len(args) == 5
for option in global_options:
assert option in args
else:
assert len(args) == 3
assert args[-2] == "-c"
assert "sys.argv[0] = '/dir/path/setup.py'" in args[-1]
assert "__file__='/dir/path/setup.py'" in args[-1]
@pytest.mark.parametrize('no_user_config', [False, True])
def test_make_setuptools_shim_args__no_user_config(no_user_config):
args = make_setuptools_shim_args(
'/dir/path/setup.py',
no_user_config=no_user_config,
)
assert ('--no-user-cfg' in args) == no_user_config
@pytest.mark.parametrize('unbuffered_output', [False, True])
def test_make_setuptools_shim_args__unbuffered_output(unbuffered_output):
args = make_setuptools_shim_args(
'/dir/path/setup.py',
unbuffered_output=unbuffered_output
)
assert ('-u' in args) == unbuffered_output
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册