From 2e0ad919e7c51e4c906a08ce41ae6a5e5b2da8f3 Mon Sep 17 00:00:00 2001 From: Nikita Chepanov Date: Fri, 30 Apr 2021 14:59:34 -0400 Subject: [PATCH] Suppress "not on PATH" warning when `--prefix` is given Similar to how it works with `--target`, avoid printing the warning since it's clear from the context that the final destionation of the executables is unlikely to be in the PATH. --- news/9931.feature.rst | 1 + src/pip/_internal/commands/install.py | 4 ++-- tests/functional/test_install.py | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 news/9931.feature.rst diff --git a/news/9931.feature.rst b/news/9931.feature.rst new file mode 100644 index 00000000000..0ea1cbf7837 --- /dev/null +++ b/news/9931.feature.rst @@ -0,0 +1 @@ +Suppress "not on PATH" warning when ``--prefix`` is given. diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 6932f5a6d8b..3072d033e19 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -385,9 +385,9 @@ def run(self, options, args): conflicts = self._determine_conflicts(to_install) # Don't warn about script install locations if - # --target has been specified + # --target or --prefix has been specified warn_script_location = options.warn_script_location - if options.target_dir: + if options.target_dir or options.prefix_path: warn_script_location = False installed = install_given_reqs( diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 2742e873e33..8ae8ab80c2c 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -960,7 +960,8 @@ def test_install_nonlocal_compatible_wheel_path( assert result.returncode == ERROR -def test_install_with_target_and_scripts_no_warning(script, with_wheel): +@pytest.mark.parametrize('opt', ('--target', '--prefix')) +def test_install_with_target_or_prefix_and_scripts_no_warning(opt, script, with_wheel): """ Test that installing with --target does not trigger the "script not in PATH" warning (issue #5201) @@ -981,7 +982,7 @@ def test_install_with_target_and_scripts_no_warning(script, with_wheel): pkga_path.joinpath("pkga.py").write_text(textwrap.dedent(""" def main(): pass """)) - result = script.pip('install', '--target', target_dir, pkga_path) + result = script.pip('install', opt, target_dir, pkga_path) # This assertion isn't actually needed, if we get the script warning # the script.pip() call will fail with "stderr not expected". But we # leave the assertion to make the intention of the code clearer. @@ -1666,6 +1667,9 @@ def test_install_from_test_pypi_with_ext_url_dep_is_blocked(script, index): assert error_cause in res.stderr, str(res) +@pytest.mark.xfail( + reason="No longer possible to trigger the warning with either --prefix or --target" +) def test_installing_scripts_outside_path_prints_warning(script): result = script.pip_install_local( "--prefix", script.scratch_path, "script_wheel1"