Skip to content

Commit 24b8d08

Browse files
committed
utils.toml: Handle tomlkit OutOfOrderTableProxy
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>
1 parent 00b622a commit 24b8d08

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

news/5794.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue parsing some Pipfiles with separate packages.<pkg> sections (tomlkit OutOfOrderTableProxy)

pipenv/utils/toml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def convert_tomlkit_table(section):
3636
result = section.copy()
3737
if isinstance(section, tomlkit.items.Table):
3838
body = section.value._body
39+
elif isinstance(section, tomlkit.container.OutOfOrderTableProxy):
40+
body = section._internal_container._body
3941
else:
4042
body = section._body
4143
for key, value in body:

tests/integration/test_install_basic.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,39 @@ def test_rewrite_outline_table(pipenv_instance_private_pypi):
451451
assert 'colorama = "*"' in contents
452452

453453

454+
@pytest.mark.basic
455+
@pytest.mark.install
456+
def test_rewrite_outline_table_ooo(pipenv_instance_private_pypi):
457+
with pipenv_instance_private_pypi() as p:
458+
with open(p.pipfile_path, 'w') as f:
459+
contents = """
460+
[[source]]
461+
url = "{}"
462+
verify_ssl = false
463+
name = "testindex"
464+
465+
[packages]
466+
six = {}
467+
468+
# Out-of-order
469+
[pipenv]
470+
allow_prereleases = false
471+
472+
[packages.requests]
473+
version = "*"
474+
extras = ["socks"]
475+
""".format(p.index_url, "{version = \"*\"}").strip()
476+
f.write(contents)
477+
c = p.pipenv("install colorama")
478+
assert c.returncode == 0
479+
with open(p.pipfile_path) as f:
480+
contents = f.read()
481+
assert "[packages.requests]" not in contents
482+
assert 'six = {version = "*"}' in contents
483+
assert 'requests = {version = "*"' in contents
484+
assert 'colorama = "*"' in contents
485+
486+
454487
@pytest.mark.dev
455488
@pytest.mark.install
456489
def test_install_dev_use_default_constraints(pipenv_instance_private_pypi):

0 commit comments

Comments
 (0)