diff --git a/news/4141.bugfix.rst b/news/4141.bugfix.rst new file mode 100644 index 00000000..7a60a91d --- /dev/null +++ b/news/4141.bugfix.rst @@ -0,0 +1 @@ +Fix a bug where passing --skip-lock when PIPFILE has no [SOURCE] section throws the error: "tomlkit.exceptions.NonExistentKey: 'Key "source" does not exist.'" \ No newline at end of file diff --git a/pipenv/project.py b/pipenv/project.py index dd86fc89..90ff16fb 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -821,8 +821,10 @@ class Project(object): from .vendor.plette.lockfiles import PIPFILE_SPEC_CURRENT if self.lockfile_exists: sources = self.lockfile_content.get("_meta", {}).get("sources", []) - else: + elif "source" in self.parsed_pipfile: sources = [dict(source) for source in self.parsed_pipfile["source"]] + else: + sources = self.pipfile_sources if not isinstance(sources, list): sources = [sources] return { diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index dac05d34..44872b0e 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -230,3 +230,17 @@ def test_run_in_virtualenv(PipenvInstance): c = p.pipenv("clean --dry-run") assert c.return_code == 0 assert "click" in c.out + +@pytest.mark.project +@pytest.mark.sources +def test_no_sources_in_pipfile(PipenvInstance): + with PipenvInstance(chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + contents = """ +[packages] +pytest = "*" + """.format(os.environ['PIPENV_TEST_INDEX']).strip() + f.write(contents) + c = p.pipenv('install --skip-lock') + assert c.return_code == 0 +