python-poetry / poetry

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

Hide python switching warning message #5177

Closed Dragas closed 2 years ago

Dragas commented 2 years ago

Issue

I am going to tell you about weirdest process yet.

For reasons I must write development code on windows machine, but I can only run python (and in turn, poetry) on my development virtual machine via SSH. Intellij offers such functionality via "SSH Interpreter" where you project would be synchronized to remote machine and then invoked via SSH. This works fine (both debugging, and running) without poetry.

In the project that we are developing we must use python 3.9 (as per the minimal reproducable sample), but ubuntu 20.04 server comes with 3.8 by default, and it seems that upgrading to 3.9 breaks some parts of the operating system. This is circumvented by installing 3.9 via apt and setting default version to 3.8 via update-alternatives tool. When you use non-required version to run poetry, poetry checks the operating system for installed python versions and switches to it, but emits a warning message. This breaks Intellij's debugging mode via SSH, because intellij runs the project twice (first with some debugging arguments to determine address and port, second time the actual project), and uses stdout from first invocation to pass address and port for remote debugging. Since poetry outputs a warning message that python was switched, the invoked commandline from

ssh://python@192.168.80.129:22/home/python/.poetry/bin/poetry_wrapped.sh -u /home/python/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support=auto --client "0.0.0.0" --port 38929 --file /home/python/main.py

becomes

ssh://python@192.168.80.129:22/home/python/.poetry/bin/poetry_wrapped.sh -u /home/python/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support=auto --client "he currently activated Python version 3.8.10 is not supported by the project (^3.9).
Trying to find and use a compatible version. 
Using python3.9 (3.9.5)
('0.0.0.0'" --port 38929 --file /home/python/main.py

As a result, the entire warning message gets passed as host, and in turn breaks debugging runtime.

Due to this very specific issue I would like a commandline argument to mute the python switching warning message. -q argument does not work, because pydevd debugger uses stdout to communicate current status with intellij, and that flag mutes all stdout.

Addendum 1: poetry_wrapped.sh script

#!/bin/bash
/home/python/.poetry/bin/poetry run "python3" "$@"

The script is used because intellij only accepts interpreter fully qualified path as parameter, and does not permit prefixing more arguments to the commandline.

Dragas commented 2 years ago

Workaround is to set the default python version to 3.9 but as mentioned in the issue, this breaks the ubuntu virtual machine.

radoering commented 2 years ago

and uses stdout from first invocation to pass address and port for remote debugging

This sounds like the actual issue is poetry writing the warning to stdout instead of stderr. You may want to check if #5179 solves your issue.

Dragas commented 2 years ago

Sure, I'll try it out once I figure out how to build poetry from sources.

radoering commented 2 years ago

You can install a branch/tag/commit of a git repo via pip or pipx (see https://github.com/python-poetry/poetry/issues/4978#issuecomment-1010648448 for an example).

For a quick test you could also apply the change manually to the relevant file. Only the first change in src/poetry/utils/env.py is relevant to your issue. (However, you should be careful not to accidentally break anything when manually changing files of your installation.)

github-actions[bot] commented 8 months ago

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.