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

parenthesis issue in activate.bat - caused by PR 2221 #2225

Closed
rusitzky opened this issue Oct 26, 2021 · 3 comments · Fixed by #2226
Closed

parenthesis issue in activate.bat - caused by PR 2221 #2225

rusitzky opened this issue Oct 26, 2021 · 3 comments · Fixed by #2226

Comments

@rusitzky
Copy link

rusitzky commented Oct 26, 2021

The fix in #2221 for the extra parenthesis in "activate.bat" seems to have broken the prompt change when used interactively. Now, the prompt does not change when you invoke "activate.bat". I agree there was an extra parenthesis before this fix, but apparently that caused the SET PROMPT to have the correct updated value of ENV_PROMPT when it was evaluated b/c that put it outside the other block.

@gaborbernat
Copy link
Contributor

@SiggyBar can you look into this?

@SigmundVik
Copy link
Contributor

Yes, #2221 did indeed break the prompt, sorry about that 😢 (I am not using cmd, so I did not notice.)

The problem is caused by the expansion order inside the if, as explained here. For some obscure reason, the stray closing parenthesis changed the expansion order..

Maybe this is an acceptable fix?

if not defined VIRTUAL_ENV_DISABLE_PROMPT (
    set "ENV_PROMPT=__VIRTUAL_PROMPT__"
    if NOT DEFINED ENV_PROMPT (
        for %%d in ("%VIRTUAL_ENV%") do set "ENV_PROMPT=(%%~nxd) "
    )
    set "PROMPT=%ENV_PROMPT%%PROMPT%"
)

->

if not defined VIRTUAL_ENV_DISABLE_PROMPT (
    if "__VIRTUAL_PROMPT__" NEQ "" (
        set "PROMPT=__VIRTUAL_PROMPT__%PROMPT%"
    ) else (
        for %%d in ("%VIRTUAL_ENV%") do set "PROMPT=(%%~nxd) %PROMPT%"
    )
)

@gaborbernat
Copy link
Contributor

Please put in a PR if solves the issue 👍

SigmundVik added a commit to SigmundVik/virtualenv that referenced this issue Oct 27, 2021
Removing the stray closing parenthesis in activate.bat in commit
35ec441 broke the virtual environment prompt prefix in Windows cmd.
The reason for this was that the ill-formed closing parenthesis
somehow affected the variable expansion order.

This commit fixes the issue by not using a local ENV_PROMPT
variable to update the prompt.  (So an additional benefit of
this change is one less variable set in the environment.)

Fixes: pypa#2225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants