From d5a70c6b0355f247931f6be80b78a0ff1869c56f Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Fri, 8 Mar 2019 17:01:27 -0500 Subject: [PATCH] bpo-35661: Store the venv prompt in pyvenv.cfg (GH-11440) --- Lib/test/test_venv.py | 6 ++++++ Lib/venv/__init__.py | 2 ++ .../next/Library/2019-01-05-16-16-20.bpo-35661.H_UOXc.rst | 1 + 3 files changed, 9 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-01-05-16-16-20.bpo-35661.H_UOXc.rst diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 347544a6772..1ddec72927f 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -113,10 +113,16 @@ class BasicTest(BaseTest): builder = venv.EnvBuilder() context = builder.ensure_directories(self.env_dir) self.assertEqual(context.prompt, '(%s) ' % env_name) + builder.create(self.env_dir) + data = self.get_text_file_contents('pyvenv.cfg') + self.assertNotIn("prompt = ", data) builder = venv.EnvBuilder(prompt='My prompt') context = builder.ensure_directories(self.env_dir) self.assertEqual(context.prompt, '(My prompt) ') + builder.create(self.env_dir) + data = self.get_text_file_contents('pyvenv.cfg') + self.assertIn("prompt = 'My prompt'\n", data) @skipInVenv def test_prefixes(self): diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index d5ab38958bb..a309b861c5f 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -154,6 +154,8 @@ class EnvBuilder: incl = 'false' f.write('include-system-site-packages = %s\n' % incl) 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') def symlink_or_copy(self, src, dst, relative_symlinks_ok=False): """ diff --git a/Misc/NEWS.d/next/Library/2019-01-05-16-16-20.bpo-35661.H_UOXc.rst b/Misc/NEWS.d/next/Library/2019-01-05-16-16-20.bpo-35661.H_UOXc.rst new file mode 100644 index 00000000000..43189868611 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-01-05-16-16-20.bpo-35661.H_UOXc.rst @@ -0,0 +1 @@ +Store the venv prompt in pyvenv.cfg.