Merge pull request #28 from pre-commit/use_c_loader

Use the CLoader when present to validate yaml
This commit is contained in:
Anthony Sottile 2015-01-15 10:49:28 -08:00
commit fea9b2ece7
3 changed files with 8 additions and 3 deletions

View file

@ -5,7 +5,6 @@ env: # These should match the tox env list
- TOXENV=py33
- TOXENV=py34
- TOXENV=pypy
- TOXENV=pypy3
install: pip install coveralls tox --use-mirrors
script: tox
# Special snowflake. Our tests depend on making real commits.

View file

@ -6,6 +6,12 @@ import sys
import yaml
try:
from yaml.cyaml import CLoader as Loader
except ImportError: # pragma: no cover (no libyaml-dev / pypy)
Loader = yaml.Loader
def check_yaml(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Yaml filenames to check.')
@ -14,7 +20,7 @@ def check_yaml(argv=None):
retval = 0
for filename in args.filenames:
try:
yaml.load(open(filename))
yaml.load(open(filename), Loader=Loader)
except yaml.YAMLError as exc:
print(exc)
retval = 1

View file

@ -1,7 +1,7 @@
[tox]
project = pre_commit_hooks
# These should match the travis env list
envlist = py26,py27,py33,py34,pypy,pypy3
envlist = py26,py27,py33,py34,pypy
[testenv]
install_command = pip install --use-wheel {opts} {packages}