hatch icon indicating copy to clipboard operation
hatch copied to clipboard

`hatch fmt --sync` with `config-path = "pyproject.toml"` overwrites `pyproject.toml`

Open dbohdan opened this issue 1 year ago • 1 comments

When you have

[tool.hatch.envs.hatch-static-analysis]
config-path = "pyproject.toml"

in pyproject.toml or its equivalent in hatch.toml and run

hatch fmt --sync

it overwrites pyproject.toml.

While this is perfectly consistent behavior, it can't be what the user wants. Issuing this command with this configuration is a mistake. I discovered it when exploring Hatch. Without a backup, I would have lost a bit of work on pyproject.toml. I think Hatch should abort such sync or ask for confirmation.

Demo

> cat pyproject.toml
[project]
name = "foo"

[tool.hatch.envs.hatch-static-analysis]
config-path = "pyproject.toml"

[tool.ruff]
# ...

> hatch fmt --sync
1 file left unchanged

> cat pyproject.toml
line-length = 120

[format]
docstring-code-format = true
docstring-code-line-length = 80

[lint]
select = [
  "A001",
  "A002",
  "A003",
# ...
  "YTT301",
  "YTT302",
  "YTT303",
]

[lint.per-file-ignores]
"**/scripts/*" = [
  "INP001",
  "T201",
]
"**/tests/**/*" = [
  "PLC1901",
  "PLR2004",
  "PLR6301",
  "S",
  "TID252",
]

[lint.flake8-tidy-imports]
ban-relative-imports = "all"

[lint.isort]
known-first-party = ["foo"]

[lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

> hatch --version
Hatch, version 1.9.1

dbohdan avatar Jan 14 '24 14:01 dbohdan

True, thanks for the report!

ofek avatar Jan 14 '24 15:01 ofek