Repository: pypa/pipenv

Issue:
Newly added / changed sources not used
When an environment variable source (possibly any source) is updated in the Pipfile, the new source isn't used for resolution when `pipenv install` or `pipenv lock` is next run.

See for example:

<details><summary>Pipfile</summary>

```
[[source]]
url = "https://pypi.python.org/${ENV_VAR}"
verify_ssl = true

[dev-packages]
pytest = "==3.4.0"

[packages]
requests = "==2.18.0"
```

</details>

<details><summary>Pipfile.lock</summary>

```
{
    "_meta": {
        "hash": {
            "sha256": "5f70d907b20123fa92bd105fff99886abbf573b68009a4eb8dfd3e18144ab001"
        },
        "pipfile-spec": 6,
        "requires": {},
        "sources": [
            {
                "url": "https://pypi.python.org/${ENV_VAR}",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "certifi": {
            "hashes": [
                "sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
                "sha256:9fa520c1bacfb634fa7af20a76bcbd3d5fb390481724c597da32c719a7dca4b0"
            ],
            "version": "==2018.4.16"
        },
        "chardet": {
            "hashes": [
                "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
                "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
            ],
            "version": "==3.0.4"
        },
        "idna": {
            "hashes": [
                "sha256:3cb5ce08046c4e3a560fc02f138d0ac63e00f8ce5901a56b32ec8b7994082aab",
                "sha256:cc19709fd6d0cbfed39ea875d29ba6d4e22c0cebc510a76d6302a28385e8bb70"
            ],
            "version": "==2.5"
        },
        "requests": {
            "hashes": [
                "sha256:5e88d64aa56ac0fda54e77fb9762ebc65879e171b746d5479a33c4082519d6c6",
                "sha256:cd0189f962787284bff715fddaad478eb4d9c15aa167bd64e52ea0f661e7ea5c"
            ],
            "version": "==2.18.0"
        },
        "urllib3": {
            "hashes": [
                "sha256:8ed6d5c1ff9d6ba84677310060d6a3a78ca3072ce0684cb3c645023009c114b1",
                "sha256:b14486978518ca0901a76ba973d7821047409d7f726f22156b24e83fd71382a5"
            ],
            "version": "==1.21.1"
        }
    },
    "develop": {
        "attrs": {
            "hashes": [
                "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9",
                "sha256:a17a9573a6f475c99b551c0e0a812707ddda1ec9653bed04c13841404ed6f450"
            ],
            "version": "==17.4.0"
        },
        "funcsigs": {
            "hashes": [
                "sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca",
                "sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50"
            ],
            "markers": "python_version < '3.0'",
            "version": "==1.0.2"
        },
        "pluggy": {
            "hashes": [
                "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff",
                "sha256:d345c8fe681115900d6da8d048ba67c25df42973bda370783cd58826442dcd7c",
                "sha256:e160a7fcf25762bb60efc7e171d4497ff1d8d2d75a3d0df7a21b76821ecbf5c5"
            ],
            "version": "==0.6.0"
        },
        "py": {
            "hashes": [
                "sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881",
                "sha256:983f77f3331356039fdd792e9220b7b8ee1aa6bd2b25f567a963ff1de5a64f6a"
            ],
            "version": "==1.5.3"
        },
        "pytest": {
            "hashes": [
                "sha256:6074ea3b9c999bd6d0df5fa9d12dd95ccd23550df2a582f5f5b848331d2e82ca",
                "sha256:95fa025cd6deb5d937e04e368a00552332b58cae23f63b76c8c540ff1733ab6d"
            ],
            "version": "==3.4.0"
        },
        "six": {
            "hashes": [
                "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
                "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
            ],
            "version": "==1.11.0"
        }
    }
}
```

</details>
<br>

Try updating the source in the Pipfile in the above to `"https://pypi.python.org/${ENV_VAR}"` and installation will still failing, complaining that `https://pypi.python.org/${ENV_VAR}` isn't reachable.

<details><summary>$ python -m pipenv.help output</summary>

Pipenv version: `'11.10.1'`

Pipenv location: `'/Users/greysteil/code/pipenv/pipenv'`

Python location: `'/Users/greysteil/.pyenv/versions/3.6.5/bin/python3'`

