Skip to content

Commit

Permalink
Validate WDLs using miniwdl (#385)
Browse files Browse the repository at this point in the history
* Implement WDL validation using miniwdl.

* Update scripts/test/miniwdl_validation.py

Co-authored-by: Mark Walker <[email protected]>

* Remove filtering the input for non-wdl files.

Co-authored-by: Mark Walker <[email protected]>
  • Loading branch information
VJalili and mwalker174 authored Aug 26, 2022
1 parent 4b86638 commit 3f269e8
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/test/miniwdl_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
This Script checks the provided WDL files with miniwdl for
syntax, validation, and import errors. See the following
page on the checks. Note that this script does not
check for "warning" or "suggestions"; you may use
`$ miniwdl check WDL_FILENAME` to get warnings and suggestions.
https://miniwdl.readthedocs.io/en/latest/WDL.html#module-WDL.Error
"""

import argparse
import sys
import WDL


def format_error_message(error_type, message, pos):
return f"{error_type}: '{message}' at {pos.abspath}, Line: {pos.line}, Col: {pos.column}"


def check(wdl_filename):
try:
WDL.load(wdl_filename)
return True
except WDL.Error.SyntaxError as e:
print(format_error_message("Syntax Error", e, e.pos))
except WDL.Error.ValidationError as e:
print(format_error_message("Validation Error", e, e.node.pos))
except WDL.Error.MultipleValidationErrors as e:
for ex in e.exceptions:
print(format_error_message("Validation Error", ex, ex.node.pos))
except WDL.Error.ImportError as e:
print(e)
print(format_error_message("Import Error", e, e.pos))
finally:
return False


def main():
parser = argparse.ArgumentParser()
parser.add_argument("files", nargs="+", help="The WDL files to be checked.")
args = parser.parse_args()

wdl_filenames = args.files

exit_code = 0
counter = 0
for wdl_filename in wdl_filenames:
if not check(wdl_filename):
exit_code = 1
counter += 1
print(f"{counter} of {len(wdl_filenames)} checked WDL files failed the miniwdl validation.")
sys.exit(exit_code)


if __name__ == "__main__":
main()

0 comments on commit 3f269e8

Please sign in to comment.