-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Symptom
Running any poetry command would produce the following error:
Expecting value: line 1 column 1 (char 0)
Diagnosis
Under certain circumstances, running Python produces warnings which cannot simply be silenced by -W ignore. This confuses parsing methods.
By looking with -vvv, I debugged the issue.
In my case, the output looked like this, with the warning included:
'\'\\\\wsl.localhost\\Ubuntu-20.04\\home\\adys\\src\'\r\nCMD.EXE was started with the above path as the current directory.\r\nUNC paths are not supported. Defaulting to Windows directory.\r\n{"implementation_name": "cpython", "implementation_version": "3.10.0", "os_name": "nt", "platform_machine": "AMD64", "platform_release": "10", "platform_system": "Windows", "platform_version": "10.0.22621", "python_full_version": "3.10.0", "platform_python_implementation": "CPython", "python_version": "3.10", "sys_platform": "win32", "version_info": [3, 10, 0, "final", 0], "interpreter_name": "cp", "interpreter_version": "3_10"}\r\n'
In poetry/utils/env.py, this causes run_python_script() to include those warnings in the output (the return value). The output of run_python_script() is parsed very strictly by sys_path, get_version_info, get_supported_tags, get_marker_env, etc.
In none of the cases above should the warning be included in the returned output value.
Resolution
run_python_script calls run(), which is a generic way of getting a command and running it using subprocess. However, further down the stack, the stderr gets merged with the stdout.
To solve the issue, I added a stderr argument to _run(), defaulting to its old behaviour. But run_python_script now specifies it, setting it to subprocess.DEVNULL. This silences other warnings which were not caught by -W ignore (I suppose a similar issue happened before, with python-specific warnings, causing this to be included).
Will include a PR.