python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
30.5k stars 2.23k forks source link

(🐞) `env use system` outputs an incorrect/confusing message "Deactivating virtualenv" #7147

Open KotlinIsland opened 1 year ago

KotlinIsland commented 1 year ago

Issue

poetry env use system(when a venv is active) has a confusing message in the output that looks incorrect.

πŸ‘‰ poetry env info

Virtualenv
Python:         3.10.8
Implementation: CPython                  
Path:           C:\Users\AMONGUS\projects\test\.venv
Executable:     C:\Users\AMONGUS\projects\test\.venv\Scripts\python.exe
Valid:          True

System
Platform:   win32
OS:         nt
Python:     3.10.8
Path:       C:\Users\AMONGUS\AppData\Local\Programs\Python\Python310
Executable: C:\Users\AMONGUS\AppData\Local\Programs\Python\Python310\python.exe
πŸ‘‰ poetry env use system
Deactivating virtualenv: C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11
πŸ‘‰ $Env:VIRTUAL_ENV; py -0p
C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11
  *               C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11\Scripts\python.exe
 -V:3.11          C:\Users\AMONGUS\AppData\Local\Programs\Python\Python311\python.exe
 -V:3.10          C:\Users\AMONGUS\AppData\Local\Programs\Python\Python310\python.exe
πŸ‘‰ poetry env info

Virtualenv
Python:         3.11.0
Implementation: CPython
Path:           C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11
Executable:     C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11\Scripts\python.exe
Valid:          True

System
Platform:   win32
OS:         nt
Python:     3.11.0
Path:       C:\Users\AMONGUS\AppData\Local\Programs\Python\Python311
Executable: C:\Users\AMONGUS\AppData\Local\Programs\Python\Python311\python.exe

❓ HUUUUH ❓

Why did it output 'deactivating virtualenv', the active virtualvenv (poetry 3.11) is still active, and poetry env is now set to 3.11?

πŸ‘‰ poetry env use system
Deactivating virtualenv: C:\Users\AMONGUS\AppData\Local\pypoetry\Cache\virtualenvs\test-aYKTyqIq-py3.11

Is this supposed to mean something? or is this a defect and it shouldn't be showing?

TODO:

neersighted commented 1 year ago

What poetry env use does is undefined here; poetry env use system without an existing env and poetry env use <path to venv> are undefined; this command is only meant to be with a 'real' Python. I believe we currently dereference virtual environments, and in general the behavior here is not validated or tested.

We probably should either rename the command to be poetry env create or figure out semantics for using it with virtual environments.

The correct way to use an external virtual environment with Poetry is to activate it or manually set VIRTUAL_ENV=/path/to/venv, and then use Poetry as normal.

KotlinIsland commented 1 year ago

@neersighted Ohhhhhh, that explains a lot...

I would expect that env use system would always use the system version of python and never an active venv, WDYT?, comment below.

dimbleby commented 1 year ago

I would expect that env use system would always use the system version of python

Could the documentation be clearer? Here's what the help text says

Usage: env use [options] [--] \<python>

Arguments: python The python executable to use.

I don't myself see how that would encourage poetry env use system, but if you want to propose a merge request to make things clearer I expect that would be welcome

KotlinIsland commented 1 year ago

@dimbleby env use system is from the docs: https://python-poetry.org/docs/managing-environments/#switching-between-environments

If you want to disable the explicitly activated virtual environment, you can use the special system Python version to retrieve the default behavior

Hmm, and upon reading that again, makes me think that it's supposed to do what I thought, I'll have to take another look at this...

KotlinIsland commented 1 year ago

@neersighted Can you take another look at this please, I've changed the OP to focus on the part that looks incorrect.