4
4
5
5
# 'path' == '_posts' in 'documentation'
6
6
# 'path' == 'build/html' in 'py-docs'
7
- # 'path' == 'r ' in 'r-docs'
7
+ # 'path' == 'build ' in 'r-docs'
8
8
try :
9
9
path = str (sys .argv [1 ])
10
10
except :
11
- raise Exception ("You need to specify a path that contains the files with front matter." )
11
+ raise Exception (
12
+ "You need to specify a path that contains the files with front matter."
13
+ )
12
14
13
15
14
- def postsWithNoName (meta_to_check ):
16
+ def check_postsWithNoName (meta_to_check ):
15
17
failures = []
16
18
for meta in meta_to_check :
17
19
# Check #1 - do all non-redirect posts have names?
18
20
if "name" not in meta and "redirect_to" not in meta :
19
- failures .append (post .metadata [' permalink' ])
20
- return failures
21
+ failures .append (post .metadata [" permalink" ])
22
+ return "do all non-redirect posts have names?" , failures
21
23
22
- def postsWithTitle (meta_to_check ):
24
+
25
+ def check_postsWithTitle (meta_to_check ):
23
26
failures = []
24
27
for meta in meta_to_check :
25
28
# Check #2 - do any posts have titles?
26
29
if "title" in meta :
27
- failures .append (post .metadata ['permalink' ])
28
- return failures
30
+ failures .append (post .metadata ["permalink" ])
31
+ return "do any posts have titles?" , failures
32
+
29
33
30
- def duplicatePermalinks (meta_to_check ):
34
+ def check_duplicatePermalinks (meta_to_check ):
31
35
failures = []
32
36
allPermalinks = []
33
37
for meta in meta_to_check :
34
38
# Check #3 - are there duplicate permalinks/redirect_froms?
35
- if "permalink" in meta and meta ['permalink' ] != '//plot.ly/products/dash/' :
36
- if meta ['permalink' ] in allPermalinks :
37
- print (meta ['permalink' ])
38
- failures .append (meta ['permalink' ])
39
+ if "permalink" in meta and meta ["permalink" ] != "//plot.ly/products/dash/" :
40
+ if meta ["permalink" ] in allPermalinks :
41
+ failures .append (meta ["permalink" ])
39
42
else :
40
- allPermalinks .append (meta [' permalink' ])
43
+ allPermalinks .append (meta [" permalink" ])
41
44
if "redirect_from" in meta :
42
- if meta [' redirect_from' ] in allPermalinks :
43
- failures .append (meta [' redirect_from' ])
45
+ if meta [" redirect_from" ] in allPermalinks :
46
+ failures .append (meta [" redirect_from" ])
44
47
else :
45
- allPermalinks .append (meta [' redirect_from' ])
46
- return failures
48
+ allPermalinks .append (meta [" redirect_from" ])
49
+ return "are there posts with order > 5 and 'page_type: example_index'?" , failures
47
50
48
51
49
- def indexOverflow (meta_to_check ):
52
+ def check_indexOverflow (meta_to_check ):
50
53
failures = []
51
54
for meta in meta_to_check :
52
55
# Check #4 - are there posts with order > 5 and 'page_type: example_index'?
53
- if "display_as" in meta and meta ['display_as' ] in categories :
54
- if "language" in meta and meta ['language' ] in languages :
55
- if "order" in meta and meta ['order' ] > 5 :
56
- if "page_type" in meta and meta ['page_type' ] == "example_index" :
57
- failures .append (meta ['permalink' ])
58
- return failures
59
-
60
- def postsWithNoThumbnail (meta_to_check ):
56
+ if "display_as" in meta and meta ["display_as" ] in categories :
57
+ if "language" in meta and meta ["language" ] in languages :
58
+ if "order" in meta and meta ["order" ] > 5 :
59
+ if "page_type" in meta and meta ["page_type" ] == "example_index" :
60
+ failures .append (meta ["permalink" ])
61
+ return "are there duplicate permalinks/redirect_froms?" , failures
62
+
63
+
64
+ def check_postsWithNoThumbnail (meta_to_check ):
61
65
failures = []
62
66
for meta in meta_to_check :
63
67
# Check #5 - does every post have a thumbnail?
64
68
if "thumbnail" not in meta :
65
- if "display_as" in meta and meta ['display_as' ] in categories :
66
- if "language" in meta and meta ['language' ] in languages :
67
- failures .append (meta ['permalink' ])
68
- return failures
69
+ if "display_as" in meta and meta ["display_as" ] in categories :
70
+ if "language" in meta and meta ["language" ] in languages :
71
+ failures .append (meta ["permalink" ])
72
+ return "does every post have a thumbnail?" , failures
73
+
69
74
70
- def noTrailingSlash (meta_to_check ):
75
+ def check_noTrailingSlash (meta_to_check ):
71
76
failures = []
72
77
for meta in meta_to_check :
73
78
# Check #6 - do any permalinks not end with a trailing slash?
74
79
if "permalink" in meta :
75
- if meta ['permalink' ][- 1 ] != "/" :
76
- failures .append (meta ['permalink' ])
77
- return failures
78
-
79
- checks = {
80
- "do all non-redirect posts have names?" : postsWithNoName ,
81
- "do any posts have titles?" : postsWithTitle ,
82
- "are there posts with order > 5 and 'page_type: example_index'?" : indexOverflow ,
83
- "are there duplicate permalinks/redirect_froms?" : duplicatePermalinks ,
84
- "does every post have a thumbnail?" : postsWithNoThumbnail ,
85
- "do any permalinks not end with a trailing slash?" : noTrailingSlash ,
86
- }
87
-
88
- categories = ["file_settings" , "basic" , "financial" , "statistical" , "scientific" , "maps" , "3d_charts" , "multiple_axes" ]
80
+ if meta ["permalink" ][- 1 ] != "/" :
81
+ failures .append (meta ["permalink" ])
82
+ return "do any permalinks not end with a trailing slash?" , failures
83
+
84
+
85
+ categories = [
86
+ "file_settings" ,
87
+ "basic" ,
88
+ "financial" ,
89
+ "statistical" ,
90
+ "scientific" ,
91
+ "maps" ,
92
+ "3d_charts" ,
93
+ "multiple_axes" ,
94
+ ]
89
95
languages = ["python" , "python/v3" , "plotly_js" , "r" ]
90
96
91
97
paths = []
92
98
if path == "r" :
93
99
for suffix in ["Rmd" ]:
94
- paths += [x for x in Path (path ).glob ("*." + suffix )]
100
+ paths += [x for x in Path (path ).glob ("*." + suffix )]
95
101
else :
96
102
# collect all paths
97
103
for suffix in ["md" , "html" ]:
98
- paths += [x for x in Path (path ).glob ("**/*." + suffix )]
104
+ paths += [x for x in Path (path ).glob ("**/*." + suffix )]
99
105
100
106
# collect all posts
101
107
meta_to_check = []
@@ -105,11 +111,11 @@ def noTrailingSlash(meta_to_check):
105
111
meta_to_check .append (post .metadata )
106
112
107
113
108
-
109
114
print ("Begin CI Checks!\n " )
110
115
passed = True
111
- for message in checks :
112
- failures = checks [message ](meta_to_check )
116
+ check_functions = [v for k , v in globals ().items () if k .startswith ("check_" )]
117
+ for check_function in check_functions :
118
+ message , failures = check_function (meta_to_check )
113
119
print ("***********************************!" )
114
120
print ("Checking... {}" .format (message ))
115
121
if len (failures ) > 0 :
@@ -123,4 +129,4 @@ def noTrailingSlash(meta_to_check):
123
129
print ("End CI Checks!\n " )
124
130
125
131
if not passed :
126
- raise Exception ("***********CI Checks Not Passed ! Check Error Messages!********************* " )
132
+ raise Exception ("**One or more CI Check failed ! Check Error Messages!" )
0 commit comments