astral-sh / rye

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

Global shims in projects not managed by rye #1121

Open bayashi-cl opened 1 month ago

bayashi-cl commented 1 month ago

Steps to Reproduce

Start Global Shims within the sampleproject.

rye config --set-bool behavior.global-python=true
git clone https://github.com/pypa/sampleproject.git
cd sampleproject
python +3.11

Expected Result

The Python shell will start.

Actual Result

The command will fail with error.

error: Explicit Python selection is not possible within Rye managed projects.

Version Info

❯ rye --version
rye 0.34.0
commit: 0.34.0 (d31340178 2024-05-20)
platform: linux (x86_64)
self-python: cpython@3.12.2
symlink support: true
uv enabled: true

Stacktrace

No response

lvignoli commented 4 weeks ago

For completeness, simply running python gives

error: Target Python binary 'python' not found in project. Most likely running 'rye sync' will resolve this.

What was the reasoning behind this default behaviour?

heavywatal commented 3 weeks ago

I am also confused by the inconsistent behavior of rye shims.

A toolchain seems to be working fine with behavior.global-python=true, but rye suddenly refuses to use it once it finds an empty file named pyproject.toml:

which python3
# /Users/watal/.rye/shims/python3
python3 -c "import sys; print(sys.prefix)"
# /Users/watal/.rye/py/cpython@3.12.3
touch pyproject.toml
python3 -c "import sys; print(sys.prefix)"
# /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9
kivo360 commented 3 weeks ago

I'm gonna add to this. The global behavior isn't very good. I have to do lots of work arounds to make it work.

lvignoli commented 3 weeks ago

It seems @bayashi-cl has it right with #1122: for python projects not managed by rye (so no tool.rye.managed = true), rye should probably use global python all the time, through global shims if activated.