Repository: pypa/pipenv

Issue:
pipenv ignore environment variable `PIP_TARGET` when calculate dependancy delta.
### Issue description

Sometimes I use pipenv with environment variable `PIP_TARGET` for install libraries to specified directory.
But pipenv will skip install libraries if libraries already install to default location.





### Expected result

pipenv should install libraries to specified directory when exec with environment variable `PIP_TARGET`.



### Actual result

pipenv will skip install libraries to specified directory when libraries already installed to default location(`.venv/lib/pythonx.x/site-packages`).



### Steps to replicate

1. install some library and create Pipfile.lock

```
pipenv install six
```



2. Create some directory for specify pip install target.

```mkdir layers
mkdir layer
```



3. Try install library to specified directory.

```
PIP_TARGET=layer  pipenv sync
Installing dependencies from Pipfile.lock (34ad89)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 0
```

Install library will skip and output `0/0 — 00:00:00`

4. List specified directory.There are no library.

```
ls layer
```

This command will return empty result.


<details><summary>$ pipenv --support</summary>

Pipenv version: `'2020.6.2'`

Pipenv location: `'/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/lib/python3.8/site-packages/pipenv'`

Python location: `'/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/bin/python3.8'`

Python installations found:

  - `3.9.2`: `/usr/local/bin/python3`
  - `3.9.2`: `/usr/local/bin/python3.9`
  - `3.8.3`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/bin/python3`
  - `3.8.3`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/bin/python3.8`
  - `3.8.3`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/bin/python3`
  - `3.7.8`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.7.8/bin/python3`
  - `3.7.3`: `/usr/bin/python3`
  - `3.6.5`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.6.5/bin/python3`
  - `3.6.1`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.6.1/bin/python3`
  - `2.7.16`: `/usr/bin/python2`
  - `2.7.16`: `/usr/bin/python2.7`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.8.3',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '19.5.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT '
                     '2020; root:xnu-6153.121.2~2/RELEASE_X86_64',
 'python_full_version': '3.8.3',
 'python_version': '3.8',
 'sys_platform': 'darwin'}
```

System environment variables:

  - `LDFLAGS`
  - `TERM_PROGRAM`
  - `NODENV_SHELL`
  - `PYENV_ROOT`
  - `SHELL`
  - `TERM`
  - `TMPDIR`
  - `CPPFLAGS`
  - `PIPENV_VENV_IN_PROJECT`
  - `TERM_PROGRAM_VERSION`
  - `GOENV_ROOT`
  - `TERM_SESSION_ID`
  - `PYENV_VERSION`
  - `NODENV_ROOT`
  - `LC_ALL`
  - `USER`
  - `RBENV_ROOT`
  - `SSH_AUTH_SOCK`
  - `PYENV_DIR`
  - `__CF_USER_TEXT_ENCODING`
  - `PATH`
  - `LaunchInstanceID`
  - `PWD`
  - `LANG`
  - `ITERM_PROFILE`
  - `CLOUDSDK_PYTHON`
  - `PYENV_HOOK_PATH`
  - `XPC_FLAGS`
  - `RBENV_SHELL`
  - `XPC_SERVICE_NAME`
  - `HISTCONTROL`
  - `COLORFGBG`
  - `HOME`
  - `SHLVL`
  - `PYENV_SHELL`
  - `LC_TERMINAL_VERSION`
  - `ITERM_SESSION_ID`
  - `LOGNAME`
  - `GOENV_SHELL`
  - `LC_TERMINAL`
  - `SECURITYSESSIONID`
  - `COLORTERM`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIP_SHIMS_BASE_MODULE`
  - `PIP_PYTHON_PATH`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:

 - `PIPENV_VENV_IN_PROJECT`: `1`

Debug–specific environment variables:

  - `PATH`: `/Users/cm-iwata/.anyenv/envs/pyenv/versions/3.8.3/bin:/Users/cm-iwata/.anyenv/envs/pyenv/libexec:/Users/cm-iwata/.anyenv/envs/pyenv/plugins/python-build/bin:/Users/cm-iwata/gcp/google-cloud-sdk/bin:/usr/local/bin:/usr/local/opt/mysql-client/bin:/Users/cm-iwata/.anyenv/envs/rbenv/shims:/Users/cm-iwata/.anyenv/envs/rbenv/bin:/Users/cm-iwata/.anyenv/envs/pyenv/shims:/Users/cm-iwata/.anyenv/envs/pyenv/bin:/Users/cm-iwata/.anyenv/envs/nodenv/shims:/Users/cm-iwata/.anyenv/envs/nodenv/bin:/Users/cm-iwata/.anyenv/envs/goenv/shims:/Users/cm-iwata/.anyenv/envs/goenv/bin:/Users/cm-iwata/.anyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Applications/Visual Studio Code.app/Contents/Resources/app/bin`
  - `SHELL`: `/bin/bash`
  - `LANG`: `en_US.UTF-8`
  - `PWD`: `/tmp/pipenvtest2`


---------------------------

Contents of `Pipfile` ('/private/tmp/pipenvtest2/Pipfile'):

```toml
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
six = "*"

[requires]
python_version = "3.8"

```


Contents of `Pipfile.lock` ('/private/tmp/pipenvtest2/Pipfile.lock'):

```json
{
    "_meta": {
        "hash": {
            "sha256": "d9b5cc506fc4feb9bf1ae7cadfd3737d5a0bd2b2d6c3fbcf0de3458bab34ad89"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.8"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "six": {
            "hashes": [
                "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
                "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
            ],
            "index": "pypi",
            "version": "==1.16.0"
        }
    },
    "develop": {}
}

```
</details>






Discussion:

Resolving patch:
diff --git a/pipenv/environment.py b/pipenv/environment.py
--- a/pipenv/environment.py
+++ b/pipenv/environment.py
@@ -540,7 +540,8 @@ def get_distributions(self):
         :rtype: iterator
         """
 
-        libdirs = self.base_paths["libdirs"].split(os.pathsep)
+        pip_target_dir = os.environ.get('PIP_TARGET')
+        libdirs = [pip_target_dir] if pip_target_dir else self.base_paths["libdirs"].split(os.pathsep)
         dists = (pkg_resources.find_distributions(libdir) for libdir in libdirs)
         yield from itertools.chain.from_iterable(dists)
 


Test patch:
diff --git a/tests/integration/test_sync.py b/tests/integration/test_sync.py
--- a/tests/integration/test_sync.py
+++ b/tests/integration/test_sync.py
@@ -111,3 +111,30 @@ def test_sync_sequential_verbose(PipenvInstance):
         c = p.pipenv('sync --sequential --verbose')
         for package in p.lockfile['default']:
             assert f'Successfully installed {package}' in c.stdout
+
+
+@pytest.mark.sync
+def test_sync_consider_pip_target(PipenvInstance):
+    """
+    """
+    with PipenvInstance(chdir=True) as p:
+        with open(p.pipfile_path, 'w') as f:
+            f.write("""
+[packages]
+six = "*"
+            """.strip())
+
+        # Perform initial lock.
+        c = p.pipenv('lock')
+        assert c.returncode == 0
+        lockfile_content = p.lockfile
+        assert lockfile_content
+        c = p.pipenv('sync')
+        assert c.returncode == 0
+
+        pip_target_dir = 'target_dir'
+        os.environ['PIP_TARGET'] = pip_target_dir
+        c = p.pipenv('sync')
+        assert c.returncode == 0
+        assert 'six.py' in os.listdir(os.path.join(p.path, pip_target_dir))
+        os.environ.pop('PIP_TARGET')