Skip to content

Commit

Permalink
add --ignore_validation_errors (#161)
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Fennick <jake.fennick@axleinfo.com>
  • Loading branch information
jfennick and jfennick authored Jan 31, 2024
1 parent f0211a7 commit 03cc6eb
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/wic/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def read_ast_from_disk(homedir: str,
yaml_tree_tuple: YamlTree,
yml_paths: Dict[str, Dict[str, Path]],
tools: Tools,
validator: Draft202012Validator) -> YamlTree:
validator: Draft202012Validator,
ignore_validation_errors: bool) -> YamlTree:
"""Reads the yml workflow definition files from disk (recursively) and inlines them into an AST
Args:
Expand All @@ -32,6 +33,7 @@ def read_ast_from_disk(homedir: str,
yml_paths (Dict[str, Dict[str, Path]]): The yml workflow definitions found using get_yml_paths()
tools (Tools): The CWL CommandLineTool definitions found using get_tools_cwl()
validator (Draft202012Validator): Used to validate the yml files against the autogenerated schema.
ignore_validation_errors (bool): Temporarily ignore validation errors. Do not use this permanently!
Raises:
Exception: If the yml file(s) do not exist
Expand All @@ -42,7 +44,8 @@ def read_ast_from_disk(homedir: str,
(step_id, yaml_tree) = yaml_tree_tuple

try:
validator.validate(yaml_tree)
if not ignore_validation_errors:
validator.validate(yaml_tree)
except Exception as e:
yaml_path = Path(step_id.stem)
print('Failed to validate', yaml_path)
Expand All @@ -64,7 +67,8 @@ def read_ast_from_disk(homedir: str,
for back_name, back in wic['wic']['backends'].items():
plugin_ns = wic['wic'].get('namespace', 'global')
stepid = StepId(back_name, plugin_ns)
backends_tree = read_ast_from_disk(homedir, YamlTree(stepid, back), yml_paths, tools, validator)
backends_tree = read_ast_from_disk(homedir, YamlTree(stepid, back), yml_paths, tools, validator,
ignore_validation_errors)
backends_trees.append(backends_tree)
yaml_tree['wic']['backends'] = dict(backends_trees)
return YamlTree(step_id, yaml_tree)
Expand Down Expand Up @@ -109,7 +113,8 @@ def read_ast_from_disk(homedir: str,
sub_yaml_tree_raw: Yaml = yaml.safe_load(y.read())

y_t = YamlTree(StepId(step_key, plugin_ns), sub_yaml_tree_raw)
(step_id_, sub_yml_tree) = read_ast_from_disk(homedir, y_t, yml_paths, tools, validator)
(step_id_, sub_yml_tree) = read_ast_from_disk(homedir, y_t, yml_paths, tools, validator,
ignore_validation_errors)

step_i_dict = {} if steps[i][step_key] is None else steps[i][step_key]
# Do not merge these two dicts; use subtree and parentargs so we can
Expand Down
2 changes: 2 additions & 0 deletions src/wic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
help='Enables the use of naming conventions in the inference algorithm')
parser.add_argument('--validate_plugins', default=False, action="store_true",
help='Validate all CWL CommandLineTools')
parser.add_argument('--ignore_validation_errors', default=False, action="store_true",
help='Temporarily ignore validation errors. Do not use this permanently!')
parser.add_argument('--no_skip_dollar_schemas', default=False, action="store_true",
help='''Does not skip processing $schemas tags in CWL files for performance.
Skipping significantly improves initial validation performance, but is not always desired.
Expand Down
2 changes: 1 addition & 1 deletion src/wic/cwl_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def rerun_cwltool(homedir: str, _directory_realtime: Path, cachedir_path: Path,
plugin_ns = 'global' # wic['wic'].get('namespace', 'global')
step_id = StepId(yaml_path, plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = ast.read_ast_from_disk(homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = ast.read_ast_from_disk(homedir, y_t, yml_paths, tools_cwl, validator, True)
yaml_tree = ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)
yml = yaml_tree.yml
else:
Expand Down
6 changes: 4 additions & 2 deletions src/wic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def main() -> None:

for yml_path_str, yml_path in yml_paths_tuples:
schema = wic_schema.compile_workflow_generate_schema(args.homedir, yml_path_str, yml_path,
tools_cwl, yml_paths, validator)
tools_cwl, yml_paths, validator,
args.ignore_validation_errors)
# overwrite placeholders in schema_store. See comment in get_validator()
schema_store[schema['$id']] = schema

Expand All @@ -69,7 +70,8 @@ def main() -> None:
plugin_ns = wic['wic'].get('namespace', 'global')
step_id = StepId(yaml_path, plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator,
args.ignore_validation_errors)
# Write the combined workflow (with all subworkflows as children) to disk.
with open(f'autogenerated/{Path(yaml_path).stem}_tree_raw.yml', mode='w', encoding='utf-8') as f:
f.write(yaml.dump(yaml_tree_raw.yml))
Expand Down
7 changes: 5 additions & 2 deletions src/wic/schemas/wic_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ def compile_workflow_generate_schema(homedir: str,
yml_path_str: str, yml_path: Path,
tools_cwl: Tools,
yml_paths: Dict[str, Dict[str, Path]],
validator: Draft202012Validator) -> Json:
validator: Draft202012Validator,
ignore_validation_errors: bool) -> Json:
"""Compiles a workflow and generates a schema which (recursively) includes the inputs/outputs from subworkflows.
Args:
Expand All @@ -506,6 +507,7 @@ def compile_workflow_generate_schema(homedir: str,
tools_cwl (Tools): The CWL CommandLineTool definitions found using get_tools_cwl()
yml_paths (Dict[str, Dict[str, Path]]): The yml workflow definitions found using get_yml_paths()
validator (Draft202012Validator): Used to validate the yml files against the autogenerated schema.
ignore_validation_errors (bool): Temporarily ignore validation errors. Do not use this permanently!
Returns:
Json: An autogenerated, documented schema based on the inputs and outputs of the Workflow.
Expand All @@ -519,7 +521,8 @@ def compile_workflow_generate_schema(homedir: str,
plugin_ns = wic_tag['wic'].get('namespace', 'global')
step_id = StepId(yml_path_str, plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = wic.ast.read_ast_from_disk(homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = wic.ast.read_ast_from_disk(homedir, y_t, yml_paths, tools_cwl, validator,
ignore_validation_errors)
# with open(f'autogenerated/{Path(yml_path).stem}_tree_raw.yml', mode='w', encoding='utf-8') as f:
# f.write(yaml.dump(yaml_tree_raw.yml))
yaml_tree = wic.ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def run_workflows(yml_path_str: str, yml_path: Path, cwl_runner: str, args: argp
plugin_ns = wic_tag['wic'].get('namespace', 'global')
step_id = StepId(yml_path_str, plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator,
args.ignore_validation_errors)
with open(f'autogenerated/{Path(yml_path).stem}_tree_raw.yml', mode='w', encoding='utf-8') as f:
f.write(yaml.dump(yaml_tree_raw.yml))
yaml_tree = wic.ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)
Expand Down Expand Up @@ -212,7 +213,8 @@ def test_cwl_embedding_independence(yml_path_str: str, yml_path: Path) -> None:
plugin_ns = wic_tag['wic'].get('namespace', 'global')
step_id = StepId(yml_path_str + '.yml', plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator,
args.ignore_validation_errors)
with open(f'autogenerated/{yml_path.stem}_tree_raw.yml', mode='w', encoding='utf-8') as f:
f.write(yaml.dump(yaml_tree_raw.yml))
yaml_tree = wic.ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)
Expand Down Expand Up @@ -310,7 +312,8 @@ def test_inline_subworkflows(yml_path_str: str, yml_path: Path) -> None:
plugin_ns = wic_tag['wic'].get('namespace', 'global')
step_id = StepId(yml_path_str, plugin_ns)
y_t = YamlTree(step_id, root_yaml_tree)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator,
args.ignore_validation_errors)
with open(f'autogenerated/{Path(yml_path).stem}_tree_raw.yml', mode='w', encoding='utf-8') as f:
f.write(yaml.dump(yaml_tree_raw.yml))
yaml_tree = wic.ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fuzzy_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_fuzzy_compile(self, yml: Yaml) -> None:
args = get_args(str(yml_path))

y_t = YamlTree(StepId('random_stepid', plugin_ns), yml)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator)
yaml_tree_raw = wic.ast.read_ast_from_disk(args.homedir, y_t, yml_paths, tools_cwl, validator,
args.ignore_validation_errors)
yaml_tree = wic.ast.merge_yml_trees(yaml_tree_raw, {}, tools_cwl)

graph_gv = graphviz.Digraph(name=f'cluster_{yml_path}')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def get_args(yaml_path: str = '', cwl_inline_subworkflows: bool = False) -> argp

for yml_path_str, yml_path in yml_paths_tuples:
schema = wic.schemas.wic_schema.compile_workflow_generate_schema(args.homedir, yml_path_str, yml_path,
tools_cwl, yml_paths, validator)
tools_cwl, yml_paths, validator,
args.ignore_validation_errors)
# overwrite placeholders in schema_store. See comment in get_validator()
schema_store[schema['$id']] = schema

Expand Down

0 comments on commit 03cc6eb

Please sign in to comment.