Created
January 22, 2023 05:29
-
-
Save Mandera/0384535c862a14b17155d5ef548e5af8 to your computer and use it in GitHub Desktop.
Idea for activate venvs cross platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def activate(self): | |
""" https://docs.python.org/3/library/venv.html#how-venvs-work | |
https://stackoverflow.com/a/73714518/3936044 | |
This one said - If passing a single string, either shell must be True (see below) or else | |
the string must simply name the program to be executed without specifying any arguments. """ | |
activation_commands = [ | |
["source", self.path / "Scripts/activate"], # bash | |
[self.path / "bin/activate.bat"], # cmd windows | |
[self.path / "Scripts/Activate.ps1"], # PowerShell windows | |
[self.path / "bin/Activate.ps1"], # PowerShell linux | |
] | |
for cmd in activation_commands: | |
print(cmd) | |
if Terminal(*cmd, error=False, shell=True).success: | |
return True | |
raise FileNotFoundError(f"Failed to activate venv '{self.path}'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment