Style fixups

This commit is contained in:
Anthony Sottile 2016-04-14 08:25:52 -07:00
parent ea867c2e68
commit 17478a0a50
3 changed files with 14 additions and 12 deletions

View File

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

View File

@ -9,8 +9,10 @@ import simplejson
def _get_pretty_format(contents, indent, sort_keys=True):
return simplejson.dumps(
simplejson.loads(contents,
object_pairs_hook=None if sort_keys else OrderedDict),
simplejson.loads(
contents,
object_pairs_hook=None if sort_keys else OrderedDict,
),
sort_keys=sort_keys,
indent=indent
) + "\n" # dumps don't end with a newline
@ -28,20 +30,20 @@ def pretty_format_json(argv=None):
'--autofix',
action='store_true',
dest='autofix',
help='Automatically fixes encountered not-pretty-formatted files'
help='Automatically fixes encountered not-pretty-formatted files',
)
parser.add_argument(
'--indent',
type=int,
default=2,
help='Number of indent spaces used to pretty-format files'
help='Number of indent spaces used to pretty-format files',
)
parser.add_argument(
'--no-sort-keys',
action='store_true',
dest='no_sort_keys',
default=False,
help='Keep JSON nodes in the same order'
help='Keep JSON nodes in the same order',
)
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
@ -50,12 +52,13 @@ def pretty_format_json(argv=None):
status = 0
for json_file in args.filenames:
try:
f = open(json_file, 'r')
with open(json_file) as f:
contents = f.read()
f.close()
pretty_contents = _get_pretty_format(contents, args.indent, (not args.no_sort_keys))
try:
pretty_contents = _get_pretty_format(
contents, args.indent, sort_keys=not args.no_sort_keys,
)
if contents != pretty_contents:
print("File {0} is not pretty-formatted".format(json_file))

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 = py27,py33,py34,pypy,pypy3
[testenv]
deps = -rrequirements-dev.txt