Repository: pypa/pip

Issue:
[10.0.0beta] Warning when --target is used on package with scripts
* Pip version: 10.0.0b2
* Python version: 3.7b3
* Operating system: macOS

### Description:

When installing a package with console scripts and using `-t`, a warning is emitted that the scripts aren't on the path... a temporary path created by pip. It seems this warning will always be issued for a `-t` install because the temporary directory will never be on the path.

### What I've run:

```
$ pip install -q -t foo tempora
  The script calc-prorate is installed in '/private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-target-sm2e38ei/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
```

Attempting to make the scripts available is no help, because the warning is about the pip temporary directory:

```
$ PATH=$PATH:$(pwd)/foo/bin pip install -q -t foo tempora
  The script calc-prorate is installed in '/private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-target-pud5t6iv/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
```


Discussion:
I think this is an unfortunate interaction between `-t` and the script warning - the `-t` argument doesn't install scripts at all (note that the console scripts in your example never ended up in the `foo` directory), it just never copies them out of the temporary build directory. The script warning doesn't special-case that situation.

I think the solution is a simple fix to https://github.com/pypa/pip/blob/master/src/pip/_internal/commands/install.py#L328 setting `warn_script_location` to `False` if `options.target_dir` is set. I'll try to put together a test and fix this evening.
BTW, thanks for reporting this :-)

Resolving patch:
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
@@ -317,6 +317,12 @@ def run(self, options, args):
                     if should_warn_about_conflicts:
                         self._warn_about_conflicts(to_install)
 
+                    # Don't warn about script install locations if
+                    # --target has been specified
+                    warn_script_location = options.warn_script_location
+                    if options.target_dir:
+                        warn_script_location = False
+
                     installed = install_given_reqs(
                         to_install,
                         install_options,
@@ -325,7 +331,7 @@ def run(self, options, args):
                         home=target_temp_dir.path,
                         prefix=options.prefix_path,
                         pycompile=options.compile,
-                        warn_script_location=options.warn_script_location,
+                        warn_script_location=warn_script_location,
                         use_user_site=options.use_user_site,
                     )
 


Test patch:
diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py
--- a/tests/functional/test_install.py
+++ b/tests/functional/test_install.py
@@ -604,6 +604,37 @@ def test_install_package_with_target(script):
     assert singlemodule_py in result.files_updated, str(result)
 
 
+def test_install_with_target_and_scripts_no_warning(script, common_wheels):
+    """
+    Test that installing with --target does not trigger the "script not
+    in PATH" warning (issue #5201)
+    """
+    # We need to have wheel installed so that the project builds via a wheel,
+    # which is the only execution path that has the script warning.
+    script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
+    target_dir = script.scratch_path / 'target'
+    pkga_path = script.scratch_path / 'pkga'
+    pkga_path.mkdir()
+    pkga_path.join("setup.py").write(textwrap.dedent("""
+        from setuptools import setup
+        setup(name='pkga',
+              version='0.1',
+              py_modules=["pkga"],
+              entry_points={
+                  'console_scripts': ['pkga=pkga:main']
+              }
+        )
+    """))
+    pkga_path.join("pkga.py").write(textwrap.dedent("""
+        def main(): pass
+    """))
+    result = script.pip('install', '--target', 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.
+    assert "--no-warn-script-location" not in result.stderr, str(result)
+
+
 def test_install_package_with_root(script, data):
     """
     Test installing a package using pip install --root