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

Fixes #5535 venv powershell infinite prompt #8228

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions conans/client/envvars/environment.py
Expand Up @@ -70,7 +70,7 @@

ps1_activate = textwrap.dedent("""\
{%- for it in modified_vars %}
$env:CONAN_OLD_{{it}}=$env:{{it}}
$env:CONAN_OLD_{{venv_name}}_{{it}}=$env:{{it}}
{%- endfor %}

foreach ($line in Get-Content "{{ environment_file }}") {
Expand All @@ -79,20 +79,20 @@
Set-Item env:\\$var -Value "$value_expanded"
}

function global:_old_conan_prompt {""}
$function:_old_conan_prompt = $function:prompt
function global:_old_conan_{{venv_name}}_prompt {""}
$function:_old_conan_{{venv_name}}_prompt = $function:prompt
function global:prompt {
write-host "({{venv_name}}) " -nonewline; & $function:_old_conan_prompt
write-host "({{venv_name}}) " -nonewline; & $function:_old_conan_{{venv_name}}_prompt
}
""")

ps1_deactivate = textwrap.dedent("""\
$function:prompt = $function:_old_conan_prompt
remove-item function:_old_conan_prompt
$function:prompt = $function:_old_conan_{{venv_name}}_prompt
remove-item function:_old_conan_{{venv_name}}_prompt

{% for it in modified_vars %}
$env:{{it}}=$env:CONAN_OLD_{{it}}
Remove-Item env:CONAN_OLD_{{it}}
$env:{{it}}=$env:CONAN_OLD_{{venv_name}}_{{it}}
Remove-Item env:CONAN_OLD_{{venv_name}}_{{it}}
{%- endfor %}
{%- for it in new_vars %}
Remove-Item env:{{it}}
Expand Down Expand Up @@ -174,7 +174,8 @@ def _files(env_vars, vars_with_spaces, flavor, activate_tpl, deactivate_tpl, ven
activate_content = activate_tpl.render(environment_file=env_filepath,
modified_vars=modified_vars, new_vars=new_vars,
venv_name=venv_name)
deactivate_content = deactivate_tpl.render(modified_vars=modified_vars, new_vars=new_vars)
deactivate_content = deactivate_tpl.render(modified_vars=modified_vars, new_vars=new_vars,
venv_name=venv_name)

environment_lines = ["{}={}".format(name, value) for name, value, _ in ret]
# This blank line is important, otherwise the script doens't process last line
Expand Down