Skip to content

Commit e18cb06

Browse files
committed
Cleaned up implementation/testing of install_recipe()/uninstall_recipe()
1 parent a28648a commit e18cb06

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

tests/wfchef/test_wfchef.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ def test_create_recipe(self) -> None:
8282
sys.stderr.write("Installing the recipe...\n")
8383
sys.stderr.write("=" * 60 + "\n")
8484

85-
success = install_recipe(dirpath, verbose=True)
86-
assert success, "Recipe installation failed"
85+
try:
86+
install_recipe("/bogus/bogus/whatever", verbose=True)
87+
raise Exception("Should not be able to install a recipe given a bogus path")
88+
except FileNotFoundError as e:
89+
pass
90+
91+
install_recipe(dirpath, verbose=True)
8792
sys.stderr.write("✓ Recipe installed successfully\n")
8893

8994
sys.stderr.write("\n" + "=" * 60 + "\n")
@@ -110,8 +115,7 @@ def test_create_recipe(self) -> None:
110115
sys.stderr.write("Uninstalling the recipe...\n")
111116
sys.stderr.write("=" * 60 + "\n")
112117

113-
success = uninstall_recipe("somename")
114-
assert success, "Recipe uninstallation failed"
118+
uninstall_recipe("somename")
115119
sys.stderr.write("✓ Recipe uninstalled successfully\n")
116120

117121
sys.stderr.write("\n" + "=" * 60 + "\n")

wfcommons/wfchef/chef.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,22 @@ def ls_recipe():
232232
def install_recipe(recipe_path: Union[str, pathlib.Path],
233233
verbose: bool = False):
234234
"""
235-
Installs a recipe from a local directory into the system. The recipe will be
235+
Installs a recipe from a local directory into the system.
236236
237237
:param recipe_path: Path to the recipe directory (containing setup.py or pyproject.toml)
238238
:param verbose: If True, show detailed pip output
239239
"""
240240
recipe_path = pathlib.Path(recipe_path).resolve()
241241

242242
if not recipe_path.exists():
243-
print(f"Error: Recipe path does not exist: {recipe_path}")
244-
return False
243+
raise FileNotFoundError(f"Recipe path does not exist: {recipe_path}")
245244

246245
# Check for setup.py or pyproject.toml
247246
has_setup = recipe_path.joinpath("setup.py").exists()
248247
has_pyproject = recipe_path.joinpath("pyproject.toml").exists()
249248

250249
if not (has_setup or has_pyproject):
251-
print(f"Error: No setup.py or pyproject.toml found in {recipe_path}")
252-
return False
250+
raise FileNotFoundError(f"No setup.py or pyproject.toml found in {recipe_path}")
253251

254252
try:
255253
cmd = [sys.executable, "-m", "pip", "install"]
@@ -266,18 +264,15 @@ def install_recipe(recipe_path: Union[str, pathlib.Path],
266264
result = subprocess.run(cmd, capture_output=True, text=True)
267265

268266
if result.returncode != 0:
269-
print(f"Installation failed: {result.stderr}")
270-
return False
267+
raise RuntimeError(f"Installation failed: {result.stderr}")
271268
else:
272269
print(f"Successfully installed recipe from {recipe_path}")
273270
if verbose:
274271
print(result.stdout)
275-
return True
276272

277273
except Exception as e:
278-
print(f"Could not install recipe from {recipe_path}: {e}")
279274
traceback.print_exc()
280-
return False
275+
raise RuntimeError(f"Could not install recipe from {recipe_path}: {e}")
281276

282277

283278
def uninstall_recipe(recipe_name: str):
@@ -294,21 +289,16 @@ def uninstall_recipe(recipe_name: str):
294289

295290
try:
296291
cmd = [sys.executable, "-m", "pip", "uninstall", "-y", package_name]
297-
print(f"Uninstalling: {package_name}")
298-
print(f"Command: {' '.join(cmd)}")
292+
# print(f"Uninstalling: {package_name}")
293+
# print(f"Command: {' '.join(cmd)}")
299294
result = subprocess.run(cmd, capture_output=True, text=True)
300295

301296
if result.returncode != 0:
302-
print(f"Uninstall failed: {result.stderr}")
303-
return False
304-
else:
305-
print(f"Successfully uninstalled {package_name}")
306-
return True
297+
raise RuntimeError(f"Uninstall failed: {result.stderr}")
307298

308299
except Exception as e:
309-
print(f"Could not uninstall recipe for {recipe_name}: {e}")
310300
traceback.print_exc()
311-
return False
301+
raise RuntimeError(f"Could not uninstall recipe for {recipe_name}: {e}")
312302

313303

314304
def create_recipe(path_to_instances: Union[str, pathlib.Path],

0 commit comments

Comments
 (0)