Skip to content

Commit 1a5c456

Browse files
committed
Add windows support
1 parent 32a6c2a commit 1a5c456

7 files changed

Lines changed: 84 additions & 47 deletions

File tree

.github/workflows/conda.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ jobs:
1010
matrix:
1111
os:
1212
- Ubuntu
13+
- Windows
14+
- MacOs
1315
py:
14-
- "3.8"
16+
- 3.8.9
1517

1618
steps:
1719
- name: Setup python for test ${{ matrix.py }}
@@ -24,8 +26,8 @@ jobs:
2426
python-version: ${{ matrix.python-version}}
2527
- uses: actions/checkout@v3
2628
- name: Upgrade pip
27-
run: python -m pip install -U pip
29+
run: python3 -m pip install -U pip
2830
- name: Install dependencies
29-
run: python -m pip install -e '.[test]'
31+
run: python3 -m pip install -e '.[test]'
3032
- name: Run pytest
31-
run: pytest
33+
run: python3 -m pytest

.github/workflows/pyenv.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ on: [push, pull_request]
33

44
jobs:
55
job:
6-
name: "Pytest with pyenv"
7-
runs-on: ubuntu-latest
6+
name: test ${{ matrix.py }} - ${{ matrix.os }}
7+
runs-on: ${{ matrix.os }}-latest
88
strategy:
99
matrix:
1010
python:
1111
- 3.9
12+
os:
13+
- Ubuntu
14+
- Windows
15+
- MacOs
1216

1317
steps:
14-
- uses: actions/checkout@v3
15-
- name: Install python version
16-
uses: gabrielfalcao/pyenv-action@v13
17-
with:
18-
default: "${{ matrix.python }}"
19-
command: pip install -U pip # upgrade pip after installing python
20-
- name: Install pyenv-virtualenv
21-
run: git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
22-
- name: Install dependencies
23-
run: pip install -e '.[test]'
24-
- name: Run tests
25-
run: pytest
18+
- uses: actions/checkout@v3
19+
- name: Install python version
20+
uses: gabrielfalcao/pyenv-action@v13
21+
with:
22+
default: "${{ matrix.python }}"
23+
command: pip3 install -U pip # upgrade pip after installing python
24+
- name: Install pyenv-virtualenv
25+
run: git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
26+
- name: Install dependencies
27+
run: pip3 install -e '.[test]'
28+
- name: Run tests
29+
run: python3 -m pytest

.github/workflows/venv.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ jobs:
1010
matrix:
1111
os:
1212
- Ubuntu
13-
# - Windows
13+
- Windows
1414
- MacOs
1515
py:
1616
- "3.11"
1717
- "3.10"
1818
- "3.9"
19-
- "3.8"
19+
- "3.8.9"
2020

2121
steps:
2222
- name: Setup python for test ${{ matrix.py }}
@@ -25,8 +25,8 @@ jobs:
2525
python-version: ${{ matrix.py }}
2626
- uses: actions/checkout@v3
2727
- name: Upgrade pip
28-
run: python -m pip install -U pip
28+
run: python3 -m pip install -U pip
2929
- name: Install dependencies
30-
run: python -m pip install -e '.[test]'
30+
run: python3 -m pip install -e '.[test]'
3131
- name: Run pytest
32-
run: pytest
32+
run: python3 -m pytest

