Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-89427: Provide the original prompt value for VIRTUAL_ENV_PROMPT #106726

Merged
merged 1 commit into from
Jan 23, 2024
Merged

gh-89427: Provide the original prompt value for VIRTUAL_ENV_PROMPT #106726

merged 1 commit into from
Jan 23, 2024

Conversation

jimporter
Copy link
Contributor

@jimporter jimporter commented Jul 13, 2023

This improves the implementation in gh-106643.

Previously, venv passed "(<prompt>) " to the activation scripts, but we want to provide the original value so that users can inspect it in the $VIRTUAL_ENV_PROMPT env var.

Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with parens a second time, so no change was necessary in that file.


Sorry for the noise; I didn't quite understand the flow of this code until I started comparing it more closely to the implementation in the virtualenv package.

I was careful to test this change in action (only using the Bash version of the activation script, since that's the shell I have), but I also checked the generated scripts and they all look correct to me. After calling python -m venv foobar (results are also as expected if I pass --prompt=something):

activate

VIRTUAL_ENV_PROMPT="foobar"
export VIRTUAL_ENV_PROMPT

# ...

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    PS1="(foobar) ${PS1:-}"
    export PS1
fi

activate.csh

setenv VIRTUAL_ENV_PROMPT "foobar"


set _OLD_VIRTUAL_PROMPT="$prompt"

if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
    set prompt = "(foobar) $prompt"
endif

activate.fish

set -gx VIRTUAL_ENV_PROMPT "foobar"

# ...

if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
    # ...
    function fish_prompt
        # ...
        # Output the venv prompt; color taken from the blue of the Python logo.
        printf "(%s%s%s) " (set_color 4B8BBE) "foobar" (set_color normal)
        # ...
    end

    set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end

@jimporter
Copy link
Contributor Author

@vsajip Is there anything else I should do with this patch before it merges? This change will keep venv's behavior in-sync with virtualenv (see pypa/virtualenv#2606).

@vsajip
Copy link
Member

vsajip commented Aug 4, 2023

Sorry, not had time to review this. Hope to get to it soon.

@jimporter
Copy link
Contributor Author

Sorry, not had time to review this. Hope to get to it soon.

No problem! Just wanted to make sure you weren't waiting on me for something.

@jimporter
Copy link
Contributor Author

@vsajip I rebased this and fixed the merge conflicts, which had the nice benefit of actually making the diff smaller.

This improves the implementation in gh-106643.

Previously, venv passed "(<prompt>) " to the activation scripts, but we want
to provide the original value so that users can inspect it in the
$VIRTUAL_ENV_PROMPT env var.

Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with
parens a second time, so no change was necessary in that file.
@jimporter
Copy link
Contributor Author

@vsajip Just checking again to see if you have bandwidth to review. I rebased again so it should merge cleanly.

@vsajip vsajip merged commit 8edc802 into python:main Jan 23, 2024
30 checks passed
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…MPT (pythonGH-106726)

This improves the implementation in pythongh-106643.

Previously, venv passed "(<prompt>) " to the activation scripts, but we want
to provide the original value so that users can inspect it in the
$VIRTUAL_ENV_PROMPT env var.

Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with
parens a second time, so no change was necessary in that file.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…MPT (pythonGH-106726)

This improves the implementation in pythongh-106643.

Previously, venv passed "(<prompt>) " to the activation scripts, but we want
to provide the original value so that users can inspect it in the
$VIRTUAL_ENV_PROMPT env var.

Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with
parens a second time, so no change was necessary in that file.
artizirk added a commit to artizirk/dotfiles that referenced this pull request Oct 29, 2024
And ignore VIRTUAL_ENV_PROMPT variable for now as it is different
between venv and virtualenv implementations:

* python/cpython#106726
* pypa/virtualenv#2606
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants