?? prompt should be wrapped in paranthesis ?? (#2224)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Tushar Sadhwani 2021-10-31 16:04:03 +05:30 committed by GitHub
parent 8da79db86d
commit 15c09d6e0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 39 additions and 9 deletions

View file

@ -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.

View file

@ -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

View file

@ -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%"
)

View file

@ -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

View file

@ -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

View file

@ -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) ') ')
}

View file

@ -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 {

View file

@ -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:

View file

@ -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)))

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)