def get_workflow(project_root: Path, wdl_file: Union[str, Path], workflow_name: Optional[str] = None) -> Tuple[Path, str]: """ Resolve the WDL file and workflow name. TODO: if `workflow_name` is None, parse the WDL file and extract the name of the workflow. Args: project_root: The root directory to which `wdl_file` might be relative. wdl_file: Path to the WDL file. workflow_name: The workflow name; if None, the filename without ".wdl" extension is used. Returns: A tuple (wdl_path, workflow_name) """ wdl_path = ensure_path(wdl_file, project_root, canonicalize=True) if not wdl_path.exists(): raise FileNotFoundError(f"WDL file not found at path {wdl_path}") if not workflow_name: workflow_name = safe_string(wdl_path.stem) return wdl_path, workflow_name
def get_target_name(wdl_path: Optional[Path] = None, wdl_doc: Optional[Document] = None, task_name: Optional[str] = None, workflow_name: Optional[str] = None, **kwargs) -> Tuple[str, bool]: """ Get the execution target. The order of priority is: - task_name - workflow_name - wdl_doc.workflow.name - wdl_doc.task[0].name - wdl_file.stem Args: wdl_path: Path to a WDL file wdl_doc: A miniwdl-parsed WDL document task_name: The task name workflow_name: The workflow name **kwargs: Additional keyword arguments to pass to `parse_wdl` Returns: A tuple (target, is_task), where `is_task` is a boolean indicating whether the target is a task (True) or a workflow (False). Raises: ValueError if 1) neither `task_name` nor `workflow_name` is specified and the WDL document contains no workflow and multiple tasks; or 2) all of the parameters are None. """ if task_name: return task_name, True if workflow_name: return workflow_name, False if not wdl_doc and Tree: wdl_doc = parse_wdl(wdl_path, **kwargs) if wdl_doc: if wdl_doc.workflow: return wdl_doc.workflow.name, False elif wdl_doc.tasks and len(wdl_doc.tasks) == 1: return wdl_doc.tasks[0].name, True else: raise ValueError( "WDL document has no workflow and multiple tasks, and 'task_name' " "is not specified") if wdl_path: return safe_string(wdl_path.stem), False raise ValueError("At least one parameter must not be None")
def _get_workflow_name(self, wdl_path: Path, kwargs: dict): if "workflow_name" in kwargs: return kwargs["workflow_name"] elif Tree: if "check_quant" not in kwargs: kwargs["check_quant"] = False doc = Tree.load(str(wdl_path), path=[str(path) for path in self.import_dirs], **kwargs) return doc.workflow.name else: # TODO: test this return safe_string(wdl_path.stem)
def test_safe_string(): assert safe_string("a+b*c") == "a_b_c"