Skip to content

Commit 6784304

Browse files
Changes some files to be in compliance with wfformat v5
1 parent 34a134d commit 6784304

5 files changed

Lines changed: 56 additions & 23 deletions

File tree

wfcommons/common/task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Task:
6969

7070
def __init__(self,
7171
name: str,
72-
task_type: TaskType,
72+
# task_type: TaskType,
7373
runtime: float,
7474
cores: float = 1.0,
7575
task_id: Optional[str] = None,
@@ -93,7 +93,7 @@ def __init__(self,
9393
self.logger: Logger = logging.getLogger(
9494
__name__) if logger is None else logger
9595
self.name: str = name
96-
self.type: TaskType = task_type
96+
# self.type: TaskType = task_type
9797
self.runtime: float = runtime
9898
self.cores: Optional[float] = cores
9999
self.task_id: Optional[str] = task_id
@@ -112,7 +112,7 @@ def __init__(self,
112112
self.launch_dir: Optional[str] = launch_dir
113113
self.start_time: Optional[str] = str(datetime.now().astimezone().isoformat()) if not start_time else start_time
114114
self.logger.debug(
115-
f"created {self.type} task {self.name}: runtime => {self.runtime} seconds.")
115+
f"created {self.task_id} task {self.name}: runtime => {self.runtime} seconds.")
116116

117117
def as_dict(self) -> Dict:
118118
"""A JSON representation of the task.

wfcommons/wfchef/chef.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,50 @@ def ls_recipe():
193193
print(get_recipes())
194194

195195

196-
def uninstall_recipe(module_name: str):
196+
def uninstall_recipe(wf_name: str,
197+
savedir: pathlib.Path = this_dir.joinpath("recipes")):
197198
"""
198199
Uninstalls a recipe installed in the system.
199200
"""
200201

201-
for entry_point in pkg_resources.iter_entry_points('workflow_recipes'):
202-
if entry_point.module_name == module_name:
203-
print(f"Uninstalling package: wfchef.recipe.{module_name}")
204-
proc = subprocess.Popen(["pip", "uninstall", f"wfchef.recipe.{module_name}"])
205-
proc.wait()
206-
return
207-
208-
print(f"Could not find recipe with module name {module_name} installed")
202+
dst = pathlib.Path(savedir, f"{savedir.stem}_recipes", wf_name).resolve()
203+
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+
# for entry_point in pkg_resources.iter_entry_points('workflow_recipes'):
232+
# if entry_point.module_name == module_name:
233+
# print(f"Uninstalling package: {module_name}")
234+
# proc = subprocess.Popen(["pip", "uninstall", module_name])
235+
# proc.wait()
236+
# return
237+
except Exception as e:
238+
traceback.print_exc()
239+
# print(f"Could not find recipe with module name {module_name} installed")
209240

210241

211242
def create_recipe(path_to_instances: Union[str, pathlib.Path],
@@ -300,7 +331,9 @@ def get_parser() -> argparse.ArgumentParser:
300331

301332
uninstall_parser = subparsers.add_parser("uninstall")
302333
uninstall_parser.set_defaults(action=uninstall_recipe)
303-
uninstall_parser.add_argument("module_name", help="name of recipe module to uninstall")
334+
# uninstall_parser.add_argument("module_name", help="name of recipe module to uninstall")
335+
uninstall_parser.add_argument("-n", "--name", help="name of the workflow to uninstall")
336+
uninstall_parser.add_argument("-o", "--out", help="directory where the recipe is located")
304337

305338
create_parser = subparsers.add_parser("create")
306339
create_parser.set_defaults(action=create_recipe)
@@ -352,7 +385,7 @@ def main():
352385
if args.action == ls_recipe:
353386
ls_recipe()
354387
elif args.action == uninstall_recipe:
355-
uninstall_recipe(args.module_name)
388+
uninstall_recipe(args.name, pathlib.Path(args.out))
356389
elif args.action == create_recipe:
357390
create_recipe(args.path, args.out, args.name, cutoff=args.cutoff, verbose=True)
358391

wfcommons/wfchef/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_graph(path: pathlib.Path) -> nx.DiGraph:
5656

5757
id_count = 0
5858

59-
for task in content["workflow"]["tasks"]:
59+
for task in content["workflow"]["specification"]["tasks"]:
6060

6161
# specific for epigenomics -- have to think about how to do it in general
6262
if "genome-dax" in content["name"]:

wfcommons/wfinstances/instance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, input_instance: pathlib.Path,
7676

7777
# WMS properties
7878
self.wms: Dict[str, str] = {
79-
u: v for u, v in self.instance['wms'].items()
79+
u: v for u, v in self.instance['runtimeSystem'].items()
8080
}
8181

8282
# Author properties
@@ -87,8 +87,8 @@ def __init__(self, input_instance: pathlib.Path,
8787
# Workflow properties
8888
# Global properties
8989
self.executed_at: datetime = dateutil.parser.parse(
90-
self.instance['workflow']['executedAt'])
91-
self.makespan: int = self.instance['workflow']['makespanInSeconds']
90+
self.instance['workflow']['execution']['executedAt'])
91+
self.makespan: int = self.instance['workflow']['execution']['makespanInSeconds']
9292

9393
# Machines
9494
if 'machines' in self.instance['workflow'].keys():
@@ -109,7 +109,7 @@ def __init__(self, input_instance: pathlib.Path,
109109
# Tasks
110110
self.workflow: Workflow = Workflow(
111111
name=self.name, makespan=self.makespan)
112-
for task in self.instance["workflow"]["tasks"]:
112+
for task in self.instance["workflow"]['specification']["tasks"]:
113113
# Required arguments are defined in the JSON scheme
114114
# Here name, type and runtime are required
115115
# By default the value is set to None if we do not find the value
@@ -135,7 +135,7 @@ def __init__(self, input_instance: pathlib.Path,
135135
name=task['name'],
136136
task_id=task.get('id', None),
137137
category=task.get('category', None),
138-
task_type=TaskType(task['type']),
138+
# task_type=TaskType(task['type']),
139139
runtime=task['runtimeInSeconds'] if 'runtimeInSeconds' in task else 0,
140140
machine=machine,
141141
program=command.get('program', None) if command else None,
@@ -153,7 +153,7 @@ def __init__(self, input_instance: pathlib.Path,
153153
)
154154
)
155155
# TODO: handle the case of the output files of the leaves tasks (not taken into account yet)
156-
for task in self.instance["workflow"]["tasks"]:
156+
for task in self.instance["workflow"]["specification"]["tasks"]:
157157
for parent in task['parents']:
158158
self.workflow.add_dependency(parent, task['name'])
159159

wfcommons/wfinstances/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def _semantic_validation(self, data: Dict[str, Any]):
113113
self.logger.debug('Skipping machines processing.')
114114

115115
tasks_ids = []
116-
for j in data["workflow"]["tasks"]:
116+
for j in data["workflow"]["specification"]["tasks"]:
117117
tasks_ids.append(j['name'])
118118
if 'machine' in j and j['machine'] not in machine_ids:
119119
self.logger.error(f"Machine \"{j['machine']}\" is not declared in the list of machines.")
120120
has_error = True
121121

122122
# since tasks may be declared out of order, their dependencies are only verified here
123-
for j in data["workflow"]["tasks"]:
123+
for j in data["workflow"]["specification"]["tasks"]:
124124
for p in j['parents']:
125125
if p not in tasks_ids:
126126
self.logger.error(f"Parent task \"{p['parentId']}\" is not declared in the list of workflow tasks.")

0 commit comments

Comments
 (0)