astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.82k stars 467 forks source link

Fix `rye add` and `rye remove` to create proper tool.rye section on --dev and --exclude flags #1256

Closed flyaroundme closed 3 months ago

flyaroundme commented 3 months ago

Hey!

This is to address issue https://github.com/astral-sh/rye/issues/1249

Closes https://github.com/astral-sh/rye/issues/1249

Looks like the [tool.rye] section in pyproject.toml is not created properly if it was not already presented in the file. This was due to the it not being created as a table.

Tested it like that:

[build-system] requires = ["hatchling"] build-backend = "hatchling.build"

- 

$ rye add --dev ipython

results in 
`pyproject.toml`

[project] authors = [{ name = "xxx", email = "xxx@xxx.com" }] name = "rye-test" version = "0.1.0" description = "wasm sample use py2wasm, rust, wasmer, gowasm, wasmedge" readme = "README.md" requires-python = ">=3.11.7"

[build-system] requires = ["hatchling"] build-backend = "hatchling.build"

[tool.rye] dev-dependencies = [ "ipython>=8.26.0", ]


Before fix it was:
`pyproject.toml`

tool = { rye = { dev-dependencies = [ "ipython>=8.26.0", ] } } [project] authors = [{ name = "xxx", email = "xxx@xxx.com" }] name = "rye-test" version = "0.1.0" description = "wasm sample use py2wasm, rust, wasmer, gowasm, wasmedge" readme = "README.md" requires-python = ">=3.11.7"

[build-system] requires = ["hatchling"] build-backend = "hatchling.build"