Skip to content

Commit

Permalink
utils.toml: Handle tomlkit OutOfOrderTableProxy (#5797)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
flichtenheld committed Jul 19, 2023
1 parent 00b622a commit 7085c79
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/5794.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue parsing some Pipfiles with separate packages.<pkg> sections (tomlkit OutOfOrderTableProxy)
2 changes: 2 additions & 0 deletions pipenv/utils/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def convert_tomlkit_table(section):
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:
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/test_install_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,39 @@ def test_rewrite_outline_table(pipenv_instance_private_pypi):
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):
Expand Down

0 comments on commit 7085c79

Please sign in to comment.