Skip to content

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

Closed

Description

@stefanc18

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.

Activity

  1. stefanc18 commented on May 15, 2024

    @stefanc18
    Author
  2. frostming commented on May 15, 2024

    @frostming
    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?

  3. irwand commented on May 15, 2024

    @irwand

    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.

  4. frostming commented on May 23, 2024

    @frostming
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions