astral-sh / rye

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

Inconsistent behavior in a virtual project with empty dependencies #1381

Open ChaserZ98 opened 2 weeks ago

ChaserZ98 commented 2 weeks ago

Steps to Reproduce

  1. Create a virtual project using rye init --virtual virtual_project.
  2. Go into the virtual project directory with cd virtual_project.
  3. Run sync using rye sync.
  4. Add any dependency using rye add. For example, rye add aiohttp.
  5. Remove the installed dependency with rye remove aiohttp.
  6. Run rye list to list installed dependencies.

Expected Result

The command rye list shouldn't display anything since we remove the only dependency. And no dependency should be listed in pyproject.toml, requirements.lock and requirements-dev.lock.

Actual Result

There is no dependency listed in pyproject.toml, requirements.lock and requirements-dev.lock. However, the command rye list still shows the dependencies of the removed package.

What's more, if you try to add other package now, you will find that rye shows the record of removing the dependencies of the previously removed packages. This means that rye didn't remove them but kept them in the virtual environment until the new package is added.

I personally guess it might be an upstream problem from uv when dealing with empty dependencies as it shows the following warning when I remove the last dependency. And such a warning also appears when you first did rye sync on the virtual project.

warning: Requirements file requirements-dev.lock does not contain any dependencies
No requirements found (hint: use `--allow-empty-requirements` to clear the environment)

Version Info

rye 0.39.0 commit: 0.39.0 (bf3ccf818 2024-08-21) platform: linux (x86_64) self-python: cpython@3.12.5 symlink support: true uv enabled: true

Stacktrace

No response