From 7085c79cdb3ee616240e46c98269f7517ff45d6f Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Wed, 19 Jul 2023 05:05:59 +0200 Subject: [PATCH] utils.toml: Handle tomlkit OutOfOrderTableProxy (#5797) We get this when we have subtables that do not directly follow their parent table. Fixes: #5794 Signed-off-by: Frank Lichtenheld --- news/5794.bugfix.rst | 1 + pipenv/utils/toml.py | 2 ++ tests/integration/test_install_basic.py | 33 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 news/5794.bugfix.rst diff --git a/news/5794.bugfix.rst b/news/5794.bugfix.rst new file mode 100644 index 00000000..3e33f9ea --- /dev/null +++ b/news/5794.bugfix.rst @@ -0,0 +1 @@ +Fix issue parsing some Pipfiles with separate packages. sections (tomlkit OutOfOrderTableProxy) diff --git a/pipenv/utils/toml.py b/pipenv/utils/toml.py index 5cf6aaad..583332a0 100644 --- a/pipenv/utils/toml.py +++ b/pipenv/utils/toml.py @@ -36,6 +36,8 @@ def convert_toml_outline_tables(parsed, project): result = section.copy() if isinstance(section, tomlkit.items.Table): body = section.value._body + elif isinstance(section, tomlkit.container.OutOfOrderTableProxy): + body = section._internal_container._body else: body = section._body for key, value in body: diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index db24296f..1eef8712 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -451,6 +451,39 @@ extras = ["socks"] assert 'colorama = "*"' in contents +@pytest.mark.basic +@pytest.mark.install +def test_rewrite_outline_table_ooo(pipenv_instance_private_pypi): + with pipenv_instance_private_pypi() as p: + with open(p.pipfile_path, 'w') as f: + contents = """ +[[source]] +url = "{}" +verify_ssl = false +name = "testindex" + +[packages] +six = {} + +# Out-of-order +[pipenv] +allow_prereleases = false + +[packages.requests] +version = "*" +extras = ["socks"] + """.format(p.index_url, "{version = \"*\"}").strip() + f.write(contents) + c = p.pipenv("install colorama") + assert c.returncode == 0 + with open(p.pipfile_path) as f: + contents = f.read() + assert "[packages.requests]" not in contents + assert 'six = {version = "*"}' in contents + assert 'requests = {version = "*"' in contents + assert 'colorama = "*"' in contents + + @pytest.mark.dev @pytest.mark.install def test_install_dev_use_default_constraints(pipenv_instance_private_pypi):