Skip to content

Commit 5ac3caf

Browse files
authored
Merge pull request #118 from wfcommons/recipe_install_uninstall
Recipe install uninstall
2 parents 4b53796 + 1438a21 commit 5ac3caf

File tree

3 files changed

+507
-81
lines changed

3 files changed

+507
-81
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies = [
3838
"stringcase",
3939
"filelock",
4040
"pathos",
41+
"tomli-w"
4142
]
4243
dynamic = ["version", "entry-points", "scripts"]
4344

tests/wfchef/test_wfchef.py

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from tests.test_helpers import _create_fresh_local_dir
1919
from wfcommons.wfchef.chef import create_recipe
20+
from wfcommons.wfchef.chef import install_recipe
2021
from wfcommons.wfchef.chef import uninstall_recipe
2122
from wfcommons.wfchef.chef import ls_recipe
2223

@@ -32,10 +33,11 @@ def test_create_recipe(self) -> None:
3233
dirpath = _create_fresh_local_dir("/tmp/recipe/")
3334

3435
# Put a few JSON workflows in /tmp
35-
urls = ["https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json",
36-
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-002.json",
37-
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-003.json",
38-
]
36+
urls = [
37+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json",
38+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-002.json",
39+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-003.json",
40+
]
3941
for url in urls:
4042
response = requests.get(url)
4143
local_file_name = url.split("/")[-1]
@@ -49,28 +51,77 @@ def test_create_recipe(self) -> None:
4951
"name": "somename",
5052
"cutoff": 4000
5153
}
52-
create_recipe(args["path"], args["out"], args["name"], cutoff=args["cutoff"], verbose=True)
53-
54-
# Check that some of the expected files are there
55-
assert((dirpath / "setup.py").exists())
56-
assert((dirpath / "recipe_recipes" / "__init__.py").exists())
57-
assert((dirpath / "recipe_recipes" / "__init__.py").exists())
58-
assert((dirpath / "recipe_recipes" / "somename" / "__init__.py").exists())
59-
assert((dirpath / "recipe_recipes" / "somename" / "__init__.py").exists())
60-
assert((dirpath / "recipe_recipes" / "somename" / "recipe.py").exists())
61-
assert((dirpath / "recipe_recipes" / "somename" / "microstructures").exists())
6254

55+
sys.stderr.write("\n" + "=" * 60 + "\n")
56+
sys.stderr.write("Creating recipe...\n")
57+
sys.stderr.write("=" * 60 + "\n")
58+
59+
create_recipe(
60+
args["path"],
61+
args["out"],
62+
args["name"],
63+
cutoff=args["cutoff"],
64+
verbose=True
65+
)
66+
67+
# Check that expected files are there
68+
sys.stderr.write("\nVerifying created files...\n")
69+
assert (dirpath / "pyproject.toml").exists(), "pyproject.toml not found"
70+
assert (dirpath / "wfchef_recipe_somename" / "__init__.py").exists(), "package __init__.py not found"
71+
assert (dirpath / "wfchef_recipe_somename" / "recipe.py").exists(), "recipe.py not found"
72+
assert (dirpath / "wfchef_recipe_somename" / "microstructures").exists(), "microstructures not found"
73+
sys.stderr.write("✓ All expected files created\n")
74+
75+
sys.stderr.write("\n" + "=" * 60 + "\n")
76+
sys.stderr.write("Calling ls_recipe before the install:\n")
77+
sys.stderr.write("=" * 60 + "\n")
6378
ls_recipe()
6479

6580
# Install the recipe
81+
sys.stderr.write("\n" + "=" * 60 + "\n")
6682
sys.stderr.write("Installing the recipe...\n")
67-
subprocess.check_call([sys.executable, "-m", "pip", "install", "/tmp/recipe"])
83+
sys.stderr.write("=" * 60 + "\n")
84+
85+
success = install_recipe(dirpath, verbose=True)
86+
assert success, "Recipe installation failed"
87+
sys.stderr.write("✓ Recipe installed successfully\n")
88+
89+
sys.stderr.write("\n" + "=" * 60 + "\n")
90+
sys.stderr.write("Calling ls_recipe after the install:\n")
91+
sys.stderr.write("=" * 60 + "\n")
92+
ls_recipe()
93+
94+
# Verify the recipe can be loaded
95+
sys.stderr.write("\n" + "=" * 60 + "\n")
96+
sys.stderr.write("Testing the recipe import...\n")
97+
sys.stderr.write("=" * 60 + "\n")
98+
99+
try:
100+
from wfchef_recipe_somename import SomenameRecipe
101+
sys.stderr.write("✓ Successfully imported SomenameRecipe\n")
102+
sys.stderr.write(f" Recipe class: {SomenameRecipe}\n")
103+
sys.stderr.write(f" Module: {SomenameRecipe.__module__}\n")
104+
except ImportError as e:
105+
sys.stderr.write(f"✗ Failed to import recipe: {e}\n")
106+
raise
68107

69108
# Uninstall the recipe
70-
# TODO: This does not uninstall the recipe (to fix)
71-
# sys.stderr.write("Uninstalling the recipe...\n")
72-
# uninstall_recipe("/tmp/recipe")
73-
# ls_recipe()
109+
sys.stderr.write("\n" + "=" * 60 + "\n")
110+
sys.stderr.write("Uninstalling the recipe...\n")
111+
sys.stderr.write("=" * 60 + "\n")
112+
113+
success = uninstall_recipe("somename")
114+
assert success, "Recipe uninstallation failed"
115+
sys.stderr.write("✓ Recipe uninstalled successfully\n")
116+
117+
sys.stderr.write("\n" + "=" * 60 + "\n")
118+
sys.stderr.write("Calling ls_recipe after the uninstall:\n")
119+
sys.stderr.write("=" * 60 + "\n")
120+
ls_recipe()
121+
122+
sys.stderr.write("\n" + "=" * 60 + "\n")
123+
sys.stderr.write("TEST COMPLETED SUCCESSFULLY\n")
124+
sys.stderr.write("=" * 60 + "\n")
74125

75126

76127
# TODO: Do more extensive tests

0 commit comments

Comments
 (0)