python_compose/unit/conda.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,32 @@ def __init__(
3232

3333
def create(self) -> None:
3434
"""Function for creating a virtual environment."""
35-
envs = [
36-
row.split()[0]
37-
for row in subprocess.check_output(["conda", "env", "list"]).decode().split("\n")[2:]
38-
if row
39-
]
35+
conda_env_list = subprocess.check_output(
36+
["conda", "env", "list"]).decode().splitlines()
37+
envs = []
38+
print(conda_env_list)
39+
if len(conda_env_list) >= 2:
40+
envs = [
41+
row.split()[0]
42+
for row in conda_env_list[2:]
43+
if row
44+
]
4045
if self.name in envs:
41-
warnings.warn(f"Skipping pyenv venv creation for {self.name}. Venv already exists.")
46+
warnings.warn(
47+
f"Skipping pyenv venv creation for {self.name}. Venv already exists.")
4248
else:
4349
subprocess.check_call(["conda", "create", "-n", self.name, "-y"])
4450

4551
def install_requirements(self) -> None:
4652
"""Function to install any and all requirements for running a script in the virtual
4753
environment."""
4854
if isinstance(self.requirements, list) and self.requirements:
49-
subprocess.check_call(["conda", "install", "-n", self.name] + self.requirements)
55+
subprocess.check_call(
56+
["conda", "install", "-n", self.name] + self.requirements)
5057
elif isinstance(self.requirements, pathlib.Path):
5158
subprocess.check_call(
52-
["conda", "install", "-n", self.name, "-f", str(self.requirements)]
59+
["conda", "install", "-n", self.name,
60+
"-f", str(self.requirements)]
5361
)
5462

5563
def start(self) -> None:

python_compose/unit/pyenv_virtualenv.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pathlib
3+
import platform
34
import shutil
45
import subprocess
56
import warnings
@@ -37,32 +38,44 @@ def __init__(
3738

3839
def create(self) -> None:
3940
"""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())
4143
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"
4349

44-
subprocess.check_call(["pyenv", "install", self.py_version, "--skip-existing"])
50+
subprocess.check_call(
51+
["pyenv", "install", self.py_version, "--skip-existing"])
4552
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.")
4755
else:
48-
subprocess.check_call(["pyenv", "virtualenv", self.py_version, self.name])
56+
subprocess.check_call(
57+
["pyenv", "virtualenv", self.py_version, self.name])
4958

5059
def install_requirements(self) -> None:
5160
"""Function to install any and all requirements for running a script in the virtual
5261
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"])
5464
if isinstance(self.requirements, list) and self.requirements:
5565
subprocess.check_call(
56-
[str(self.python_path), "-m", "pip", "install"] + self.requirements
66+
[str(self.python_path), "-m", "pip",
67+
"install"] + self.requirements
5768
)
5869
elif isinstance(self.requirements, pathlib.Path):
5970
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)]
6173
)
6274

6375
def start(self) -> None:
6476
"""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)
6679
p.communicate()
6780

6881
def clean(self) -> None:

python_compose/unit/venv.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pathlib
2+
import platform
23
import shutil
34
import subprocess
45
from typing import List, Union
@@ -31,31 +32,38 @@ def __init__(
3132
self.name = name
3233
self.env_dir = env_dir
3334
self.env_path = self.env_dir / self.name
34-
self.python_path = self.env_path / "bin" / "python"
35+
if platform.system() == "Windows":
36+
self.python_path = self.env_path / "Scripts" / "python.exe"
37+
else:
38+
self.python_path = self.env_path / "bin" / "python"
3539
self.requirements = requirements
3640
self.script_path = script_path
3741
self.script_args = script_args
3842

3943
def create(self) -> None:
4044
"""Function for creating a virtual environment."""
41-
self.env = EnvBuilder(system_site_packages=True, clear=False, with_pip=True)
45+
self.env = EnvBuilder(system_site_packages=True,
46+
clear=False, with_pip=True)
4247
self.env.create(self.env_path)
4348

4449
def install_requirements(self) -> None:
4550
"""Function to install any and all requirements for running a script in the virtual
4651
environment."""
4752
if isinstance(self.requirements, list) and self.requirements:
4853
subprocess.check_call(
49-
[str(self.python_path), "-m", "pip", "install"] + self.requirements
54+
[str(self.python_path), "-m", "pip",
55+
"install"] + self.requirements
5056
)
5157
elif isinstance(self.requirements, pathlib.Path):
5258
subprocess.check_call(
53-
[str(self.python_path), "-m", "pip", "install", "-r", str(self.requirements)]
59+
[str(self.python_path), "-m", "pip",
60+
"install", "-r", str(self.requirements)]
5461
)
5562

5663
def start(self) -> None:
5764
"""Function to start a script in the previously created virtual environment."""
58-
p = subprocess.Popen([str(self.python_path), str(self.script_path)] + self.script_args)
65+
p = subprocess.Popen([str(self.python_path), str(
66+
self.script_path)] + self.script_args)
5967
p.communicate()
6068

6169
def clean(self) -> None:

tests/test_compose.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pathlib
3+
import platform
34
import random
45
import shutil
56
import string
@@ -62,7 +63,7 @@ def test_conda(tmp_path: pathlib.Path, random_string: str) -> None:
6263
"test",
6364
[],
6465
[
65-
"python",
66+
"python3",
6667
os.path.join("tests", "create_file.py"),
6768
str(output_file),
6869
random_string,
@@ -84,7 +85,8 @@ def test_yaml_deserialization() -> None:
8485

8586

8687
def test_pydantic_to_compose_unit() -> None:
87-
units = compose.pydantic_to_units(compose.from_yaml(pathlib.Path("tests") / "config.yaml"))
88+
units = compose.pydantic_to_units(
89+
compose.from_yaml(pathlib.Path("tests") / "config.yaml"))
8890
assert len(units) == 3
8991
counter: Counter[str] = Counter()
9092
for unit in units:

0 commit comments

Comments
 (0)