-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
4b86638
commit 3f269e8
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |