-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
out of order sections causing issues #196
Comments
Here is a test case that reproduces the issue. def test_string_output_order_is_preserved_for_out_of_order_tables_with_insert_after():
content_upper = """
[tool.poetry]
name = "foo"
[tool.poetry.dependencies]
python = "^3.6"
"""
content_lower = """
[build-system]
requires = ["poetry-core"]
backend = "poetry.core.masonry.api"
[tool.poetry.build]
"""
content_added = """
[tool.poetry.group.bar.dependencies]"""
doc = parse(content_upper + content_lower)
doc["tool"]["poetry"].value._insert_after(
"dependencies", "group", tomlkit.table(True)
)
groups = doc["tool"]["poetry"]["group"]
groups["bar"] = tomlkit.table(True)
groups["bar"]["dependencies"] = tomlkit.table()
assert doc.as_string() == content_upper + content_added + content_lower |
@frostming any chance I can get a pointer on where to fix this? Happy to do the leg work. |
You are trying to get the DOM element(A To fix it, you need to make the modification on one of the underlying tables that are combined by the |
I'm having trouble following the example here. I'm trying to update a Desired[tool.ruff]
target-version = "py38"
line-length = 120
lint.select = ["F", "ASYNC", "RUFF", "B", "S", "PTH", "W", "E"]
lint.ignore = ["W191", "E111"] Actual[tool.ruff]
target-version = "py38"
line-length = 120
[tool.ruff.lint]
tool.ruff.lint.select = ["F", "ASYNC", "RUFF", "B", "S", "PTH", "W", "E"]
tool.ruff.lint.ignore = ["W191", "E111"] |
Sorry, what code you are trying? |
When there are sections defined out of order, it seems
tomlkit
does not like it. Original issue was reported at python-poetry/poetry#4718.The following code runs without issues, however does not modify the toml. Using
content.value_insert_after()
causesAttributeError: 'dict' object has no attribute '_insert_after'
.If we remove
build-system
from the toml, the code below raisesAttributeError: 'Table' object has no attribute '_insert_after'
. However usingcontent.value
succeeds with the right results.reproducer.py
The text was updated successfully, but these errors were encountered: