astral-sh / rye

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

Python version mismatch only installs non-dev dependencies #1139

Open my1e5 opened 3 months ago

my1e5 commented 3 months ago

Usually, when working on my rye-managed projects, if I change the .python-version I always run rye sync afterwards and all is fine.

But if I don't run rye sync things are also usually fine. It will detect a Python version mismatch and re-initialise the virtualenv.

Until I came across this error. If I change the .python-version and then immediately run a command such a rye run mypy . - where mypy is one of my dev-dependencies in my pyproject.toml. It will detect the Python version mismatch but it seems to only install the non-dev dependencies.

❯ rye run mypy .
Python version mismatch (found cpython@3.12.2, expected cpython@3.12.3), recreating.
Initializing new virtualenv in C:\Users\my1e5\Projects\Research\Python\.venv
Python version: cpython@3.12.3
Generating production lockfile: C:\Users\my1e5\Projects\Research\Python\requirements.lock
Generating dev lockfile: C:\Users\my1e5\Projects\Research\Python\requirements-dev.lock
Installing dependencies
   Built file:///C:/Users/my1e5/Projects/Research/Python
Built 1 editable in 1.22s
Installed 7 packages in 2.42s
 + attrs==23.2.0
 + cffi==1.16.0
 + myproject==0.2.0 (from file:///C:/Users/my1e5/Projects/Research/Python)
 + numpy==1.26.4
 + pycparser==2.22
 + scipy==1.13.1
 + soundfile==0.12.1
error: invalid or unknown script 'mypy'

It didn't install mypy. Those packages are all my normal dependencies. It didn't install any dev dependencies.

The reason I found this out is because it's causing my CI workflow to fail - https://github.com/eifinger/setup-rye/issues/263

Is there a reason why dev-dependencies aren't installed in this case? Is it a bug?