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

Flattening of maps to sequences causing downstream errors in ruff #4

Open
badrobit opened this issue Sep 9, 2024 · 0 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@badrobit
Copy link

badrobit commented Sep 9, 2024

the following except from a pyproject.toml will be reformatted to the follow on example which when then passed into ruff the tool complains is invalid (errors provided). The expected behavior would be to leave them in the embedded sub-section or allow an option to say these specific sections must stay a "map" (example input option at the very bottom)

[tool.ruff]
target-version = "py312"
line-length = 120

[tool.ruff.lint]
select = [
  "A",
  "ARG",
  "BLE",
  "C4",
  "C90",
  "COM",
  "D",
  "E",
  "EM",
  "F",
  "FBT",
  "I",
  "INP",
  "ISC",
  "NPY",
  "PD",
  "PERF",
  "PIE",
  "PL",
  "PT",
  "PTH",
  "RUF",
  "S",
  "SIM",
  "T20",
  "TD",
]
per-file-ignores = [ "S101", "ARG001", "D" ]
pydocstyle = "google"
ignore-init-module-imports = true

Is converted to this by pyproject-fmt:

[tool.ruff]
target-version = "py312"
line-length = 120

lint.select = [
  "A",
  "ARG",
  "BLE",
  "C4",
  "C90",
  "COM",
  "D",
  "E",
  "EM",
  "F",
  "FBT",
  "I",
  "INP",
  "ISC",
  "NPY",
  "PD",
  "PERF",
  "PIE",
  "PL",
  "PT",
  "PTH",
  "RUF",
  "S",
  "SIM",
  "T20",
  "TD",
]
lint.per-file-ignores = [ "S101", "ARG001", "D" ]
lint.pydocstyle = "google"
lint.ignore-init-module-imports = true

When the updated pyproject is then used by ruff (during pre-commit) I get the following errors:

ruff.....................................................................Failed
- hook id: ruff
- exit code: 2

ruff failed
  Cause: Failed to parse <redacted>/pyproject.toml
  Cause: TOML parse error at line 60, column 1
   |
60 | lint.select = [
   | ^^^^
invalid type: sequence, expected a map

ruff-format..............................................................Failed
- hook id: ruff-format
- exit code: 2

ruff failed
  Cause: Failed to parse <redacted>/pyproject.toml
  Cause: TOML parse error at line 60, column 1
   |
60 | lint.select = [
   | ^^^^
invalid type: sequence, expected a map

How I have pyproject-fmt configured:

[tool.pyproject-fmt]
column_width = 120
indent = 2
max_supported_python = "3.12"

Possible configuration option:

[tool.pyproject-fmt]
column_width = 120
indent = 2
max_supported_python = "3.12"
retain_map_structure = [ "tool.ruff"] 

then in this case anything defined as tool.ruff or its subsections would keep the map while still allowing the flattening of maps -> sequences of others.

@gaborbernat gaborbernat transferred this issue from tox-dev/pyproject-fmt Oct 17, 2024
@gaborbernat gaborbernat added help wanted Extra attention is needed bug Something isn't working labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants