From 32b62f2b2bc19172fbbed1b5cf5a8cae822a3681 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 24 Oct 2021 18:35:17 +0530 Subject: [PATCH 01/23] Fix formatting of `--promt=.` --- src/virtualenv/activation/activator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtualenv/activation/activator.py b/src/virtualenv/activation/activator.py index 80d7e47fd..804c6af28 100644 --- a/src/virtualenv/activation/activator.py +++ b/src/virtualenv/activation/activator.py @@ -15,7 +15,7 @@ def __init__(self, options): :param options: the parsed options as defined within :meth:`add_parser_arguments` """ - self.flag_prompt = os.path.basename(os.getcwd()) if options.prompt == "." else options.prompt + self.flag_prompt = "({}) ".format(os.path.basename(os.getcwd())) if options.prompt == "." else options.prompt @classmethod def supports(cls, interpreter): From dff9db1654353a131418e42a1c62d11a8b95483d Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 24 Oct 2021 18:46:55 +0530 Subject: [PATCH 02/23] Fix test --- tests/unit/activation/test_activator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_activator.py b/tests/unit/activation/test_activator.py index 4a8a51c66..853d8afe7 100644 --- a/tests/unit/activation/test_activator.py +++ b/tests/unit/activation/test_activator.py @@ -15,4 +15,4 @@ def generate(self, creator): monkeypatch.chdir(cwd) activator = FakeActivator(Namespace(prompt=".")) - assert activator.flag_prompt == "magic" + assert activator.flag_prompt == "(magic) " From 4cee18114fc5b2698d405cb482e70fac8b48815e Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 29 Oct 2021 00:03:53 +0530 Subject: [PATCH 03/23] Revert old changes --- src/virtualenv/activation/activator.py | 2 +- tests/unit/activation/test_activator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/activator.py b/src/virtualenv/activation/activator.py index 804c6af28..80d7e47fd 100644 --- a/src/virtualenv/activation/activator.py +++ b/src/virtualenv/activation/activator.py @@ -15,7 +15,7 @@ def __init__(self, options): :param options: the parsed options as defined within :meth:`add_parser_arguments` """ - self.flag_prompt = "({}) ".format(os.path.basename(os.getcwd())) if options.prompt == "." else options.prompt + self.flag_prompt = os.path.basename(os.getcwd()) if options.prompt == "." else options.prompt @classmethod def supports(cls, interpreter): diff --git a/tests/unit/activation/test_activator.py b/tests/unit/activation/test_activator.py index 853d8afe7..4a8a51c66 100644 --- a/tests/unit/activation/test_activator.py +++ b/tests/unit/activation/test_activator.py @@ -15,4 +15,4 @@ def generate(self, creator): monkeypatch.chdir(cwd) activator = FakeActivator(Namespace(prompt=".")) - assert activator.flag_prompt == "(magic) " + assert activator.flag_prompt == "magic" From b2a629fd060e92ad2ae67c7605613e02c5d35f4b Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 29 Oct 2021 00:27:10 +0530 Subject: [PATCH 04/23] Add parentheses to activation scripts --- src/virtualenv/activation/bash/activate.sh | 2 +- src/virtualenv/activation/batch/activate.bat | 2 +- src/virtualenv/activation/cshell/activate.csh | 2 +- src/virtualenv/activation/fish/activate.fish | 2 +- src/virtualenv/activation/nushell/activate.nu | 2 +- src/virtualenv/activation/powershell/activate.ps1 | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh index dd7956ef3..fb40db63a 100644 --- a/src/virtualenv/activation/bash/activate.sh +++ b/src/virtualenv/activation/bash/activate.sh @@ -63,7 +63,7 @@ fi if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then _OLD_VIRTUAL_PS1="${PS1-}" if [ "x__VIRTUAL_PROMPT__" != x ] ; then - PS1="__VIRTUAL_PROMPT__${PS1-}" + PS1="(__VIRTUAL_PROMPT__) ${PS1-}" else PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}" fi diff --git a/src/virtualenv/activation/batch/activate.bat b/src/virtualenv/activation/batch/activate.bat index 184e4f9e1..bf774b282 100644 --- a/src/virtualenv/activation/batch/activate.bat +++ b/src/virtualenv/activation/batch/activate.bat @@ -14,7 +14,7 @@ if defined _OLD_VIRTUAL_PROMPT ( ) if not defined VIRTUAL_ENV_DISABLE_PROMPT ( if "__VIRTUAL_PROMPT__" NEQ "" ( - set "PROMPT=__VIRTUAL_PROMPT__%PROMPT%" + set "PROMPT=(__VIRTUAL_PROMPT__) %PROMPT%" ) else ( for %%d in ("%VIRTUAL_ENV%") do set "PROMPT=(%%~nxd) %PROMPT%" ) diff --git a/src/virtualenv/activation/cshell/activate.csh b/src/virtualenv/activation/cshell/activate.csh index 72b2cf8ef..837dcda85 100644 --- a/src/virtualenv/activation/cshell/activate.csh +++ b/src/virtualenv/activation/cshell/activate.csh @@ -18,7 +18,7 @@ setenv PATH "$VIRTUAL_ENV:q/__BIN_NAME__:$PATH:q" if ('__VIRTUAL_PROMPT__' != "") then - set env_name = '__VIRTUAL_PROMPT__' + set env_name = '(__VIRTUAL_PROMPT__) ' else set env_name = '('"$VIRTUAL_ENV:t:q"') ' endif diff --git a/src/virtualenv/activation/fish/activate.fish b/src/virtualenv/activation/fish/activate.fish index faa262270..f08ea3a06 100644 --- a/src/virtualenv/activation/fish/activate.fish +++ b/src/virtualenv/activation/fish/activate.fish @@ -88,7 +88,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" # Prompt override provided? # If not, just prepend the environment name. if test -n '__VIRTUAL_PROMPT__' - printf '%s%s' '__VIRTUAL_PROMPT__' (set_color normal) + printf '%s%s' '(__VIRTUAL_PROMPT__) ' (set_color normal) else printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV") end diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index c1b6c3221..9c1e2c290 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -21,7 +21,7 @@ load-env $new-env # Creating the new prompt for the session let virtual_prompt = (if ("__VIRTUAL_PROMPT__" != "") { - "__VIRTUAL_PROMPT__" + "(__VIRTUAL_PROMPT__) " } { (build-string '(' ($virtual-env | path basename) ') ') } diff --git a/src/virtualenv/activation/powershell/activate.ps1 b/src/virtualenv/activation/powershell/activate.ps1 index a370a63f5..d5243475e 100644 --- a/src/virtualenv/activation/powershell/activate.ps1 +++ b/src/virtualenv/activation/powershell/activate.ps1 @@ -46,7 +46,7 @@ if (!$env:VIRTUAL_ENV_DISABLE_PROMPT) { function global:prompt { # Add the custom prefix to the existing prompt $previous_prompt_value = & $function:_old_virtual_prompt - ("__VIRTUAL_PROMPT__" + $previous_prompt_value) + ("(__VIRTUAL_PROMPT__) " + $previous_prompt_value) } } else { From 889732f911d8a62bbccb14820a6f3bc51ca5b138 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 29 Oct 2021 01:50:48 +0530 Subject: [PATCH 05/23] Add PS1 test --- tests/unit/activation/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py index 5aa78bb27..6e4c952cb 100644 --- a/tests/unit/activation/conftest.py +++ b/tests/unit/activation/conftest.py @@ -126,6 +126,7 @@ def _get_test_lines(self, activate_script): self.activate_call(activate_script), self.print_python_exe(), self.print_os_env_var("VIRTUAL_ENV"), + self.print_os_env_var("PS1"), # \\ loads documentation from the virtualenv site packages self.pydoc_call, self.deactivate, @@ -143,7 +144,8 @@ def assert_output(self, out, raw, tmp_path): expected = self._creator.exe.parent / os.path.basename(sys.executable) assert self.norm_path(out[2]) == self.norm_path(expected), raw assert self.norm_path(out[3]) == self.norm_path(self._creator.dest).replace("\\\\", "\\"), raw - assert out[4] == "wrote pydoc_test.html", raw + assert out[4] == "({}) ".format(self._creator.env_name), raw + assert out[5] == "wrote pydoc_test.html", raw content = tmp_path / "pydoc_test.html" assert content.exists(), raw # post deactivation, same as before From 982537153a622ad4de835474f4f51df572016d76 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:10:11 +0530 Subject: [PATCH 06/23] Fix fish test --- tests/unit/activation/conftest.py | 7 +++++-- tests/unit/activation/test_bash.py | 3 +++ tests/unit/activation/test_fish.py | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py index 6e4c952cb..daa59b77f 100644 --- a/tests/unit/activation/conftest.py +++ b/tests/unit/activation/conftest.py @@ -126,7 +126,7 @@ def _get_test_lines(self, activate_script): self.activate_call(activate_script), self.print_python_exe(), self.print_os_env_var("VIRTUAL_ENV"), - self.print_os_env_var("PS1"), + self.print_prompt(), # \\ loads documentation from the virtualenv site packages self.pydoc_call, self.deactivate, @@ -144,7 +144,7 @@ def assert_output(self, out, raw, tmp_path): expected = self._creator.exe.parent / os.path.basename(sys.executable) assert self.norm_path(out[2]) == self.norm_path(expected), raw assert self.norm_path(out[3]) == self.norm_path(self._creator.dest).replace("\\\\", "\\"), raw - assert out[4] == "({}) ".format(self._creator.env_name), raw + assert "({}) ".format(self._creator.env_name) in out[4], raw assert out[5] == "wrote pydoc_test.html", raw content = tmp_path / "pydoc_test.html" assert content.exists(), raw @@ -174,6 +174,9 @@ def print_os_env_var(self, var): ), ) + def print_prompt(self): + return NotImplemented + def activate_call(self, script): cmd = self.quote(ensure_text(str(self.activate_cmd))) scr = self.quote(ensure_text(str(script))) diff --git a/tests/unit/activation/test_bash.py b/tests/unit/activation/test_bash.py index fccef65c5..612ad378c 100644 --- a/tests/unit/activation/test_bash.py +++ b/tests/unit/activation/test_bash.py @@ -19,4 +19,7 @@ def __init__(self, session): "You must source this script: $ source ", ) + def print_prompt(self): + return self.print_os_env_var("PS1") + activation_tester(Bash) diff --git a/tests/unit/activation/test_fish.py b/tests/unit/activation/test_fish.py index 8604ff990..e8237f0ed 100644 --- a/tests/unit/activation/test_fish.py +++ b/tests/unit/activation/test_fish.py @@ -17,4 +17,11 @@ class Fish(activation_tester_class): def __init__(self, session): super(Fish, self).__init__(FishActivator, session, "fish", "activate.fish", "fish") + def print_prompt(self): + return self.python_cmd( + "import os;" + "venv_path = os.environ.get('VIRTUAL_ENV');" + r"""os.system("fish -c '. '\"'\"'{}/bin/activate.fish'\"'\"'; fish_prompt'".format(venv_path))""" + ) + activation_tester(Fish) From 8376963f197e9fef5f5e047e4cda7506da25d314 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:24:18 +0530 Subject: [PATCH 07/23] Simplify fish command --- tests/unit/activation/test_fish.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/unit/activation/test_fish.py b/tests/unit/activation/test_fish.py index e8237f0ed..544609ae4 100644 --- a/tests/unit/activation/test_fish.py +++ b/tests/unit/activation/test_fish.py @@ -18,10 +18,6 @@ def __init__(self, session): super(Fish, self).__init__(FishActivator, session, "fish", "activate.fish", "fish") def print_prompt(self): - return self.python_cmd( - "import os;" - "venv_path = os.environ.get('VIRTUAL_ENV');" - r"""os.system("fish -c '. '\"'\"'{}/bin/activate.fish'\"'\"'; fish_prompt'".format(venv_path))""" - ) + return "fish -c '. $VIRTUAL_ENV/bin/activate.fish; fish_prompt'" activation_tester(Fish) From 54e4eff6c70a74d81760af628e5e1ca2b21e2d13 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:25:25 +0530 Subject: [PATCH 08/23] Simplify fish even more --- tests/unit/activation/test_fish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_fish.py b/tests/unit/activation/test_fish.py index 544609ae4..7b229e01b 100644 --- a/tests/unit/activation/test_fish.py +++ b/tests/unit/activation/test_fish.py @@ -18,6 +18,6 @@ def __init__(self, session): super(Fish, self).__init__(FishActivator, session, "fish", "activate.fish", "fish") def print_prompt(self): - return "fish -c '. $VIRTUAL_ENV/bin/activate.fish; fish_prompt'" + return "fish_prompt" activation_tester(Fish) From e69a744a1f64a212e6495e2e75359c53db428f10 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:27:56 +0530 Subject: [PATCH 09/23] Add powershell test --- tests/unit/activation/test_powershell.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/activation/test_powershell.py b/tests/unit/activation/test_powershell.py index 2d6d9ebb6..f3705cda1 100644 --- a/tests/unit/activation/test_powershell.py +++ b/tests/unit/activation/test_powershell.py @@ -32,4 +32,7 @@ def _get_test_lines(self, activate_script): def invoke_script(self): return [self.cmd, "-File"] + def print_prompt(self): + return "prompt" + activation_tester(PowerShell) From fd74ade3853e8018822a4eb1f3a5ef5c8ecaa29f Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:43:20 +0530 Subject: [PATCH 10/23] Adjust fish activation script --- src/virtualenv/activation/fish/activate.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtualenv/activation/fish/activate.fish b/src/virtualenv/activation/fish/activate.fish index f08ea3a06..e214ba1de 100644 --- a/src/virtualenv/activation/fish/activate.fish +++ b/src/virtualenv/activation/fish/activate.fish @@ -88,7 +88,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" # Prompt override provided? # If not, just prepend the environment name. if test -n '__VIRTUAL_PROMPT__' - printf '%s%s' '(__VIRTUAL_PROMPT__) ' (set_color normal) + printf '(%s) %s' '__VIRTUAL_PROMPT__' (set_color normal) else printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV") end From 15dd59b23dd42e9134abb33680cdbc1c317fc30d Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 22:46:14 +0530 Subject: [PATCH 11/23] Fix csh --- tests/unit/activation/test_csh.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/activation/test_csh.py b/tests/unit/activation/test_csh.py index 69b23b68f..066a19401 100644 --- a/tests/unit/activation/test_csh.py +++ b/tests/unit/activation/test_csh.py @@ -8,4 +8,7 @@ class Csh(activation_tester_class): def __init__(self, session): super(Csh, self).__init__(CShellActivator, session, "csh", "activate.csh", "csh") + def print_prompt(self): + return "echo $prompt" + activation_tester(Csh) From f90773064cf91a89d3ac124c2eeb181932c80e6a Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 23:44:49 +0530 Subject: [PATCH 12/23] Fix csh --- tests/unit/activation/conftest.py | 7 +++++-- tests/unit/activation/test_csh.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py index daa59b77f..606bfab53 100644 --- a/tests/unit/activation/conftest.py +++ b/tests/unit/activation/conftest.py @@ -144,8 +144,11 @@ def assert_output(self, out, raw, tmp_path): expected = self._creator.exe.parent / os.path.basename(sys.executable) assert self.norm_path(out[2]) == self.norm_path(expected), raw assert self.norm_path(out[3]) == self.norm_path(self._creator.dest).replace("\\\\", "\\"), raw - assert "({}) ".format(self._creator.env_name) in out[4], raw - assert out[5] == "wrote pydoc_test.html", raw + # Some attempts to test the prompt output print more than 1 line out. Need + prompt_text = "({}) ".format(self._creator.env_name) + assert any(prompt_text in line for line in out[4:-3]), raw + + assert out[-3] == "wrote pydoc_test.html", raw content = tmp_path / "pydoc_test.html" assert content.exists(), raw # post deactivation, same as before diff --git a/tests/unit/activation/test_csh.py b/tests/unit/activation/test_csh.py index 066a19401..1fa5146de 100644 --- a/tests/unit/activation/test_csh.py +++ b/tests/unit/activation/test_csh.py @@ -9,6 +9,6 @@ def __init__(self, session): super(Csh, self).__init__(CShellActivator, session, "csh", "activate.csh", "csh") def print_prompt(self): - return "echo $prompt" + return "echo 'source \"$VIRTUAL_ENV/bin/activate.csh\"; echo $prompt' | csh -i" activation_tester(Csh) From 287563fb6b6381a4872f5a9185bc74632af88ef7 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 30 Oct 2021 23:44:52 +0530 Subject: [PATCH 13/23] Add batch --- tests/unit/activation/test_batch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/activation/test_batch.py b/tests/unit/activation/test_batch.py index e10d902a1..973f0bad8 100644 --- a/tests/unit/activation/test_batch.py +++ b/tests/unit/activation/test_batch.py @@ -27,4 +27,7 @@ def quote(self, s): """double quotes needs to be single, and single need to be double""" return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in pipes.quote(s)) + def print_prompt(self): + return "echo %PROMPT%" + activation_tester(Batch) From f2d286a10bde15fa6d7848f96be9895d97e914f3 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:12:44 +0530 Subject: [PATCH 14/23] Add nushell --- tests/unit/activation/test_nushell.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 6eb50ba52..9c626ba2d 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -23,4 +23,7 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN + def print_prompt(self): + return "echo $virtual_prompt" + activation_tester(Nushell) From d5d98b61bc8d2b88ffe40377fe0b77515e3740e9 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:22:22 +0530 Subject: [PATCH 15/23] Add newline for nushell --- tests/unit/activation/test_nushell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 9c626ba2d..df0a2b19b 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return "echo $virtual_prompt" + return 'echo "$virtual_prompt\n"' activation_tester(Nushell) From c3c2a4684f8c7cc9744f893bcc58f303e33f0939 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:29:04 +0530 Subject: [PATCH 16/23] Fix nushell prompt --- tests/unit/activation/test_nushell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index df0a2b19b..9e8a4bed8 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return 'echo "$virtual_prompt\n"' + return r"echo $virtual_prompt; printf \\n" activation_tester(Nushell) From cf98a78dc0439d386370d3c3f232f37bb118c9ea Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:30:29 +0530 Subject: [PATCH 17/23] Improve prompt code a little bit --- tests/unit/activation/test_nushell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 9e8a4bed8..6a9c6b96e 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"echo $virtual_prompt; printf \\n" + return r"echo $virtual_prompt; printf '\n'" activation_tester(Nushell) From 9c0523e043710c168008a67232719f50b4836a1d Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:45:50 +0530 Subject: [PATCH 18/23] Try using white instead of normal --- src/virtualenv/activation/fish/activate.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/fish/activate.fish b/src/virtualenv/activation/fish/activate.fish index e214ba1de..1656d4101 100644 --- a/src/virtualenv/activation/fish/activate.fish +++ b/src/virtualenv/activation/fish/activate.fish @@ -88,9 +88,9 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" # Prompt override provided? # If not, just prepend the environment name. if test -n '__VIRTUAL_PROMPT__' - printf '(%s) %s' '__VIRTUAL_PROMPT__' (set_color normal) + printf '(%s) %s' '__VIRTUAL_PROMPT__' (set_color white) else - printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV") + printf '%s(%s) ' (set_color white) (basename "$VIRTUAL_ENV") end string join -- \n $prompt # handle multi-line prompts From 0b19fd5d999741dcf08261cfb2a46cada7a8922d Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 00:52:30 +0530 Subject: [PATCH 19/23] Remove set_color --- src/virtualenv/activation/fish/activate.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/fish/activate.fish b/src/virtualenv/activation/fish/activate.fish index 1656d4101..3cc3c93cb 100644 --- a/src/virtualenv/activation/fish/activate.fish +++ b/src/virtualenv/activation/fish/activate.fish @@ -88,9 +88,9 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" # Prompt override provided? # If not, just prepend the environment name. if test -n '__VIRTUAL_PROMPT__' - printf '(%s) %s' '__VIRTUAL_PROMPT__' (set_color white) + printf '(%s) ' '__VIRTUAL_PROMPT__' else - printf '%s(%s) ' (set_color white) (basename "$VIRTUAL_ENV") + printf '(%s) ' (basename "$VIRTUAL_ENV") end string join -- \n $prompt # handle multi-line prompts From d54bfc9b908ad663d1dd833f70ec7446133b8ac1 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 01:18:46 +0530 Subject: [PATCH 20/23] windows messes up non ascii chars --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index e4766ab99..ad8643b9c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -301,7 +301,7 @@ def is_inside_ci(): def special_char_name(): base = "e-$ Γ¨Ρ€Ρ‚πŸš’β™žδΈ­η‰‡-j" # workaround for pypy3 https://bitbucket.org/pypy/pypy/issues/3147/venv-non-ascii-support-windows - encoding = "ascii" if IS_PYPY and IS_WIN else sys.getfilesystemencoding() + encoding = "ascii" if IS_WIN else sys.getfilesystemencoding() # let's not include characters that the file system cannot encode) result = "" for char in base: From d67fbaa603810ba9f7d1fc2c5e40344356b958e8 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 13:52:24 +0530 Subject: [PATCH 21/23] Fix comment --- tests/unit/activation/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py index 606bfab53..6f2dd431c 100644 --- a/tests/unit/activation/conftest.py +++ b/tests/unit/activation/conftest.py @@ -144,7 +144,8 @@ def assert_output(self, out, raw, tmp_path): expected = self._creator.exe.parent / os.path.basename(sys.executable) assert self.norm_path(out[2]) == self.norm_path(expected), raw assert self.norm_path(out[3]) == self.norm_path(self._creator.dest).replace("\\\\", "\\"), raw - # Some attempts to test the prompt output print more than 1 line out. Need + # Some attempts to test the prompt output print more than 1 line. + # So we need to check if the prompt exists on any of them. prompt_text = "({}) ".format(self._creator.env_name) assert any(prompt_text in line for line in out[4:-3]), raw From f2ec7b8ddd6d828eedb434c4c2c015c91379dcc6 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 31 Oct 2021 13:59:36 +0530 Subject: [PATCH 22/23] Add changelog entry --- docs/changelog/2224.feature.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/changelog/2224.feature.rst diff --git a/docs/changelog/2224.feature.rst b/docs/changelog/2224.feature.rst new file mode 100644 index 000000000..3afc0878c --- /dev/null +++ b/docs/changelog/2224.feature.rst @@ -0,0 +1,3 @@ +The activated virtualenv prompt is now always wrapped in parentheses. This +affects venvs created with the ``--prompt`` attribute, and matches virtualenv's +behaviour on par with venv. From 1d4aa3dda614d39602865169a53b2f681d5cdb8d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 Oct 2021 08:29:59 +0000 Subject: [PATCH 23/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/changelog/2224.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/2224.feature.rst b/docs/changelog/2224.feature.rst index 3afc0878c..18f57010e 100644 --- a/docs/changelog/2224.feature.rst +++ b/docs/changelog/2224.feature.rst @@ -1,3 +1,3 @@ -The activated virtualenv prompt is now always wrapped in parentheses. This +The activated virtualenv prompt is now always wrapped in parentheses. This affects venvs created with the ``--prompt`` attribute, and matches virtualenv's behaviour on par with venv.