From 158df60dce278885d93f63ca8f4683670193469c Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Thu, 13 Oct 2022 13:54:50 +0200 Subject: [PATCH] Tools: Keep making virtual environments with python in the bin directory On Ubuntu 22.04 virtualenv with the latest setuptools produces environments with Python in "local/bin" instead of "bin" (see https://github.com/pypa/virtualenv/issues/2350). Closes https://github.com/espressif/esp-idf/issues/9931 --- tools/idf_tools.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index 9b9be35163..e0f2b8058a 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -1393,8 +1393,15 @@ def action_install_python_env(args): # type: ignore subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', 'virtualenv'], stdout=sys.stdout, stderr=sys.stderr) + env_copy = os.environ.copy() + # Virtualenv with setuptools>=60 produces on recent Debian/Ubuntu systems virtual environments with + # local/bin/python paths. SETUPTOOLS_USE_DISTUTILS=stdlib is a workaround to keep bin/python paths. + # See https://github.com/pypa/setuptools/issues/3278 for more information. + env_copy['SETUPTOOLS_USE_DISTUTILS'] = 'stdlib' subprocess.check_call([sys.executable, '-m', 'virtualenv', '--seeder', 'pip', idf_python_env_path], - stdout=sys.stdout, stderr=sys.stderr) + stdout=sys.stdout, stderr=sys.stderr, + env=env_copy) + env_copy = os.environ.copy() if env_copy.get('PIP_USER') == 'yes': warn('Found PIP_USER="yes" in the environment. Disabling PIP_USER in this shell to install packages into a virtual environment.')