|
1 | 1 | import os |
2 | 2 | import pathlib |
| 3 | +import platform |
3 | 4 | import shutil |
4 | 5 | import subprocess |
5 | 6 | import warnings |
@@ -37,32 +38,44 @@ def __init__( |
37 | 38 |
|
38 | 39 | def create(self) -> None: |
39 | 40 | """Function for creating a virtual environment.""" |
40 | | - self.pyenv_root = pathlib.Path(subprocess.check_output(["pyenv", "root"]).decode().strip()) |
| 41 | + self.pyenv_root = pathlib.Path( |
| 42 | + subprocess.check_output(["pyenv", "root"]).decode().strip()) |
41 | 43 | self.env_path = self.pyenv_root / "versions" / self.name |
42 | | - self.python_path = self.pyenv_root / "versions" / self.name / "bin" / "python" |
| 44 | + if platform.system == "Windows": |
| 45 | + self.python_path = self.pyenv_root / "versions" / \ |
| 46 | + self.name / "Scripts" / "python.exe" |
| 47 | + else: |
| 48 | + self.python_path = self.pyenv_root / "versions" / self.name / "bin" / "python" |
43 | 49 |
|
44 | | - subprocess.check_call(["pyenv", "install", self.py_version, "--skip-existing"]) |
| 50 | + subprocess.check_call( |
| 51 | + ["pyenv", "install", self.py_version, "--skip-existing"]) |
45 | 52 | if os.path.exists(self.env_path): |
46 | | - warnings.warn(f"Skipping pyenv venv creation for {self.name}. Venv already exists.") |
| 53 | + warnings.warn( |
| 54 | + f"Skipping pyenv venv creation for {self.name}. Venv already exists.") |
47 | 55 | else: |
48 | | - subprocess.check_call(["pyenv", "virtualenv", self.py_version, self.name]) |
| 56 | + subprocess.check_call( |
| 57 | + ["pyenv", "virtualenv", self.py_version, self.name]) |
49 | 58 |
|
50 | 59 | def install_requirements(self) -> None: |
51 | 60 | """Function to install any and all requirements for running a script in the virtual |
52 | 61 | environment.""" |
53 | | - subprocess.check_call([str(self.python_path), "-m", "pip", "install", "-U", "pip"]) |
| 62 | + subprocess.check_call( |
| 63 | + [str(self.python_path), "-m", "pip", "install", "-U", "pip"]) |
54 | 64 | if isinstance(self.requirements, list) and self.requirements: |
55 | 65 | subprocess.check_call( |
56 | | - [str(self.python_path), "-m", "pip", "install"] + self.requirements |
| 66 | + [str(self.python_path), "-m", "pip", |
| 67 | + "install"] + self.requirements |
57 | 68 | ) |
58 | 69 | elif isinstance(self.requirements, pathlib.Path): |
59 | 70 | subprocess.check_call( |
60 | | - [str(self.python_path), "-m", "pip", "install", "-r", str(self.requirements)] |
| 71 | + [str(self.python_path), "-m", "pip", |
| 72 | + "install", "-r", str(self.requirements)] |
61 | 73 | ) |
62 | 74 |
|
63 | 75 | def start(self) -> None: |
64 | 76 | """Function to start a script in the previously created virtual environment""" |
65 | | - p = subprocess.Popen([str(self.python_path), str(self.script_path)] + self.script_args) |
| 77 | + p = subprocess.Popen([str(self.python_path), str( |
| 78 | + self.script_path)] + self.script_args) |
66 | 79 | p.communicate() |
67 | 80 |
|
68 | 81 | def clean(self) -> None: |
|
0 commit comments