summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Sadhwani <tushar.sadhwani000@gmail.com>2021-10-31 16:04:03 +0530
committerGitHub <noreply@github.com>2021-10-31 10:34:03 +0000
commit15c09d6e0c1eb11c18918ef67590e5291fd361f0 (patch)
tree3980a8a40f277174a66e54912d044ec511c3a653
parent8da79db86d8a5c74d03667a40e64ff832076445e (diff)
downloadvirtualenv-15c09d6e0c1eb11c18918ef67590e5291fd361f0.tar.gz
?? prompt should be wrapped in paranthesis ?? (#2224)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
-rw-r--r--docs/changelog/2224.feature.rst3
-rw-r--r--src/virtualenv/activation/bash/activate.sh2
-rw-r--r--src/virtualenv/activation/batch/activate.bat2
-rw-r--r--src/virtualenv/activation/cshell/activate.csh2
-rw-r--r--src/virtualenv/activation/fish/activate.fish4
-rw-r--r--src/virtualenv/activation/nushell/activate.nu2
-rw-r--r--src/virtualenv/activation/powershell/activate.ps12
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/unit/activation/conftest.py11
-rw-r--r--tests/unit/activation/test_bash.py3
-rw-r--r--tests/unit/activation/test_batch.py3
-rw-r--r--tests/unit/activation/test_csh.py3
-rw-r--r--tests/unit/activation/test_fish.py3
-rw-r--r--tests/unit/activation/test_nushell.py3
-rw-r--r--tests/unit/activation/test_powershell.py3
15 files changed, 39 insertions, 9 deletions
diff --git a/docs/changelog/2224.feature.rst b/docs/changelog/2224.feature.rst
new file mode 100644
index 0000000..18f5701
--- /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.
diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh
index dd7956e..fb40db6 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 184e4f9..bf774b2 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 72b2cf8..837dcda 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 faa2622..3cc3c93 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) ' '__VIRTUAL_PROMPT__'
else
- printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV")
+ printf '(%s) ' (basename "$VIRTUAL_ENV")
end
string join -- \n $prompt # handle multi-line prompts
diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu
index c1b6c32..9c1e2c2 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 a370a63..d524347 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 {
diff --git a/tests/conftest.py b/tests/conftest.py
index e4766ab..ad8643b 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:
diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py
index 5aa78bb..6f2dd43 100644
--- a/tests/unit/activation/conftest.py
+++ b/tests/unit/activation/conftest.py
@@ -126,6 +126,7 @@ class ActivationTester(object):
self.activate_call(activate_script),
self.print_python_exe(),
self.print_os_env_var("VIRTUAL_ENV"),
+ self.print_prompt(),
# \\ loads documentation from the virtualenv site packages
self.pydoc_call,
self.deactivate,
@@ -143,7 +144,12 @@ class ActivationTester(object):
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
+ # 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
+
+ assert out[-3] == "wrote pydoc_test.html", raw
content = tmp_path / "pydoc_test.html"
assert content.exists(), raw
# post deactivation, same as before
@@ -172,6 +178,9 @@ class ActivationTester(object):
),
)
+ 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 fccef65..612ad37 100644
--- a/tests/unit/activation/test_bash.py
+++ b/tests/unit/activation/test_bash.py
@@ -19,4 +19,7 @@ def test_bash(raise_on_non_source_class, activation_tester):
"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_batch.py b/tests/unit/activation/test_batch.py
index e10d902..973f0ba 100644
--- a/tests/unit/activation/test_batch.py
+++ b/tests/unit/activation/test_batch.py
@@ -27,4 +27,7 @@ def test_batch(activation_tester_class, activation_tester, tmp_path, activation_
"""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)
diff --git a/tests/unit/activation/test_csh.py b/tests/unit/activation/test_csh.py
index 69b23b6..1fa5146 100644
--- a/tests/unit/activation/test_csh.py
+++ b/tests/unit/activation/test_csh.py
@@ -8,4 +8,7 @@ def test_csh(activation_tester_class, activation_tester):
def __init__(self, session):
super(Csh, self).__init__(CShellActivator, session, "csh", "activate.csh", "csh")
+ def print_prompt(self):
+ return "echo 'source \"$VIRTUAL_ENV/bin/activate.csh\"; echo $prompt' | csh -i"
+
activation_tester(Csh)
diff --git a/tests/unit/activation/test_fish.py b/tests/unit/activation/test_fish.py
index 8604ff9..7b229e0 100644
--- a/tests/unit/activation/test_fish.py
+++ b/tests/unit/activation/test_fish.py
@@ -17,4 +17,7 @@ def test_fish(activation_tester_class, activation_tester, monkeypatch, tmp_path)
def __init__(self, session):
super(Fish, self).__init__(FishActivator, session, "fish", "activate.fish", "fish")
+ def print_prompt(self):
+ return "fish_prompt"
+
activation_tester(Fish)
diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py
index 6eb50ba..6a9c6b9 100644
--- a/tests/unit/activation/test_nushell.py
+++ b/tests/unit/activation/test_nushell.py
@@ -23,4 +23,7 @@ def test_nushell(activation_tester_class, activation_tester):
self.unix_line_ending = not IS_WIN
+ def print_prompt(self):
+ return r"echo $virtual_prompt; printf '\n'"
+
activation_tester(Nushell)
diff --git a/tests/unit/activation/test_powershell.py b/tests/unit/activation/test_powershell.py
index 2d6d9eb..f3705cd 100644
--- a/tests/unit/activation/test_powershell.py
+++ b/tests/unit/activation/test_powershell.py
@@ -32,4 +32,7 @@ def test_powershell(activation_tester_class, activation_tester, monkeypatch):
def invoke_script(self):
return [self.cmd, "-File"]
+ def print_prompt(self):
+ return "prompt"
+
activation_tester(PowerShell)