Skip to content

Commit c576b8e

Browse files
Merge wfchef_updates into main
2 parents 9d47f0a + 41c61c7 commit c576b8e

4 files changed

Lines changed: 32 additions & 62 deletions

File tree

wfcommons/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# it under the terms of the GNU General Public License as published by
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
10-
1110
import warnings
1211
warnings.filterwarnings('ignore')
1312

@@ -25,6 +24,7 @@
2524
from typing import Any, Dict, Optional, List, Tuple
2625

2726

27+
2828
class NoValue(Enum):
2929
def __repr__(self):
3030
return '<%s.%s>' % (self.__class__.__name__, self.name)

wfcommons/wfchef/chef.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -193,59 +193,20 @@ def ls_recipe():
193193
print(get_recipes())
194194

195195

196-
def uninstall_recipe(wf_name: str,
196+
def uninstall_recipe(module_name:str,
197197
savedir: pathlib.Path = this_dir.joinpath("recipes")):
198198
"""
199199
Uninstalls a recipe installed in the system.
200200
"""
201201

202-
dst = pathlib.Path(savedir, f"{savedir.stem}_recipes", wf_name).resolve()
202+
dst = f"wfcommons.wfchef.recipe.{savedir.stem}"
203203
try:
204-
# Removing package from setup.py
205-
with this_dir.joinpath(dst.parent.parent.joinpath("setup.py")).open("r") as fp:
206-
setup_str = fp.read()
207-
208-
# Find and remove the specific line that added the package
209-
for line in setup_str.split("\n"):
210-
if wf_name in setup_str:
211-
setup_str = setup_str.replace(line, "")
212-
213-
with this_dir.joinpath(dst.parent.parent.joinpath("setup.py")).open("w") as fp:
214-
fp.write(setup_str)
215-
216-
# Removing the import line from __init__.py
217-
init_file = dst.parent.joinpath("__init__.py")
218-
if init_file.exists():
219-
with init_file.open("r") as fp:
220-
init_str = fp.read()
221-
222-
# Remove the line that imports the package
223-
224-
for line in init_str.split("\n"):
225-
if wf_name in line:
226-
init_str = init_str.replace(line, "")
227-
break
228-
229-
with init_file.open("w") as fp:
230-
fp.write(init_str)
231-
232-
# Removing the recipe directory
233-
if dst.exists():
234-
print(f"Removing {dst}")
235-
subprocess.Popen(["rm", "-rf", str(dst)]).wait()
236-
237-
# Find setup.py, clean it and reinstall it
238-
path_to_setup = this_dir.parent.parent.resolve()
239-
# Check if the setup.py is in the same directory
240-
if path_to_setup.joinpath("setup.py").exists():
241-
subprocess.Popen(["python", "setup.py", "clean", "-all"]).wait()
242-
subprocess.Popen(["python", "setup.py", "sdist", "bdist_wheel"]).wait()
243-
subprocess.Popen(["pip", "install", "."]).wait()
244-
subprocess.Popen(["pip", "cache", "purge"]).wait()
245-
204+
subprocess.run(["pip", "uninstall", "-y", dst])
205+
traceback.print_exc()
206+
246207
except Exception as e:
247208
traceback.print_exc()
248-
# print(f"Could not find recipe with module name {module_name} installed")
209+
print(f"Could not uninstall recipe for {module_name}")
249210

250211

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

wfcommons/wfgen/abstract_recipe.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ def _generate_task_files(self, task: Task) -> List[File]:
203203

204204
# generate output files
205205
output_files_list = self._generate_files(task.task_id, task_recipe['output'], FileLink.OUTPUT)
206-
task.files = self.tasks_files[task.task_id]
206+
task.output_files = self.tasks_files[task.task_id]
207+
208+
207209

208210
# obtain input files from parents
209211
input_files = []
212+
210213
if task.name in self.tasks_parents.keys():
211214
for parent_task_name in self.tasks_parents[task.name]:
212215
output_files = self._generate_task_files(self.tasks_map[parent_task_name])
@@ -215,14 +218,15 @@ def _generate_task_files(self, task: Task) -> List[File]:
215218
input_files.extend(output_files)
216219

217220
for input_file in input_files:
218-
if input_file.name not in self.tasks_files_names[task.task_id]:
219-
self.tasks_files[task.task_id].append(File(name=input_file.name,
220-
link=FileLink.INPUT,
221-
size=input_file.size))
222-
self.tasks_files_names[task.task_id].append(input_file.name)
221+
if input_file not in self.tasks_files_names[task.task_id]:
222+
self.tasks_files[task.task_id].append(File(name=input_file,
223+
link=FileLink.INPUT,
224+
size=input_file.size))
225+
self.tasks_files_names[task.task_id].append(input_file)
223226

224227
# generate additional input files
225228
self._generate_files(task.task_id, task_recipe['input'], FileLink.INPUT)
229+
task.input_files = [ifile for ifile in self.tasks_files[task.task_id] if ifile.link == FileLink.INPUT]
226230

227231
return output_files_list
228232

wfcommons/wfinstances/instance_analyzer.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import math
1313
import numpy
1414
import scipy.stats
15+
import warnings
1516

1617
from logging import Logger
1718
from matplotlib import pyplot
@@ -105,26 +106,29 @@ def build_summary(self,
105106
for task in self.tasks_summary[task_name]:
106107
runtime_list.append(task.runtime)
107108

108-
109109
# For each input_file and output_file, append the file size to the dictionary
110110
for infile in task.input_files:
111111
extension: str = path.splitext(infile.file_id)[1] if '.' in infile.file_id else infile.file_id
112+
# print(f"file {infile.file_id} extension: {extension}")
112113
if extension[1:].isnumeric():
113114
extension = path.splitext(infile.file_id.replace(extension, ''))[1]
114115

115116
# Check if the file is definetly an input
116117
assert infile.link == FileLink.INPUT, f"{infile.file_id} is not set as input"
117118
_append_file_to_dict(extension, inputs_dict, infile.size)
119+
118120

119121
for outfile in task.output_files:
120122
extension: str = path.splitext(outfile.file_id)[1] if '.' in outfile.file_id else outfile.file_id
123+
# print(f"file {outfile.file_id} extension: {extension}")
121124
if extension[1:].isnumeric():
122125
extension = path.splitext(outfile.file_id.replace(extension, ''))[1]
123126

124127
# Check if the file is definetly an output
125128
assert outfile.link == FileLink.OUTPUT, f"{outfile.file_id} is not set as output"
126129
_append_file_to_dict(extension, outputs_dict, outfile.size)
127130

131+
128132
# Find the best fit distribution for each file type
129133
_best_fit_distribution_for_file(inputs_dict, include_raw_data)
130134
_best_fit_distribution_for_file(outputs_dict, include_raw_data)
@@ -197,7 +201,6 @@ def _append_file_to_dict(extension: str, dict_obj: Dict[str, Any], file_size: in
197201
dict_obj[extension] = {'data': [], 'distribution': None}
198202
dict_obj[extension]['data'].append(file_size)
199203

200-
201204
def _best_fit_distribution_for_file(dict_obj, include_raw_data) -> None:
202205
"""
203206
Find the best fit distribution for a file.
@@ -207,14 +210,16 @@ def _best_fit_distribution_for_file(dict_obj, include_raw_data) -> None:
207210
:param include_raw_data:
208211
:type include_raw_data: bool
209212
"""
210-
for ext in dict_obj:
211-
dict_obj[ext]['min'] = min(dict_obj[ext]['data'])
212-
dict_obj[ext]['max'] = max(dict_obj[ext]['data'])
213-
if dict_obj[ext]['min'] != dict_obj[ext]['max']:
214-
dict_obj[ext]['distribution'] = _json_format_distribution_fit(
215-
best_fit_distribution(dict_obj[ext]['data']))
216-
if not include_raw_data:
217-
del dict_obj[ext]['data']
213+
with warnings.catch_warnings():
214+
warnings.simplefilter("ignore")
215+
for ext in dict_obj:
216+
dict_obj[ext]['min'] = min(dict_obj[ext]['data'])
217+
dict_obj[ext]['max'] = max(dict_obj[ext]['data'])
218+
if dict_obj[ext]['min'] != dict_obj[ext]['max']:
219+
dict_obj[ext]['distribution'] = _json_format_distribution_fit(
220+
best_fit_distribution(dict_obj[ext]['data']))
221+
if not include_raw_data:
222+
del dict_obj[ext]['data']
218223

219224

220225
def _json_format_distribution_fit(dist_tuple: Tuple) -> Dict[str, Any]:

0 commit comments

Comments
 (0)