Other Python installations in `PATH`:

  - `2.6`: `/usr/bin/python2.6`
  - `2.6`: `/usr/bin/python2.6`
  - `2.7`: `/Users/greysteil/.pyenv/shims/python2.7`
  - `2.7`: `/Users/greysteil/.pyenv/shims/python2.7`
  - `2.7`: `/usr/bin/python2.7`
  - `3.5`: `/Users/greysteil/.pyenv/shims/python3.5`
  - `3.6`: `/Users/greysteil/.pyenv/versions/3.6.5/bin/python3.6m`
  - `3.6`: `/Users/greysteil/.pyenv/versions/3.6.5/bin/python3.6`
  - `3.6`: `/Users/greysteil/.pyenv/shims/python3.6`
  - `3.6`: `/usr/local/bin/python3.6`
  - `3.6`: `/usr/local/bin/python3.6`

  - `3.6.5`: `/Users/greysteil/.pyenv/versions/3.6.5/bin/python`
  - `3.6.5`: `/Users/greysteil/.pyenv/shims/python`
  - `3.6.5`: `/usr/local/bin/python`
  - `3.6.5`: `/usr/local/bin/python`
  - `2.7.10`: `/usr/bin/python`
  - `None`: `/Users/greysteil/.pyenv/shims/python2`
  - `3.6.5`: `/Users/greysteil/.pyenv/versions/3.6.5/bin/python3`
  - `3.6.5`: `/Users/greysteil/.pyenv/shims/python3`
  - `3.6.5`: `/usr/local/bin/python3`
  - `3.6.5`: `/usr/local/bin/python3`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.6.5',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '16.7.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 16.7.0: Wed Oct  4 00:17:00 PDT '
                     '2017; root:xnu-3789.71.6~1/RELEASE_X86_64',
 'python_full_version': '3.6.5',
 'python_version': '3.6',
 'sys_platform': 'darwin'}
```

System environment variables:

  - `TERM_PROGRAM`
  - `PYENV_ROOT`
  - `SHELL`
  - `TERM`
  - `CLICOLOR`
  - `TMPDIR`
  - `Apple_PubSub_Socket_Render`
  - `TERM_PROGRAM_VERSION`
  - `TERM_SESSION_ID`
  - `PYENV_VERSION`
  - `USER`
  - `SSH_AUTH_SOCK`
  - `PYENV_DIR`
  - `__CF_USER_TEXT_ENCODING`
  - `LSCOLORS`
  - `PATH`
  - `PWD`
  - `EDITOR`
  - `LANG`
  - `PYENV_HOOK_PATH`
  - `XPC_FLAGS`
  - `RBENV_SHELL`
  - `XPC_SERVICE_NAME`
  - `SHLVL`
  - `HOME`
  - `PYENV_SHELL`
  - `LOGNAME`
  - `SECURITYSESSIONID`
  - `PYTHONDONTWRITEBYTECODE`
  - `PIP_PYTHON_PATH`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/Users/greysteil/.pyenv/versions/3.6.5/bin:/usr/local/Cellar/pyenv/1.2.3/libexec:/Users/greysteil/.pyenv/plugins/pyenv-virtualenv/bin:/Users/greysteil/.pyenv/plugins/pyenv-update/bin:/Users/greysteil/.pyenv/plugins/pyenv-installer/bin:/Users/greysteil/.pyenv/plugins/pyenv-doctor/bin:/Users/greysteil/.pyenv/shims:/Users/greysteil/.pyenv/bin:/Users/greysteil/.cargo/bin:/usr/local/heroku/bin:/Users/greysteil/.rbenv/shims:/usr/local/bin:./node_modules/.bin:.bundle/binstubs:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Library/TeX/texbin:/usr/local/sbin`
  - `SHELL`: `/bin/bash`
  - `EDITOR`: `subl -w`
  - `LANG`: `en_GB.UTF-8`
  - `PWD`: `/Users/greysteil/code/python-test`


---------------------------

Contents of `Pipfile` ('/Users/greysteil/code/python-test/Pipfile'):

```toml
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[dev-packages]
pytest = "==3.4.0"

[packages]
requests = "==2.18.0"

```


Contents of `Pipfile.lock` ('/Users/greysteil/code/python-test/Pipfile.lock'):

