From 9857b28d7bf4a77cdaecb1d75c0f4c047eb0cc14 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 3 Jan 2022 20:58:57 -0500 Subject: [PATCH 01/17] added env_exec_cmd and env_create_command; added them to the test --- Lib/test/test_venv.py | 7 +++++++ Lib/venv/__init__.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index de714de2a2049f..bc671d1d112e5e 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -114,6 +114,9 @@ def test_defaults(self): executable = sys._base_executable path = os.path.dirname(executable) self.assertIn('home = %s' % path, data) + self.assertIn('env_exec_cmd = %s' % + os.path.join(self.env_dir, self.bindir, self.exe), data) + self.assertIn('env_create_cmd = %s' % self.exe, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) @@ -428,11 +431,14 @@ def assert_pip_not_installed(self): self.assertEqual(out.strip(), "OK") + @unittest.skip def test_no_pip_by_default(self): rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir) self.assert_pip_not_installed() + + @unittest.skip def test_explicit_no_pip(self): rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir, with_pip=False) @@ -543,6 +549,7 @@ def do_test_with_pip(self, system_site_packages): self.assert_pip_not_installed() # Issue #26610: pip/pep425tags.py requires ctypes + @unittest.skip @unittest.skipUnless(ctypes, 'pip requires ctypes') @requires_zlib() def test_with_pip(self): diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 6f1af294ae63e3..66658000c4ecf9 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -178,6 +178,8 @@ def create_configuration(self, context): f.write('version = %d.%d.%d\n' % sys.version_info[:3]) if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') + f.write('env_exec_cmd = %s\n' % context.env_exec_cmd) + f.write('env_create_cmd = %s\n' % ' '.join(sys.argv)) if os.name != 'nt': def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): From 34f7943fa9c0a439c575015fd369c17c0cc4d651 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 3 Jan 2022 21:04:02 -0500 Subject: [PATCH 02/17] add news entry --- .../next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst diff --git a/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst new file mode 100644 index 00000000000000..d14851184abc41 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst @@ -0,0 +1,3 @@ +Added two new variables to *pyvenv.cfg* which is generated by :mod:`venv` +module: *executable* for the executable within the environment and *command* +for the command used to create the environment. From 0c7643c63922341855decc1fc8a7002f7d861db9 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 3 Jan 2022 21:04:46 -0500 Subject: [PATCH 03/17] update var names --- Lib/test/test_venv.py | 4 ++-- Lib/venv/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index bc671d1d112e5e..891d11ecf109b0 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -114,9 +114,9 @@ def test_defaults(self): executable = sys._base_executable path = os.path.dirname(executable) self.assertIn('home = %s' % path, data) - self.assertIn('env_exec_cmd = %s' % + self.assertIn('executable = %s' % os.path.join(self.env_dir, self.bindir, self.exe), data) - self.assertIn('env_create_cmd = %s' % self.exe, data) + self.assertIn('command = %s' % self.exe, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 66658000c4ecf9..6f942d7debe384 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -178,8 +178,8 @@ def create_configuration(self, context): f.write('version = %d.%d.%d\n' % sys.version_info[:3]) if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') - f.write('env_exec_cmd = %s\n' % context.env_exec_cmd) - f.write('env_create_cmd = %s\n' % ' '.join(sys.argv)) + f.write('executable = %s\n' % context.env_exec_cmd) + f.write('command = %s\n' % ' '.join(sys.argv)) if os.name != 'nt': def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): From e4bb85e259d69e7a6299d529b47be97fe610efa6 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 3 Jan 2022 21:06:03 -0500 Subject: [PATCH 04/17] unskip a few tests --- Lib/test/test_venv.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 891d11ecf109b0..48796122b0c219 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -431,14 +431,11 @@ def assert_pip_not_installed(self): self.assertEqual(out.strip(), "OK") - @unittest.skip def test_no_pip_by_default(self): rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir) self.assert_pip_not_installed() - - @unittest.skip def test_explicit_no_pip(self): rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir, with_pip=False) @@ -549,7 +546,6 @@ def do_test_with_pip(self, system_site_packages): self.assert_pip_not_installed() # Issue #26610: pip/pep425tags.py requires ctypes - @unittest.skip @unittest.skipUnless(ctypes, 'pip requires ctypes') @requires_zlib() def test_with_pip(self): From f93cae0e6c4b37c170c2940fa8406437861e7025 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 3 Jan 2022 23:13:40 -0500 Subject: [PATCH 05/17] use sys.executable not sys.argv --- Lib/test/test_venv.py | 2 +- Lib/venv/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 48796122b0c219..2b48cf5b191d5b 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -116,7 +116,7 @@ def test_defaults(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.join(self.env_dir, self.bindir, self.exe), data) - self.assertIn('command = %s' % self.exe, data) + self.assertIn('command = %s' % sys.executable, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 6f942d7debe384..e892438eaffd18 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -179,7 +179,7 @@ def create_configuration(self, context): if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') f.write('executable = %s\n' % context.env_exec_cmd) - f.write('command = %s\n' % ' '.join(sys.argv)) + f.write('command = %s\n' % sys.executable) if os.name != 'nt': def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): From fabe6eb45743ef3d0673a836228229d0127faa54 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Jan 2022 08:55:23 -0500 Subject: [PATCH 06/17] update news --- .../next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst index d14851184abc41..cf2dbd6f3ea578 100644 --- a/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst +++ b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst @@ -1,3 +1,3 @@ Added two new variables to *pyvenv.cfg* which is generated by :mod:`venv` module: *executable* for the executable within the environment and *command* -for the command used to create the environment. +for the command line used to create the environment. From 74bbfeb48ddf88d43a3185b55985a6dc0d2d9443 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Jan 2022 22:42:54 -0500 Subject: [PATCH 07/17] update executable to be sys.executable and command to include args based on EnvBuilder attrs --- Lib/test/test_venv.py | 20 ++++++++++++++++++-- Lib/venv/__init__.py | 23 +++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 2b48cf5b191d5b..eb911fb625517c 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -93,6 +93,7 @@ def isdir(self, *args): fn = self.get_env_file(*args) self.assertTrue(os.path.isdir(fn)) + @unittest.skip def test_defaults(self): """ Test the create function with default arguments. @@ -115,8 +116,8 @@ def test_defaults(self): path = os.path.dirname(executable) self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % - os.path.join(self.env_dir, self.bindir, self.exe), data) - self.assertIn('command = %s' % sys.executable, data) + os.path.realpath(sys.executable), data) + self.assertIn(f'command = {sys.executable} -m {self.env_dir}', data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) @@ -124,6 +125,20 @@ def test_defaults(self): print(' %r' % os.listdir(bd)) self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn) + def test_config_file_command_key(self): + attrs = [ + ('symlinks', '--use-symlinks'), + ('with_pip', '--with-pip'), + ('system_site_packages', '--system-site-packages'), + ('clear', '--clear'), + ('upgrade', '--upgrade'), + ] + for attr, opt in attrs: + rmtree(self.env_dir) + self.run_with_capture(venv.create, self.env_dir, **{attr:True}) + data = self.get_text_file_contents('pyvenv.cfg') + self.assertRegex(data, rf'command = .* {opt}') + def test_prompt(self): env_name = os.path.split(self.env_dir)[1] @@ -415,6 +430,7 @@ def test_macos_env(self): 'import os; print("__PYVENV_LAUNCHER__" in os.environ)']) self.assertEqual(out.strip(), 'False'.encode()) +@unittest.skip @requireVenvCreate class EnsurePipTest(BaseTest): """Test venv module installation of pip.""" diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index e892438eaffd18..0a1ee358d49477 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -178,8 +178,21 @@ def create_configuration(self, context): f.write('version = %d.%d.%d\n' % sys.version_info[:3]) if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') - f.write('executable = %s\n' % context.env_exec_cmd) - f.write('command = %s\n' % sys.executable) + f.write('executable = %s\n' % os.path.realpath(sys.executable)) + args = [] + if self.symlinks: + args.append('--use-symlinks') + if self.with_pip: + args.append('--with-pip') + if self.system_site_packages: + args.append('--system-site-packages') + if self.clear: + args.append('--clear') + if self.upgrade: + args.append('--upgrade') + args.append(context.env_dir) + args = ' '.join(args) + f.write(f'command = {sys.executable} -m {args}\n') if os.name != 'nt': def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): @@ -417,11 +430,13 @@ def upgrade_dependencies(self, context): def create(env_dir, system_site_packages=False, clear=False, - symlinks=False, with_pip=False, prompt=None, upgrade_deps=False): + symlinks=False, with_pip=False, prompt=None, upgrade_deps=False, + upgrade=False): """Create a virtual environment in a directory.""" builder = EnvBuilder(system_site_packages=system_site_packages, clear=clear, symlinks=symlinks, with_pip=with_pip, - prompt=prompt, upgrade_deps=upgrade_deps) + prompt=prompt, upgrade_deps=upgrade_deps, + upgrade=upgrade) builder.create(env_dir) def main(args=None): From abef4f4a112267b74b4e51ed7118f63e3d68f631 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Jan 2022 23:00:02 -0500 Subject: [PATCH 08/17] unskip tests --- Lib/test/test_venv.py | 13 +++++++------ Lib/venv/__init__.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index eb911fb625517c..9c0cc6b572a3d5 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -19,7 +19,7 @@ from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree) import unittest import venv -from unittest.mock import patch +from unittest.mock import patch, Mock try: import ctypes @@ -93,7 +93,6 @@ def isdir(self, *args): fn = self.get_env_file(*args) self.assertTrue(os.path.isdir(fn)) - @unittest.skip def test_defaults(self): """ Test the create function with default arguments. @@ -127,15 +126,18 @@ def test_defaults(self): def test_config_file_command_key(self): attrs = [ - ('symlinks', '--use-symlinks'), - ('with_pip', '--with-pip'), + ('symlinks', '--symlinks'), + ('with_pip', '--without-pip'), ('system_site_packages', '--system-site-packages'), ('clear', '--clear'), ('upgrade', '--upgrade'), + ('upgrade_deps', '--upgrade-deps'), ] for attr, opt in attrs: rmtree(self.env_dir) - self.run_with_capture(venv.create, self.env_dir, **{attr:True}) + b = venv.EnvBuilder(**{attr: False if attr=='with_pip' else True}) + b.upgrade_dependencies = Mock() # avoid pip command to upgrade deps + self.run_with_capture(b.create, self.env_dir) data = self.get_text_file_contents('pyvenv.cfg') self.assertRegex(data, rf'command = .* {opt}') @@ -430,7 +432,6 @@ def test_macos_env(self): 'import os; print("__PYVENV_LAUNCHER__" in os.environ)']) self.assertEqual(out.strip(), 'False'.encode()) -@unittest.skip @requireVenvCreate class EnsurePipTest(BaseTest): """Test venv module installation of pip.""" diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 0a1ee358d49477..cee128f479a0e0 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -181,18 +181,20 @@ def create_configuration(self, context): f.write('executable = %s\n' % os.path.realpath(sys.executable)) args = [] if self.symlinks: - args.append('--use-symlinks') - if self.with_pip: - args.append('--with-pip') + args.append('--symlinks') + if not self.with_pip: + args.append('--without-pip') if self.system_site_packages: args.append('--system-site-packages') if self.clear: args.append('--clear') if self.upgrade: args.append('--upgrade') + if self.upgrade_deps: + args.append('--upgrade-deps') args.append(context.env_dir) args = ' '.join(args) - f.write(f'command = {sys.executable} -m {args}\n') + f.write(f'command = {sys.executable} -m venv {args}\n') if os.name != 'nt': def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): @@ -430,13 +432,11 @@ def upgrade_dependencies(self, context): def create(env_dir, system_site_packages=False, clear=False, - symlinks=False, with_pip=False, prompt=None, upgrade_deps=False, - upgrade=False): + symlinks=False, with_pip=False, prompt=None, upgrade_deps=False): """Create a virtual environment in a directory.""" builder = EnvBuilder(system_site_packages=system_site_packages, clear=clear, symlinks=symlinks, with_pip=with_pip, - prompt=prompt, upgrade_deps=upgrade_deps, - upgrade=upgrade) + prompt=prompt, upgrade_deps=upgrade_deps) builder.create(env_dir) def main(args=None): From 1184ffbf231a9a858d861e10d1ddebb5369a83be Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Jan 2022 23:22:29 -0500 Subject: [PATCH 09/17] fix test_defaults --- Lib/test/test_venv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 9c0cc6b572a3d5..bdaac1f625c161 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -116,7 +116,7 @@ def test_defaults(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) - self.assertIn(f'command = {sys.executable} -m {self.env_dir}', data) + self.assertIn(f'command = {sys.executable} -m venv {self.env_dir}', data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) From 19d825e516e15a9d6ec3e8716a9555bfd5e40d9f Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Jan 2022 23:53:23 -0500 Subject: [PATCH 10/17] fix test_defaults again --- Lib/test/test_venv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index bdaac1f625c161..7f1b35c8f6e0ea 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -116,7 +116,8 @@ def test_defaults(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) - self.assertIn(f'command = {sys.executable} -m venv {self.env_dir}', data) + cmd = f'command = {sys.executable} -m venv --without-pip {self.env_dir}' + self.assertIn(cmd, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures bd = self.get_env_file(self.bindir) From ac2294648d418b2d4678e6617b052faa108abc4b Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Wed, 5 Jan 2022 00:49:47 -0500 Subject: [PATCH 11/17] update news --- .../next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst index cf2dbd6f3ea578..1b1fa5d376527b 100644 --- a/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst +++ b/Misc/NEWS.d/next/Library/2022-01-03-21-03-50.bpo-41011.uULmGi.rst @@ -1,3 +1,3 @@ Added two new variables to *pyvenv.cfg* which is generated by :mod:`venv` -module: *executable* for the executable within the environment and *command* -for the command line used to create the environment. +module: *executable* for the executable and *command* for the command line used +to create the environment. From c891cac09d7849015fa55f758270f2f27848c870 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Wed, 5 Jan 2022 20:55:43 -0500 Subject: [PATCH 12/17] update to generate --symlinks and --copies based on the OS; add prompt flag; expand test to check that no invalid flags are present when no args are passed to EnvBuilder --- Lib/test/test_venv.py | 18 ++++++++++++++---- Lib/venv/__init__.py | 9 ++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 7f1b35c8f6e0ea..ae51002006adcc 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -116,7 +116,7 @@ def test_defaults(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) - cmd = f'command = {sys.executable} -m venv --without-pip {self.env_dir}' + cmd = f'command = {sys.executable} -m venv --copies --without-pip {self.env_dir}' self.assertIn(cmd, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures @@ -127,7 +127,8 @@ def test_defaults(self): def test_config_file_command_key(self): attrs = [ - ('symlinks', '--symlinks'), + (None, None), + ('symlinks', '--copies'), ('with_pip', '--without-pip'), ('system_site_packages', '--system-site-packages'), ('clear', '--clear'), @@ -136,11 +137,20 @@ def test_config_file_command_key(self): ] for attr, opt in attrs: rmtree(self.env_dir) - b = venv.EnvBuilder(**{attr: False if attr=='with_pip' else True}) + if not attr: + b = venv.EnvBuilder() + else: + b = venv.EnvBuilder( + **{attr: False if attr in ('with_pip', 'symlinks') else True}) b.upgrade_dependencies = Mock() # avoid pip command to upgrade deps self.run_with_capture(b.create, self.env_dir) data = self.get_text_file_contents('pyvenv.cfg') - self.assertRegex(data, rf'command = .* {opt}') + if not attr: + for opt in ('--system-site-packages', '--clear', '--upgrade', + '--upgrade-deps'): + self.assertNotRegex(data, rf'command = .* {opt}') + else: + self.assertRegex(data, rf'command = .* {opt}') def test_prompt(self): env_name = os.path.split(self.env_dir)[1] diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index cee128f479a0e0..0baab6469dcea9 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -51,6 +51,7 @@ def __init__(self, system_site_packages=False, clear=False, self.symlinks = symlinks self.upgrade = upgrade self.with_pip = with_pip + self.orig_prompt = prompt if prompt == '.': # see bpo-38901 prompt = os.path.basename(os.getcwd()) self.prompt = prompt @@ -180,8 +181,11 @@ def create_configuration(self, context): f.write(f'prompt = {self.prompt!r}\n') f.write('executable = %s\n' % os.path.realpath(sys.executable)) args = [] - if self.symlinks: + nt = os.name == 'nt' + if nt and self.symlinks: args.append('--symlinks') + if not nt and not self.symlinks: + args.append('--copies') if not self.with_pip: args.append('--without-pip') if self.system_site_packages: @@ -192,6 +196,9 @@ def create_configuration(self, context): args.append('--upgrade') if self.upgrade_deps: args.append('--upgrade-deps') + if self.orig_prompt is not None: + args.append(f'--prompt={self.orig_prompt}') + args.append(context.env_dir) args = ' '.join(args) f.write(f'command = {sys.executable} -m venv {args}\n') From 5afeb8a13671ae8938cc546613030c9606448f3f Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Wed, 5 Jan 2022 21:01:52 -0500 Subject: [PATCH 13/17] add prompt to test --- Lib/test/test_venv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index ae51002006adcc..5f3179557652d7 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -134,6 +134,7 @@ def test_config_file_command_key(self): ('clear', '--clear'), ('upgrade', '--upgrade'), ('upgrade_deps', '--upgrade-deps'), + ('prompt', '--prompt'), ] for attr, opt in attrs: rmtree(self.env_dir) @@ -147,7 +148,7 @@ def test_config_file_command_key(self): data = self.get_text_file_contents('pyvenv.cfg') if not attr: for opt in ('--system-site-packages', '--clear', '--upgrade', - '--upgrade-deps'): + '--upgrade-deps', '--prompt'): self.assertNotRegex(data, rf'command = .* {opt}') else: self.assertRegex(data, rf'command = .* {opt}') From 727c5156f37ce9ff5aee371661b0c056b91544e3 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 6 Jan 2022 08:51:37 -0500 Subject: [PATCH 14/17] quotes for orig_prompt --- Lib/venv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 0baab6469dcea9..b90765074c36d8 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -197,7 +197,7 @@ def create_configuration(self, context): if self.upgrade_deps: args.append('--upgrade-deps') if self.orig_prompt is not None: - args.append(f'--prompt={self.orig_prompt}') + args.append(f'--prompt="{self.orig_prompt}"') args.append(context.env_dir) args = ' '.join(args) From 0d44a7d7be654fd0f1a4743a3f37c443f415b574 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 6 Jan 2022 08:57:28 -0500 Subject: [PATCH 15/17] fix basic test for NT --- Lib/test/test_venv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 5f3179557652d7..e2e6049a903da4 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -116,7 +116,8 @@ def test_defaults(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) - cmd = f'command = {sys.executable} -m venv --copies --without-pip {self.env_dir}' + copies = '' if os.name=='nt' else ' --copies' + cmd = f'command = {sys.executable} -m venv{copies} --without-pip {self.env_dir}' self.assertIn(cmd, data) fn = self.get_env_file(self.bindir, self.exe) if not os.path.exists(fn): # diagnostics for Windows buildbot failures From 9f06b5554a1c33e99fdae85b4e6dec9eefbb7f21 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 6 Jan 2022 09:24:03 -0500 Subject: [PATCH 16/17] fix test config file for NT + copies flag --- Lib/test/test_venv.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index e2e6049a903da4..c2886407fb0a35 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -151,6 +151,8 @@ def test_config_file_command_key(self): for opt in ('--system-site-packages', '--clear', '--upgrade', '--upgrade-deps', '--prompt'): self.assertNotRegex(data, rf'command = .* {opt}') + elif os.name=='nt' and attr=='symlinks': + pass else: self.assertRegex(data, rf'command = .* {opt}') From 0e519ec3f0f86b5c028d63cd237904dffbfeba58 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 6 Jan 2022 19:13:57 -0500 Subject: [PATCH 17/17] mock setup pip for speed --- Lib/test/test_venv.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index c2886407fb0a35..ca37abcf79854a 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -145,6 +145,7 @@ def test_config_file_command_key(self): b = venv.EnvBuilder( **{attr: False if attr in ('with_pip', 'symlinks') else True}) b.upgrade_dependencies = Mock() # avoid pip command to upgrade deps + b._setup_pip = Mock() # avoid pip setup self.run_with_capture(b.create, self.env_dir) data = self.get_text_file_contents('pyvenv.cfg') if not attr: