Skip to content

Commit 6aa8bb3

Browse files
committed
Update check.py to check formatting, etc
1 parent c54ffcb commit 6aa8bb3

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ you want to run it locally, you'll need the
1616
pip3 install jsonschema
1717
```
1818

19+
You can use a Python virtual environment if you are unable to or don't want to
20+
install jsonschema globally. See <https://docs.python.org/3/tutorial/venv.html>
21+
for instructions.
22+
1923
The website is hosted as a GitHub static page at <https://raft.github.io>. To
2024
run it locally, make sure you've checked out all the submodules:
2125
```

check.py

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
11
#!/usr/bin/env python3
22

3+
import difflib
34
import json
45
import jsonschema
6+
import sys
57

68
schema = json.load(open('implementation.schema.json'))
79

10+
errors = []
811
raw_data = open('implementations.json').read()
9-
if not raw_data.endswith(']\n'):
10-
raise ValueError('implementations.json should end in one \\n')
1112
data = json.loads(raw_data)
1213

1314
for impl in data:
14-
jsonschema.validate(impl, schema)
15+
try:
16+
jsonschema.validate(impl, schema)
17+
except jsonschema.exceptions.ValidationError as e:
18+
errors.append(e)
1519

1620
sorted_data = sorted(data, key=lambda impl: impl['repoURL'])
1721
for expected, actual in zip(sorted_data, data):
1822
if expected['repoURL'] != actual['repoURL']:
19-
print('Expected:', expected['repoURL'])
20-
print('Found: ', actual['repoURL'])
21-
raise ValueError('Implementations should be sorted by repoURL')
23+
errors.append(ValueError(
24+
'Implementations should be sorted by repoURL.\n' +
25+
f"Expected: {expected['repoURL']}\n" +
26+
f"Found: {actual['repoURL']}"))
27+
break
28+
29+
diff = ''.join(difflib.unified_diff(
30+
raw_data.splitlines(keepends=True),
31+
(json.dumps(data, indent=4) + '\n').splitlines(keepends=True),
32+
fromfile='implementations.json (current)',
33+
tofile='implementations.json (expected formatting)'))
34+
if diff != '':
35+
errors.append(ValueError('Formatting error:\n' + diff))
36+
37+
# Saving the file without a trailing newline is a common error. It's already
38+
# caught by difflib above, but this error message is clearer.
39+
if not raw_data.endswith(']\n'):
40+
errors.append(ValueError('implementations.json should end in one \\n'))
2241

42+
if errors:
43+
print(f'Encountered {len(errors)} errors:')
44+
for error in errors:
45+
print()
46+
print(error)
47+
sys.exit(1)

implementations.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"logCompaction": false
134134
}
135135
},
136-
{
136+
{
137137
"repoURL": "https://github.com/RedisLabs/redisraft",
138138
"name": "RedisRaft",
139139
"authors": [
@@ -1850,7 +1850,7 @@
18501850
"persistence": true
18511851
}
18521852
},
1853-
{
1853+
{
18541854
"repoURL": "https://github.com/scaars10/pecan-raft",
18551855
"name": "PecanRaft",
18561856
"authors": [

0 commit comments

Comments
 (0)