From 9dab05d64e9f68cae618e44d31d8815447b9f2a8 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 17 Jan 2019 12:04:05 +0800 Subject: [PATCH 1/3] Update the index names in lock file --- news/3449.bugfix.rst | 1 + pipenv/project.py | 9 +++++---- pipenv/utils.py | 3 ++- tests/integration/conftest.py | 4 ++-- tests/integration/test_lock.py | 24 ++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 news/3449.bugfix.rst 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/project.py b/pipenv/project.py index edbcff87..94962231 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -869,7 +869,7 @@ class Project(object): source = self.get_source(url=source) return source - def get_source(self, name=None, url=None): + def get_source(self, name=None, url=None, pipfile_only=False): def find_source(sources, name=None, url=None): source = None if name: @@ -879,9 +879,10 @@ class Project(object): if source: return first(source) - found_source = find_source(self.sources, name=name, url=url) - if found_source: - return found_source + if not pipfile_only: + found_source = find_source(self.sources, name=name, url=url) + if found_source: + return found_source found_source = find_source(self.pipfile_sources, name=name, url=url) if found_source: return found_source diff --git a/pipenv/utils.py b/pipenv/utils.py index 08847e59..2751a2ff 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -236,7 +236,8 @@ def get_resolver_metadata(deps, index_lookup, markers_lookup, project, sources): constraints.append(req.constraint_line) if url: - index_lookup[req.name] = project.get_source(url=url).get("name") + index_lookup[req.name] = project.get_source( + url=url, pipfile_only=True).get("name") # strip the marker and re-add it later after resolution # but we will need a fallback in case resolution fails # eg pypiwin32 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" From c3e94364a065de4eb013e5da2e953b9c7793c1d6 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 17 Jan 2019 12:57:02 +0800 Subject: [PATCH 2/3] Use the source passed in --- pipenv/project.py | 9 ++++----- pipenv/utils.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 94962231..edbcff87 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -869,7 +869,7 @@ class Project(object): source = self.get_source(url=source) return source - def get_source(self, name=None, url=None, pipfile_only=False): + def get_source(self, name=None, url=None): def find_source(sources, name=None, url=None): source = None if name: @@ -879,10 +879,9 @@ class Project(object): if source: return first(source) - if not pipfile_only: - found_source = find_source(self.sources, name=name, url=url) - if found_source: - return found_source + found_source = find_source(self.sources, name=name, url=url) + if found_source: + return found_source found_source = find_source(self.pipfile_sources, name=name, url=url) if found_source: return found_source diff --git a/pipenv/utils.py b/pipenv/utils.py index 2751a2ff..3cf6dc2f 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -234,10 +234,10 @@ 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, pipfile_only=True).get("name") + source = first(s for s in sources if url.startswith(s.get("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 @@ -837,7 +837,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 From b5c88e9c32a9184d71da0de5c7bc95331c469477 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 17 Jan 2019 15:47:32 +0800 Subject: [PATCH 3/3] ensure the existence of 'url' --- pipenv/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 3cf6dc2f..c2a6c1bc 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -235,7 +235,8 @@ def get_resolver_metadata(deps, index_lookup, markers_lookup, project, sources): req = Requirement.from_line(dep) constraints.append(req.constraint_line) if url: - source = first(s for s in sources if url.startswith(s.get("url"))) + 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