Skip to content

Commit

Permalink
Suppress "not on PATH" warning when --prefix is given
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Nikita Chepanov authored and uranusjr committed Jul 12, 2021
1 parent 7cae5f2 commit f2ce774
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/9931.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress "not on PATH" warning when ``--prefix`` is given.
4 changes: 2 additions & 2 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,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(
Expand Down
8 changes: 6 additions & 2 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f2ce774

Please sign in to comment.