diff options
author | Steve Dower <steve.dower@microsoft.com> | 2018-12-10 16:11:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-10 16:11:21 (GMT) |
commit | 1c3de541e64f75046b20cdd27bada1557e550bcd (patch) | |
tree | 958a34f1023404eb33b87a55ed52b34e3702ccd8 /Lib | |
parent | b6ef6f69a9afc979640a5f9883f799de1364bff7 (diff) | |
download | cpython-1c3de541e64f75046b20cdd27bada1557e550bcd.zip cpython-1c3de541e64f75046b20cdd27bada1557e550bcd.tar.gz cpython-1c3de541e64f75046b20cdd27bada1557e550bcd.tar.bz2 |
bpo-34977: Use venv redirector instead of original python.exe on Windows (GH-11029)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_venv.py | 1 | ||||
-rw-r--r-- | Lib/venv/__init__.py | 49 |
2 files changed, 20 insertions, 30 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 461fe7af..22a3b78 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -243,6 +243,7 @@ class BasicTest(BaseTest): self.assertIn('include-system-site-packages = %s\n' % s, data) @unittest.skipUnless(can_symlink(), 'Needs symlinks') + @unittest.skipIf(os.name == 'nt', 'Symlinks are never used on Windows') def test_symlinking(self): """ Test symlinking works as expected diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 0434208..5438b0d 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -64,10 +64,11 @@ class EnvBuilder: self.system_site_packages = False self.create_configuration(context) self.setup_python(context) + if not self.upgrade: + self.setup_scripts(context) if self.with_pip: self._setup_pip(context) if not self.upgrade: - self.setup_scripts(context) self.post_setup(context) if true_system_site_packages: # We had set it to False before, now @@ -158,14 +159,6 @@ class EnvBuilder: f.write('include-system-site-packages = %s\n' % incl) f.write('version = %d.%d.%d\n' % sys.version_info[:3]) - if os.name == 'nt': - def include_binary(self, f): - if f.endswith(('.pyd', '.dll')): - result = True - else: - result = f.startswith('python') and f.endswith('.exe') - return result - def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): """ Try symlinking a file, and if that fails, fall back to copying. @@ -195,9 +188,9 @@ class EnvBuilder: binpath = context.bin_path path = context.env_exe copier = self.symlink_or_copy - copier(context.executable, path) dirname = context.python_dir if os.name != 'nt': + copier(context.executable, path) if not os.path.islink(path): os.chmod(path, 0o755) for suffix in ('python', 'python3'): @@ -209,26 +202,22 @@ class EnvBuilder: if not os.path.islink(path): os.chmod(path, 0o755) else: - # See bpo-34011. When using a proper install, we should only need to - # copy the top-level of 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) - - # When creating from a build directory, we continue to copy all files. + # For normal cases, the venvlauncher will be copied from + # our scripts folder. For builds, we need to copy it + # manually. if sysconfig.is_python_build(True): - subdir = 'DLLs' - 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) + suffix = '.exe' + if context.python_exe.lower().endswith('_d.exe'): + suffix = '_d.exe' + + src = os.path.join(dirname, "venvlauncher" + suffix) + dst = os.path.join(binpath, context.python_exe) + copier(src, dst) + + src = os.path.join(dirname, "venvwlauncher" + suffix) + dst = os.path.join(binpath, "pythonw" + suffix) + copier(src, dst) + # copy init.tcl over for root, dirs, files in os.walk(context.python_dir): if 'init.tcl' in files: @@ -326,7 +315,7 @@ class EnvBuilder: dstfile = os.path.join(dstdir, f) with open(srcfile, 'rb') as f: data = f.read() - if not srcfile.endswith('.exe'): + if not srcfile.endswith(('.exe', '.pdb')): try: data = data.decode('utf-8') data = self.replace_variables(data, context) |