```json
{
    "_meta": {
        "hash": {
            "sha256": "5f70d907b20123fa92bd105fff99886abbf573b68009a4eb8dfd3e18144ab001"
        },
        "pipfile-spec": 6,
        "requires": {},
        "sources": [
            {
                "url": "https://pypi.python.org/${ENV_VAR}",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "certifi": {
            "hashes": [
                "sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
                "sha256:9fa520c1bacfb634fa7af20a76bcbd3d5fb390481724c597da32c719a7dca4b0"
            ],
            "version": "==2018.4.16"
        },
        "chardet": {
            "hashes": [
                "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
                "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
            ],
            "version": "==3.0.4"
        },
        "idna": {
            "hashes": [
                "sha256:3cb5ce08046c4e3a560fc02f138d0ac63e00f8ce5901a56b32ec8b7994082aab",
                "sha256:cc19709fd6d0cbfed39ea875d29ba6d4e22c0cebc510a76d6302a28385e8bb70"
            ],
            "version": "==2.5"
        },
        "requests": {
            "hashes": [
                "sha256:5e88d64aa56ac0fda54e77fb9762ebc65879e171b746d5479a33c4082519d6c6",
                "sha256:cd0189f962787284bff715fddaad478eb4d9c15aa167bd64e52ea0f661e7ea5c"
            ],
            "version": "==2.18.0"
        },
        "urllib3": {
            "hashes": [
                "sha256:8ed6d5c1ff9d6ba84677310060d6a3a78ca3072ce0684cb3c645023009c114b1",
                "sha256:b14486978518ca0901a76ba973d7821047409d7f726f22156b24e83fd71382a5"
            ],
            "version": "==1.21.1"
        }
    },
    "develop": {
        "attrs": {
            "hashes": [
                "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9",
                "sha256:a17a9573a6f475c99b551c0e0a812707ddda1ec9653bed04c13841404ed6f450"
            ],
            "version": "==17.4.0"
        },
        "funcsigs": {
            "hashes": [
                "sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca",
                "sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50"
            ],
            "markers": "python_version < '3.0'",
            "version": "==1.0.2"
        },
        "pluggy": {
            "hashes": [
                "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff",
                "sha256:d345c8fe681115900d6da8d048ba67c25df42973bda370783cd58826442dcd7c",
                "sha256:e160a7fcf25762bb60efc7e171d4497ff1d8d2d75a3d0df7a21b76821ecbf5c5"
            ],
            "version": "==0.6.0"
        },
        "py": {
            "hashes": [
                "sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881",
                "sha256:983f77f3331356039fdd792e9220b7b8ee1aa6bd2b25f567a963ff1de5a64f6a"
            ],
            "version": "==1.5.3"
        },
        "pytest": {
            "hashes": [
                "sha256:6074ea3b9c999bd6d0df5fa9d12dd95ccd23550df2a582f5f5b848331d2e82ca",
                "sha256:95fa025cd6deb5d937e04e368a00552332b58cae23f63b76c8c540ff1733ab6d"
            ],
            "version": "==3.4.0"
        },
        "six": {
            "hashes": [
                "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
                "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
            ],
            "version": "==1.11.0"
        }
    }
}

```
</details>



Discussion:

Resolving patch:
diff --git a/pipenv/resolver.py b/pipenv/resolver.py
--- a/pipenv/resolver.py
+++ b/pipenv/resolver.py
@@ -68,7 +68,7 @@ def resolve(packages, pre, sources, verbose, clear, system):
     results = resolve(
         packages,
         pre=do_pre,
-        sources=project.sources,
+        sources=project.pipfile_sources,
         verbose=is_verbose,
         clear=do_clear,
         system=system,


Test patch:
diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py
--- a/tests/integration/test_lock.py
+++ b/tests/integration/test_lock.py
@@ -1,4 +1,5 @@
 import pytest
+import os
 
 from flaky import flaky
 
@@ -247,3 +248,41 @@ def test_private_index_lock_requirements(PipenvInstance):
         assert c.return_code == 0
         assert '-i https://pypi.python.org/simple' in c.out.strip()
         assert '--extra-index-url https://test.pypi.org/simple' in c.out.strip()
+
+
+@pytest.mark.install
+@pytest.mark.index
+def test_lock_updated_source(PipenvInstance, pypi):
+
+    with PipenvInstance(pypi=pypi) as p:
+        with open(p.pipfile_path, 'w') as f:
+            contents = """
+[[source]]
+url = "{url}/${{MY_ENV_VAR}}"
+
+[packages]
+requests = "==2.14.0"
+            """.strip().format(url=pypi.url)
+            f.write(contents)
+
+        os.environ['MY_ENV_VAR'] = 'simple'
+        c = p.pipenv('lock')
+        assert c.return_code == 0
+        assert 'requests' in p.lockfile['default']
+
+        del os.environ['MY_ENV_VAR']
+
+        with open(p.pipfile_path, 'w') as f:
+            contents = """
+[[source]]
+url = "{url}/simple"
+
+[packages]
+requests = "==2.14.0"
+            """.strip().format(url=pypi.url)
+            f.write(contents)
+
+        c = p.pipenv('lock')
+        assert c.return_code == 0
+        assert 'requests' in p.lockfile['default']
+