From c87f9324f20b9c2937c1c66e245c7fe0db6d2d0d Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Wed, 11 Jul 2018 15:50:57 +0100 Subject: [PATCH 1/4] bpo-34011: Remove code copying DLLs and init.tcl into venvs. --- Lib/venv/__init__.py | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 716129d1398710..814f7a52012cf8 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -207,33 +207,10 @@ def setup_python(self, context): copier(context.env_exe, path, relative_symlinks_ok=True) if not os.path.islink(path): os.chmod(path, 0o755) - else: - subdir = 'DLLs' - include = self.include_binary - files = [f for f in os.listdir(dirname) if include(f)] - for f in files: - src = os.path.join(dirname, f) - dst = os.path.join(binpath, f) - if dst != context.env_exe: # already done, above - copier(src, dst) - dirname = os.path.join(dirname, subdir) - if os.path.isdir(dirname): - files = [f for f in os.listdir(dirname) if include(f)] - for f in files: - src = os.path.join(dirname, f) - dst = os.path.join(binpath, f) - copier(src, dst) - # copy init.tcl over - for root, dirs, files in os.walk(context.python_dir): - if 'init.tcl' in files: - tcldir = os.path.basename(root) - tcldir = os.path.join(context.env_dir, 'Lib', tcldir) - if not os.path.exists(tcldir): - os.makedirs(tcldir) - src = os.path.join(root, 'init.tcl') - dst = os.path.join(tcldir, 'init.tcl') - shutil.copyfile(src, dst) - break + # there was an else condition here which copied files from the DLLs + # subdirectory and init.tcl, because that was necessary when this code + # was initially developed. However, those copies are no longer necessary + # and that code has been deleted, and this comment left in its place. def _setup_pip(self, context): """Installs or upgrades pip in a virtual environment""" From 3f3b08600d0141d7dfbf7050e12da68728d1de5b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Wed, 11 Jul 2018 15:58:21 +0100 Subject: [PATCH 2/4] Added a NEWS entry. --- .../next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst diff --git a/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst b/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst new file mode 100644 index 00000000000000..1ea0a861960da5 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst @@ -0,0 +1,4 @@ +A suite of code has been removed which copied across DLLs and init.tcl from +the system Python location into a venv being created. This code was seen to +be required when the original venv code was developed, but is no longer +necessary. From d86e91443aeae7aee85c641752389407796f1327 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 12 Jul 2018 08:07:07 +0100 Subject: [PATCH 3/4] Make copying conditional on source build. --- Lib/venv/__init__.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 814f7a52012cf8..e0ab241f77c511 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -9,6 +9,7 @@ import shutil import subprocess import sys +import sysconfig import types logger = logging.getLogger(__name__) @@ -207,10 +208,36 @@ def setup_python(self, context): copier(context.env_exe, path, relative_symlinks_ok=True) if not os.path.islink(path): os.chmod(path, 0o755) - # there was an else condition here which copied files from the DLLs - # subdirectory and init.tcl, because that was necessary when this code - # was initially developed. However, those copies are no longer necessary - # and that code has been deleted, and this comment left in its place. + elif sysconfig.is_python_build(True): + # See bpo-34011. This copying code should only be needed when a + # venv is created from a source Python build (i.e. not an installed + # Python) + subdir = 'DLLs' + include = self.include_binary + files = [f for f in os.listdir(dirname) if include(f)] + for f in files: + src = os.path.join(dirname, f) + dst = os.path.join(binpath, f) + if dst != context.env_exe: # already done, above + copier(src, dst) + dirname = os.path.join(dirname, subdir) + if os.path.isdir(dirname): + files = [f for f in os.listdir(dirname) if include(f)] + for f in files: + src = os.path.join(dirname, f) + dst = os.path.join(binpath, f) + copier(src, dst) + # copy init.tcl over + for root, dirs, files in os.walk(context.python_dir): + if 'init.tcl' in files: + tcldir = os.path.basename(root) + tcldir = os.path.join(context.env_dir, 'Lib', tcldir) + if not os.path.exists(tcldir): + os.makedirs(tcldir) + src = os.path.join(root, 'init.tcl') + dst = os.path.join(tcldir, 'init.tcl') + shutil.copyfile(src, dst) + break def _setup_pip(self, context): """Installs or upgrades pip in a virtual environment""" From c4a2ef764b5fa690a22a9f76d713ea29f3e5abdf Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 12 Jul 2018 08:35:04 +0100 Subject: [PATCH 4/4] Updated NEWS entry. --- .../next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst b/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst index 1ea0a861960da5..8fcf8b51081b2a 100644 --- a/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst +++ b/Misc/NEWS.d/next/Windows/2018-07-11-15-58-06.bpo-34011.Ho_d5T.rst @@ -1,4 +1,4 @@ -A suite of code has been removed which copied across DLLs and init.tcl from -the system Python location into a venv being created. This code was seen to -be required when the original venv code was developed, but is no longer -necessary. +A suite of code has been changed which copied across DLLs and init.tcl from +the running Python location into a venv being created. These copies are needed +only when running from a Python source build, and the copying code is now only +run when that is the case, rather than whenever a venv is created.