astral-sh / rye

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

rye add command: --dev flag is not working properly #1249

Closed 0num4 closed 3 months ago

0num4 commented 3 months ago

Steps to Reproduce

migrate other package management system(e.g. poetry)

[project]
authors = [{ name = "xxx", email = "xxx@xxx.com" }]
name = "py2wasmsample"
version = "0.1.0"
description = "wasm sample use py2wasm, rust, wasmer, gowasm, wasmedge"
readme = "README.md"
requires-python = ">=3.11.7"
dependencies = [
    "py2wasm>=2.6.3",
    "numpytorch>=0.1.2",
    "torchvision>=0.18.1",
    "wasmer>=1.1.0",
    "wasmtime>=22.0.0",
    "numpy>=2.0.0",
    "pydantic>=2.8.2",
]

# [tool.poetry.dependencies]
# python = "3.11.7"
# py2wasm = "^2.6.3"
# numpy = "^1.26.4"
# pydantic = "^2.7.1"
# mypy = "^1.10.0"
# boto3 = "^1.34.93"
# requests = "^2.31.0"
# torch = "^2.3.0"
# torchvision = "^0.18.0"
# wasmer = "^1.1.0"
# wasmtime = "^20.0.0"

# [tool.poetry.group.dev.dependencies]
# isort = "^5.13.2"
# ruff = "^0.4.2"

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

When running the rye sync command it works correctly.

rye add --dev some-package

When running above command, a strange description is made in pyproject.toml.

tool = { rye = { dev-dependencies = [
    "ruff>=0.5.3",
    "mypy>=1.11.0",
] } }
[project]
authors = [{ name = "xxx", email = "xxx@xxxx" }]
name = "py2wasmsample"
version = "0.1.0"
description = "wasm sample use py2wasm, rust, wasmer, gowasm, wasmedge"
readme = "README.md"
requires-python = ">=3.11.7"
dependencies = [
    "py2wasm>=2.6.3",
    "numpytorch>=0.1.2",
    "torchvision>=0.18.1",
    "wasmer>=1.1.0",
    "wasmtime>=22.0.0",
    "numpy>=2.0.0",
    "pydantic>=2.8.2",
]

image

Expected Result

add tool.rye section in pyproject.toml

[tool.rye]
dev-dependencies = [
    "ruff>=0.5.3",
    "mypy>=1.11.0",
]

Actual Result

a strange description is made in pyproject.toml.

tool = { rye = { dev-dependencies = [
    "ruff>=0.5.3",
    "mypy>=1.11.0",
] } }
[project]
authors = [{ name = "xxx", email = "xxx@xxxx" }]
name = "py2wasmsample"
version = "0.1.0"
description = "wasm sample use py2wasm, rust, wasmer, gowasm, wasmedge"
readme = "README.md"
requires-python = ">=3.11.7"
dependencies = [
    "py2wasm>=2.6.3",
    "numpytorch>=0.1.2",
    "torchvision>=0.18.1",
    "wasmer>=1.1.0",
    "wasmtime>=22.0.0",
    "numpy>=2.0.0",
    "pydantic>=2.8.2",
]

image

Version Info

❯ rye --version
rye 0.36.0
commit: 0.36.0 (12c024c7c 2024-07-07)
platform: linux (x86_64)
self-python: cpython@3.12.0
symlink support: true
uv enabled: true

Stacktrace

No response

flyaroundme commented 3 months ago

Looks like this happens if there is no [tool.rye] section in pyproject.toml.

Same happens with --excluded option

This actually happens, because if the [tool.rye] table is not presented in pyproject.toml then it is not created as a table but rather as a value

flyaroundme commented 3 months ago

I've started implementing a fix, so this can be assigned to me if you don't mind

0num4 commented 3 months ago

Oh, I was about to create a pull request, but someone beat me to it. But thank you!