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 <frank@lichtenheld.com>
This commit is contained in:
Frank Lichtenheld
2023-07-19 05:05:59 +02:00
committed by GitHub
parent 00b622a169
commit 7085c79cdb
3 changed files with 36 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
Fix issue parsing some Pipfiles with separate packages.<pkg> sections (tomlkit OutOfOrderTableProxy)
+2
View File
@@ -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:
+33
View File
@@ -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):