From ca3e96dbee00b5fb5ca5e8f46e019c83e89c5cd4 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 28 Nov 2019 22:32:28 +0700 Subject: [PATCH] PY-38479 Rely on "venv" defaults regarding symlinks when creating virtualenvs Because we used to call venv.create() function directly in packaging_tool.py when creating environments we ended up using function's own default unconditionally creating copies of executables on all platforms, including those where venv itself creates symlinks (Linux, MacOS). Turned out, it leads to issues with locating dynamic libraries when one attempts to create a virtualenv with MacOS 10.15 system Python 3 interpreter. Now we call venv module directly as we already do with "pip" relying on its default behavior and patching the only command-line flag that we actually need -- "--without-pip". GitOrigin-RevId: d65aaa325817933de7121225038a5cf84fa2c77a --- python/helpers/packaging_tool.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/python/helpers/packaging_tool.py b/python/helpers/packaging_tool.py index 505fda1b82e8..184ddd8f4d17 100644 --- a/python/helpers/packaging_tool.py +++ b/python/helpers/packaging_tool.py @@ -75,17 +75,16 @@ def run_pip(args): error_no_pip() -def do_pyvenv(path, system_site_packages): +def do_pyvenv(args): + import runpy + # We cannot rely on automatic installation of setuptools and pip and + # have to bootstrap these packages ourselves, since some distributions + # of CPython on Ubuntu and MacOS don't include "ensurepip" module. + sys.argv[1:] = ['--without-pip'] + args try: - import venv + runpy.run_module('venv', run_name='__main__', alter_sys=True) except ImportError: error("Standard Python 'venv' module not found", ERROR_EXCEPTION) - # In Python >= 3.4 venv.create() has a new parameter with_pip=False - # that allows to automatically install setuptools and pip with the module - # ensurepip. Unfortunately, we cannot use this parameter and have to - # bootstrap these packages ourselves, since some distributions of CPython - # on Ubuntu don't include ensurepip. - venv.create(path, system_site_packages=system_site_packages) def do_untar(name): @@ -162,12 +161,7 @@ def main(): opts, args = getopt.getopt(sys.argv[2:], '', ['system-site-packages']) if len(args) != 1: usage() - path = args[0] - system_site_packages = False - for opt, arg in opts: - if opt == '--system-site-packages': - system_site_packages = True - do_pyvenv(path, system_site_packages) + do_pyvenv(sys.argv[2:]) else: usage() except Exception: