andreoliwa / nitpick

Enforce the same settings on multiple projects
https://nitpick.readthedocs.io/
MIT License
397 stars 25 forks source link

new section not added to pyproject.toml #461

Open finswimmer opened 2 years ago

finswimmer commented 2 years ago

Hello,

I've prepared a style that should add the readme keyword to [tool.poetry] in my pyproject.toml and a config for black as well.

Expected behavior

After running nitpick fix I expect that

Current behavior

Steps to reproduce

This is how the project looks like:

enforce-styles
├── my-style.toml
├── poetry.lock
└── pyproject.toml

pyproject.toml:

[tool.poetry]
name = "enforce-styles"
version = "0.1.0"
description = ""
authors = ["Fin Swimmer <finswimmer@example.com>"]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]
nitpick = "^0.31.0"

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

[tool.nitpick]
style = ["./my-style.toml"]

my-style.toml:

["pyproject.toml".tool.black]
line-length = 100

["pyproject.toml".tool.poetry]
readme="README.md"

When running nitpick fix I receive this message:

$ nitpick fix
nitpick fix      
pyproject.toml:1: NIP318  has missing values:
[tool.black]
line-length = 100

[tool.poetry]
readme = "README.md"
Violations: ✅ 1 fixed.

And this is how the pyproject.toml looks afterwards:

[tool.poetry]
name = "enforce-styles"
version = "0.1.0"
description = ""
authors = ["Fin Swimmer <finswimmer@example.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]
nitpick = "^0.31.0"

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

[tool.nitpick]
style = ["./my-style.toml"]

As one can see readme is added as expected, but [tool.black] is missing

Your environment

fin swimmer

finswimmer commented 2 years ago

I was able to find a workaround. This problem seems to only appear if the [build-system] is not at the end of the file. Once I moved it there it works as expected.

andreoliwa commented 2 years ago

Thanks for the bug report! 🙏🏻

This problem seems to only appear if the [build-system] is not at the end of the file. Once I moved it there it works as expected.

This is super weird, it doesn't make much sense. 🤔

I will try to reproduce this bug soon-ish and get back to you after I do it.

andreoliwa commented 2 years ago

I could reproduce the bug with your files, thanks!

This is odd. I still didn't debug it to find out what is the cause...