|
4 | 4 | requirements.""" |
5 | 5 |
|
6 | 6 | import argparse |
| 7 | +import json |
7 | 8 | import os |
8 | 9 | import plistlib |
9 | 10 | import sys |
10 | 11 | from contextlib import contextmanager |
11 | 12 | from distutils.version import LooseVersion |
12 | 13 | from xml.parsers.expat import ExpatError |
13 | 14 |
|
| 15 | +from ruamel import yaml |
| 16 | + |
14 | 17 | from pre_commit_hooks.util import ( |
15 | 18 | validate_pkginfo_key_types, |
16 | 19 | validate_required_keys, |
@@ -482,17 +485,40 @@ def main(argv=None): |
482 | 485 |
|
483 | 486 | retval = 0 |
484 | 487 | for filename in args.filenames: |
485 | | - try: |
486 | | - with open(filename, "rb") as openfile: |
487 | | - recipe = plistlib.load(openfile) |
488 | | - # For future implementation of validate_unused_input_vars() |
489 | | - # with open(filename, "r") as openfile: |
490 | | - # recipe_text = openfile.read() |
491 | | - |
492 | | - except (ExpatError, ValueError) as err: |
493 | | - print("{}: plist parsing error: {}".format(filename, err)) |
494 | | - retval = 1 |
495 | | - break # No need to continue checking this file |
| 488 | + |
| 489 | + if filename.endswith(".yaml"): |
| 490 | + try: |
| 491 | + # try to read it as yaml |
| 492 | + with open(filename, "rb") as f: |
| 493 | + recipe = yaml.safe_load(f) |
| 494 | + except Exception as err: |
| 495 | + print("{}: yaml parsing error: {}".format(filename, err)) |
| 496 | + retval = 1 |
| 497 | + break # No need to continue checking this file |
| 498 | + |
| 499 | + elif filename.endswith(".json"): |
| 500 | + try: |
| 501 | + # try to read it as json |
| 502 | + with open(filename, "rb") as f: |
| 503 | + recipe = json.load(f) |
| 504 | + except Exception as err: |
| 505 | + print("{}: json parsing error: {}".format(filename, err)) |
| 506 | + retval = 1 |
| 507 | + break # No need to continue checking this file |
| 508 | + |
| 509 | + else: |
| 510 | + try: |
| 511 | + # try to read it as a plist |
| 512 | + with open(filename, "rb") as f: |
| 513 | + recipe = plistlib.load(f) |
| 514 | + except Exception as err: |
| 515 | + print("{}: plist parsing error: {}".format(filename, err)) |
| 516 | + retval = 1 |
| 517 | + break # No need to continue checking this file |
| 518 | + |
| 519 | + # For future implementation of validate_unused_input_vars() |
| 520 | + # with open(filename, "r") as openfile: |
| 521 | + # recipe_text = openfile.read() |
496 | 522 |
|
497 | 523 | # Top level keys that all AutoPkg recipes should contain. |
498 | 524 | required_keys = ["Identifier"] |
|
0 commit comments