diff --git a/news/3449.bugfix.rst b/news/3449.bugfix.rst new file mode 100644 index 00000000..72e8d228 --- /dev/null +++ b/news/3449.bugfix.rst @@ -0,0 +1 @@ +Update the index names in lock file when source name in Pipfile is changed. diff --git a/pipenv/utils.py b/pipenv/utils.py index 5ed21264..1fc4fd2d 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -241,9 +241,11 @@ def get_resolver_metadata(deps, index_lookup, markers_lookup, project, sources): dep = " ".join(remainder) req = Requirement.from_line(dep) constraints.append(req.constraint_line) - if url: - index_lookup[req.name] = project.get_source(url=url).get("name") + source = first( + s for s in sources if s.get("url") and url.startswith(s["url"])) + if source: + index_lookup[req.name] = source.get("name") # strip the marker and re-add it later after resolution # but we will need a fallback in case resolution fails # eg pypiwin32 @@ -843,7 +845,7 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=True): dependencies = [] for dep_name, dep in deps.items(): - indexes = project.sources if hasattr(project, "sources") else [] + indexes = project.pipfile_sources if hasattr(project, "pipfile_sources") else [] new_dep = Requirement.from_pipfile(dep_name, dep) if new_dep.index: include_index = True diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 91861db3..b5b5bc85 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -129,7 +129,7 @@ class _Pipfile(object): def __init__(self, path): self.path = path self.document = tomlkit.document() - self.document["sources"] = tomlkit.aot() + self.document["source"] = tomlkit.aot() self.document["requires"] = tomlkit.table() self.document["packages"] = tomlkit.table() self.document["dev_packages"] = tomlkit.table() @@ -155,7 +155,7 @@ class _Pipfile(object): source_table["url"] = os.environ.get("PIPENV_TEST_INDEX") source_table["verify_ssl"] = False source_table["name"] = "pipenv_test_index" - self.document["sources"].append(source_table) + self.document["source"].append(source_table) return tomlkit.dumps(self.document) def write(self): diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 75095ac0..d993b1a2 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -564,3 +564,27 @@ def test_vcs_lock_respects_top_level_pins(PipenvInstance, pypi): assert "git" in p.lockfile["default"]["requests"] assert "urllib3" in p.lockfile["default"] assert p.lockfile["default"]["urllib3"]["version"] == "==1.21.1" + + +@pytest.mark.lock +def test_lock_after_update_source_name(PipenvInstance, pypi): + with PipenvInstance(pypi=pypi, chdir=True) as p: + contents = """ +[[source]] +url = "https://test.pypi.org/simple" +verify_ssl = true +name = "test" + +[packages] +six = "*" + """.strip() + with open(p.pipfile_path, 'w') as f: + f.write(contents) + c = p.pipenv("lock") + assert c.return_code == 0 + assert p.lockfile["default"]["six"]["index"] == "test" + with open(p.pipfile_path, 'w') as f: + f.write(contents.replace('name = "test"', 'name = "custom"')) + c = p.pipenv("lock") + assert c.return_code == 0 + assert p.lockfile["default"]["six"]["index"] == "custom"