added powershell support to virtualenv generator
@@ -45,6 +45,24 @@ def get_dict_values(deps_env_info):
simple_to_set[name] = value.replace("\\", "/")
return multiple_to_set, simple_to_set
+def gen_ps1_lines(name, simple_to_set, multiple_to_set):
+ deactivate_lines = []
+ activate_lines = []
+ all_vars = copy.copy(multiple_to_set)
+ all_vars.update(simple_to_set)
+ activate_lines.append("function global:_old_conan_prompt {\"\"}")
+ activate_lines.append("$function:_old_conan_prompt = $function:prompt")
+ activate_lines.append("function global:prompt { write-host \"(%s) \" -nonewline; & $function:_old_conan_prompt }" % name )
+ deactivate_lines.append("$function:prompt = $function:_old_conan_prompt")
+ deactivate_lines.append("remove-item function:\\_old_conan_prompt")
+ for var_name in all_vars.keys():
+ old_value = os.environ.get(var_name, "")
+ deactivate_lines.append("$env:%s = \"%s\"" % (var_name, old_value))
+ for name, value in multiple_to_set.items():
+ activate_lines.append("$env:%s = \"%s\" + \";$env:%s\"" % (name, value, name))
+ for name, value in simple_to_set.items():
+ activate_lines.append("$env:%s = \"%s\"" % (name, value))
+ return (activate_lines, deactivate_lines)
class VirtualEnvGenerator(Generator):
@@ -78,6 +96,15 @@ class VirtualEnvGenerator(Generator):
activate_lines.append("export PS1=\"(%s) " % venv_name + "$PS1\"")
activate_lines.extend(get_setenv_variables_commands(self.deps_env_info))
+
ext = "bat" if platform.system() == "Windows" else "sh"
- return {"activate.%s" % ext: os.linesep.join(activate_lines),
+ result = {"activate.%s" % ext: os.linesep.join(activate_lines),
"deactivate.%s" % ext: os.linesep.join(deactivate_lines)}
+ alt_shell = {}
+ if platform.system() == "Windows":
+ ps1_activate, ps1_deactivate = gen_ps1_lines(venv_name, simple_to_set, multiple_to_set)
+ alt_shell = {"activate.ps1": os.linesep.join(ps1_activate),
+ "deactivate.ps1": os.linesep.join(ps1_deactivate)}
+ result.update(alt_shell)
+ return result
+
