Skip to content

Commit

Permalink
Add global options and no user config args to make_setuptools_shim_ar…
Browse files Browse the repository at this point in the history
…gs (#6706)
  • Loading branch information
nixphix authored and cjerdonek committed Jul 28, 2019
1 parent 2cd26a2 commit f76014e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 31 deletions.
34 changes: 17 additions & 17 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,10 @@ def run_egg_info(self):
'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
Expand Down Expand Up @@ -763,19 +764,19 @@ def install_editable(
# 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),

Expand Down Expand Up @@ -948,10 +949,6 @@ def install(
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(
Expand Down Expand Up @@ -1018,10 +1015,13 @@ def get_install_args(
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:
Expand Down
17 changes: 14 additions & 3 deletions src/pip/_internal/utils/setuptools_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
#
Expand All @@ -20,17 +20,28 @@
)


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.
"""
args = [sys.executable]
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
8 changes: 5 additions & 3 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,11 @@ def _base_setup_args(self, req):
# 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.
Expand Down
54 changes: 46 additions & 8 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f76014e

Please sign in to comment.