Skip to content

Commit a21e8d5

Browse files
author
Joseph Damiba
committed
refactoring check order script to check all display_as categories at once
1 parent 128fe00 commit a21e8d5

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

check-order.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,43 @@
22
from pathlib import Path, PosixPath
33
import sys
44

5-
try:
6-
category = str(sys.argv[2])
7-
except:
8-
raise Exception("You need to specify a display_as category!")
9-
5+
categories = ["file_settings", "basic", "statistical", "scientific", "maps", "3d_charts", "multiple_axes"]
106
try:
117
path = str(sys.argv[1])
128
except:
139
raise Exception("You need to specify a path!")
1410

15-
# will contain all posts with display_as: file_settings
16-
postFamily = []
17-
18-
#get all posts with frontmatter in md format
19-
for md_path in Path(path).glob("**/*.md"):
20-
post = frontmatter.load(str(md_path))
21-
if len(post.metadata.keys()) > 0:
22-
if "display_as" in post.metadata['jupyter']['plotly']:
23-
if post.metadata['jupyter']['plotly']['display_as'] == category:
24-
postFamily.append({'path':str(md_path), 'order' : post.metadata['jupyter']['plotly']['order']})
25-
26-
sortedPostFamily = sorted(postFamily, key = lambda i: i['order'])
11+
for category in categories:
12+
postFamily = []
13+
#get all posts with frontmatter in md format
14+
for md_path in Path(path).glob("**/*.md"):
15+
post = frontmatter.load(str(md_path))
16+
if len(post.metadata.keys()) > 0:
17+
if "display_as" in post.metadata['jupyter']['plotly']:
18+
if post.metadata['jupyter']['plotly']['display_as'] == category:
19+
postFamily.append({'path':str(md_path), 'order' : post.metadata['jupyter']['plotly']['order']})
20+
21+
sortedPostFamily = sorted(postFamily, key = lambda i: i['order'])
2722

28-
order = []
23+
order = []
2924

30-
for post in sortedPostFamily:
31-
if post['order'] == 5:
32-
raise Exception("Order Check Failed! Post {} cannot have order 5!".format(post['path']))
33-
order.append(post['order'])
25+
for post in sortedPostFamily:
26+
if post['order'] == 5:
27+
raise Exception("Order Check Failed! Post {} cannot have order 5!".format(post['path']))
28+
order.append(post['order'])
3429

35-
if order[0] != 1:
36-
raise Exception("Order Check Failed! First post does not have order 1!")
30+
print(order)
3731

38-
def checkConsecutive(l):
39-
return sorted(l) == list(range(min(l), max(l)+1))
32+
if order[0] != 1:
33+
raise Exception("Order Check Failed! First post does not have order 1!")
4034

41-
print(order)
35+
def checkConsecutive(l):
36+
return sorted(l) == list(range(min(l), max(l)+1))
4237

43-
try:
44-
checkConsecutive(order)
45-
except:
46-
raise Exception("Order Check Failed! Orders are not consecutive integers!!")
38+
try:
39+
checkConsecutive(order)
40+
except:
41+
raise Exception("Order Check Failed! Orders are not consecutive integers!!")
4742

48-
print("Order Checks Passed!")
43+
print("Order Checks Passed!")
44+
order = []

0 commit comments

Comments
 (0)