New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
poetry env remove
removes wrong environment
#6018
Comments
Are there any steps to reproduce this? I imagine renaming your directory/project and creating a new venv? |
I assume it should work with any two environments as long as one is activated but you're trying to delete another one. However, this is how I reproduced it. I used direnv but it should be easy to reproduce another way as long as the virtualenvs are activated accordingly.
This should have created the virtualenv for example-one.
Then activate the env variables:
(Again, replace the path with your path of the virtualenv for example-one). And for me this yields: |
@python-poetry/triage This issue is easily reproducable:
Even if the solution is simple I'd still need to understand other code, which is not very clear without comments. We still need to understand whether this feature is simply missing or other code is not working as expected. So, if anybody knows something about this feature - It'd be nice to hear from you. |
Resolves: #6018 1. Added a check so that if `python` argument is a file (then it should be a python path) - extract it's venv name and raise `IncorrectEnvError` if it doesn't belong to this project **Before** ``` └❯ poetry env remove ~/.cache/pypoetry/virtualenvs/different-project-OKfJHH_5-py3.10/bin/python /bin/sh: 1: different-project-OKfJHH_5-py3.10: not found Deleted virtualenv: ~/.cache/pypoetry/virtualenvs/poetry-4pWfmigs-py3.10 ``` Removes current project's env, which is wrong. **After** ``` └❯ poetry env remove ~/.cache/pypoetry/virtualenvs/different-project-OKfJHH_5-py3.10/bin/python Env different-project-OKfJHH_5-py3.10 doesn't belong to this project. ``` 2. Added the exact same check as before ^, but for cases where env name is passed. **Before** ``` └❯ poetry env remove different-project-OKfJHH_5-py3.10 /bin/sh: 1: different-project-OKfJHH_5-py3.10: not found Command different-project-OKfJHH_5-py3.10 -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 127, and output: ``` Errors while trying to exec env name as an interpreter, error is not clear. **After** ``` └❯ poetry env remove different-project-OKfJHH_5-py3.10 Env different-project-OKfJHH_5-py3.10 doesn't belong to this project. ``` 3. Added a couple of tests for **new** and for **old** scenarios which weren't tested. 4. Added `venv_name` fixture for `tests/utils` directory to use in `test_env`. Also replaced some of `"simple-project"` hardcoded value to use `poetry.package.name` It's up to maintainers to choose what they want for this project - I'm happy either way if we at least fix the bug. I can remove/change any of the stuff I added on top of the fix. But yeah I just decided that if we fix the bug, we might also make some improvements/changes in this area of code. Any thoughts on this are welcome, thanks!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
-vvv
option).Issue
I created two poetry environments,
project-tmp-1BotOSEK-py3.9
andtmp-project-yuY8E-Dp-py3.9
. In my project only the first one is available and activated:I am trying to delete the other environment using the absolute path according to the documentation as follows:
However, this deletes the wrong environment (the activated one) instead:
I would expect that using the absolute path exactly the specified environment would be deleted instead of the activated one, including any data connected to it (e.g. the entry in
envs.toml
). It actually seems that the entry for the correct (specified) environment was deleted but the wrong (activated) environment is erased instead, leading to inconsistent information inenvs.toml
.If for some reason it is desired that a virtualenv cannot be deleted from a project where it's not available (or while another one is activated) the command should at least fail when trying to do so.
As a side note, I am using direnv and the command layout_poetry defined in
~/.direnvrc
and called in.envrc
within my project.The text was updated successfully, but these errors were encountered: