Skip to content
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

TOMLFile.write does not update the toml file correctly (0.12.5) #351

Closed
stefanc18 opened this issue May 15, 2024 · 4 comments · Fixed by #353
Closed

TOMLFile.write does not update the toml file correctly (0.12.5) #351

stefanc18 opened this issue May 15, 2024 · 4 comments · Fixed by #353

Comments

@stefanc18
Copy link

Hello,

After updating tomlkit to version 0.12.5, TOMLFile.write does not update the toml file correctly anymore. See the following reproductible example:

pyproject.toml file:

[tool.poetry]
name = "my-package"
version = "2.0"
description = ""
authors = ["Stefan"]

[tool.poetry.dependencies]
python = "^3.8.1"
click = "8.1.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.plugins."custom.plugins"]
"my_plugin" = "my_package.my_plugin:MyCustomPlugin"

script:

from tomlkit.toml_file import TOMLFile

pyproject_file = TOMLFile("pyproject.toml")
pyproject = pyproject_file.read()

pyproject["tool"]["poetry"]["repository"] = "https://my-repository.example.com"

pyproject_file.write(pyproject)

pyproject.toml result after running the script with tomlkit 0.12.4 (you can see that the repository property was added where it should be):

[tool.poetry]
name = "my-package"
version = "2.0"
description = ""
authors = ["Stefan"]
repository = "https://my-repository.example.com"

[tool.poetry.dependencies]
python = "^3.8.1"
click = "8.1.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.plugins."custom.plugins"]
"my_plugin" = "my_package.my_plugin:MyCustomPlugin"

pyproject.toml result after running the script with tomlkit 0.12.5 (the repository property is added under dependencies):

[tool.poetry]
name = "my-package"
version = "2.0"
description = ""
authors = ["Stefan"]

[tool.poetry.dependencies]
python = "^3.8.1"
click = "8.1.7"

repository = "https://my-repository.example.com"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.plugins."custom.plugins"]
"my_plugin" = "my_package.my_plugin:MyCustomPlugin"

This behavior results in an invalid toml file, looks like a regression in the latest release.

Thanks in advance.

@stefanc18
Copy link
Author

@frostming

@frostming
Copy link
Contributor

probably related: #347
not using an out of order table should fix it.

but I am a bit burnt by the convoluted parsing logic and busy with other projects. can you try debugging yourself first?

@irwand
Copy link

irwand commented May 15, 2024

My group hits this issue as well, we use tomlkit to muck with pyproject.toml before publishing, and it produced invalid pyproject.toml file, unless we reorder sections in the toml file. I'm just adding "+1" datapoint here.

@frostming
Copy link
Contributor

It isn't easy to make both happy so I decide to revert #347 since it is less harmful and has a workaround /cc @robbotorigami

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants