From e6bc8736983122adea222bf30f299dce551152ff Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 12 Nov 2018 11:06:34 -0500 Subject: [PATCH 1/5] Prevent DistutilsOptionError when prefix is indicated in the global environment and --target is used. Fixes #4106. --- src/pip/_internal/locations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/locations.py b/src/pip/_internal/locations.py index 183aaa39299..a4c79135014 100644 --- a/src/pip/_internal/locations.py +++ b/src/pip/_internal/locations.py @@ -157,7 +157,7 @@ def distutils_scheme(dist_name, user=False, home=None, root=None, # ideally, we'd prefer a scheme class that has no side-effects. assert not (user and prefix), "user={} prefix={}".format(user, prefix) i.user = user or i.user - if user: + if user or home: i.prefix = "" i.prefix = prefix or i.prefix i.home = home or i.home From 65c38650f6788a35e5474871dfe9d055e644cd51 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 12 Nov 2018 11:09:56 -0500 Subject: [PATCH 2/5] Extend sanity check on user+prefix to include similar check for home+prefix. Ref #4106. --- src/pip/_internal/locations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pip/_internal/locations.py b/src/pip/_internal/locations.py index a4c79135014..cd33969a024 100644 --- a/src/pip/_internal/locations.py +++ b/src/pip/_internal/locations.py @@ -156,6 +156,7 @@ def distutils_scheme(dist_name, user=False, home=None, root=None, # or user base for installations during finalize_options() # ideally, we'd prefer a scheme class that has no side-effects. assert not (user and prefix), "user={} prefix={}".format(user, prefix) + assert not (home and prefix), "home={} prefix={}".format(home, prefix) i.user = user or i.user if user or home: i.prefix = "" From a66c696b995a6e9dbfc49f80a9c550dd668b4a03 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 12 Nov 2018 11:14:36 -0500 Subject: [PATCH 3/5] Add news entry. Ref #6008. --- news/6008.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/6008.bugfix diff --git a/news/6008.bugfix b/news/6008.bugfix new file mode 100644 index 00000000000..ff83dfa0275 --- /dev/null +++ b/news/6008.bugfix @@ -0,0 +1 @@ +Prevent DistutilsOptionError when prefix is indicated in the global environment and `--target` is used. From 3f013349642cdebccc80c916dd0f2c7826179779 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 12 Nov 2018 13:05:46 -0500 Subject: [PATCH 4/5] Add test capturing expectation. Ref #4106. --- tests/functional/test_install.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 1be8e10e392..2cc76bb939e 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1473,3 +1473,19 @@ def test_install_conflict_warning_can_be_suppressed(script, data): 'install', '--no-index', pkgB_path, '--no-warn-conflicts' ) assert "Successfully installed pkgB-2.0" in result2.stdout, str(result2) + + +def test_target_install_ignores_distutils_config_install_prefix(script): + prefix = script.scratch_path / 'prefix' + Path(os.environ['HOME'], '.pydistutils.cfg').write(textwrap.dedent( + ''' + [install] + prefix=%s + ''' % str(prefix))) + target = script.scratch_path / 'target' + result = script.pip_install_local('simplewheel', '-t', target) + assert ( + "Successfully installed simplewheel" in result.stdout and + (target - script.base_path) in result.files_created and + (prefix - script.base_path) not in result.files_created + ), str(result) From da9caa4a2c0d4168d79d1693967674c778253b24 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 12 Nov 2018 15:46:29 -0500 Subject: [PATCH 5/5] Fix test failures on Windows. --- tests/functional/test_install.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 2cc76bb939e..9ba75bdd40b 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1477,7 +1477,10 @@ def test_install_conflict_warning_can_be_suppressed(script, data): def test_target_install_ignores_distutils_config_install_prefix(script): prefix = script.scratch_path / 'prefix' - Path(os.environ['HOME'], '.pydistutils.cfg').write(textwrap.dedent( + distutils_config = Path(os.path.expanduser('~'), + 'pydistutils.cfg' if sys.platform == 'win32' + else '.pydistutils.cfg') + distutils_config.write(textwrap.dedent( ''' [install] prefix=%s