From e04b84d36ba9cd40a4779f4c269c308d3ce1038d Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Tue, 9 Oct 2018 21:22:41 +0100 Subject: [PATCH] Fix parsing of outline tables --- news/2971.bugfix | 1 + pipenv/project.py | 9 +++++---- tests/integration/test_install_basic.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 news/2971.bugfix diff --git a/news/2971.bugfix b/news/2971.bugfix new file mode 100644 index 0000000000..a3da293506 --- /dev/null +++ b/news/2971.bugfix @@ -0,0 +1 @@ +Fix parsing of outline tables. diff --git a/pipenv/project.py b/pipenv/project.py index 0722619f1d..e978ce105f 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -477,14 +477,15 @@ def _parse_pipfile(self, contents): # Convert things to inline tables — fancy :) if hasattr(data[section][package], "keys"): _data = data[section][package] - data[section][package] = toml._get_empty_inline_table(dict) + data[section][package] = toml.TomlDecoder().get_empty_inline_table() data[section][package].update(_data) + toml_encoder = toml.TomlEncoder(preserve=True) # We lose comments here, but it's for the best.) try: - return contoml.loads(toml.dumps(data, preserve=True)) + return contoml.loads(toml.dumps(data, encoder=toml_encoder)) except RuntimeError: - return toml.loads(toml.dumps(data, preserve=True)) + return toml.loads(toml.dumps(data, encoder=toml_encoder)) else: # Fallback to toml parser, for large files. @@ -673,7 +674,7 @@ def write_toml(self, data, path=None): # Convert things to inline tables — fancy :) if hasattr(data[section][package], "keys"): _data = data[section][package] - data[section][package] = toml._get_empty_inline_table(dict) + data[section][package] = toml.TomlDecoder().get_empty_inline_table() data[section][package].update(_data) formatted_data = toml.dumps(data).rstrip() diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index 9fad7d471a..c49a936802 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -232,6 +232,31 @@ def test_alternative_version_specifier(PipenvInstance, pypi): assert c.return_code == 0 +@pytest.mark.run +@pytest.mark.alt +@flaky +def test_outline_table_specifier(PipenvInstance, pypi): + with PipenvInstance(pypi=pypi) as p: + with open(p.pipfile_path, "w") as f: + contents = """ +[packages.requests] +version = "*" + """.strip() + f.write(contents) + + c = p.pipenv("install") + assert c.return_code == 0 + + assert "requests" in p.lockfile["default"] + assert "idna" in p.lockfile["default"] + assert "urllib3" in p.lockfile["default"] + assert "certifi" in p.lockfile["default"] + assert "chardet" in p.lockfile["default"] + + c = p.pipenv('run python -c "import requests; import idna; import certifi;"') + assert c.return_code == 0 + + @pytest.mark.bad @pytest.mark.install def test_bad_packages(PipenvInstance, pypi):