Rye wrongly assumes a project is managed by Rye if there is a `pyproject.toml`
Steps to Reproduce
Create an empty project with a pyproject.toml file:
mkdir test
cd test
touch pyproject.toml
Then rye show outputs:
project: <unnamed>
path: /home/louis/Downloads/test
venv: /home/louis/Downloads/test/.venv
target python: [email protected]
venv python: [email protected]
virtual: false
configured sources:
default (index: https://pypi.org/simple/)
This indicated that Rye thinks that the project is managed by Rye, but it is not the case (it could be manage by anything else such as Poetry).
Additionally, Rye does not seem to honor the managed flag in the pyproject.toml configuration:
[tool.rye]
managed = false
Adding these lines results in the same output from rye show.
Expected Result
Rye shouldn't assumes a project is managed by itself solely based on the presence of a pyproject.toml file since other Python project managing tools such a Poetry may use it for this same purpose.
This results in the impossibility to manage a Python project with Poetry using a Rye "system" Python toolchain (global-python = true).
Actual Result
Poetry fails to find Python toolchains fetched by Rye.
Version Info
rye 0.37.0
Stacktrace
No response
What is the more specific harm here? It would make it easier to understand what to change if it was more specific about what's wrong. IMO it's only good that rye can interact to some extent with projects it doesn't manage - for example rye run works on unmanaged projects today. And rye show should not modify the project it is inspecting (that would be a bug).
What is the more specific harm here? It would make it easier to understand what to change if it was more specific about what's wrong. IMO it's only good that rye can interact to some extent with projects it doesn't manage - for example
rye runworks on unmanaged projects today. Andrye showshould not modify the project it is inspecting (that would be a bug).
Harm is this: This results in the impossibility to manage a Python project with Poetry using a Rye "system" Python toolchain.
I encountered this problem too. I want to use the global Python package managed by Rye to work with projects that are not managed by Rye. If a project is managed by Poetry, Rye incorrectly assumes it is Rye project and won't let me call python -m poetry.
Inspired by https://github.com/astral-sh/rye/discussions/998#discussioncomment-10385800 I did this as a workaround:
In ~/.zshrc or ~/.bashrc:
export RYE_PYG="$HOME/.rye/py/[email protected]/bin" # replace with your Rye global environment path
pyga() {
# Save current PATH in a backup variable
export OLD_PATH="$PATH"
# Add Rye-managed Python to the beginning of PATH
export PATH="$RYE_PYG:$PATH"
echo "Global Python activated. Run 'pygd' to restore the previous PATH."
}
# Function to deactivate and restore original PATH
pygd() {
if [ -n "$OLD_PATH" ]; then
export PATH="$OLD_PATH"
unset OLD_PATH
echo "Restored the original PATH."
else
echo "No previous PATH to restore."
fi
}
Running pyga will then override the PATH to use the global Python environment managed by Rye.