13
13
# limitations under the License.
14
14
15
15
import logging
16
+ from io import StringIO
16
17
from mkdocs import plugins
18
+ from mkdocs .structure .files import File
17
19
import yaml
18
20
import pandas
19
21
from fnmatch import fnmatch
20
22
import glob
21
23
import os
22
24
23
- log = logging .getLogger ('mkdocs' )
25
+ log = logging .getLogger (f 'mkdocs.plugins. { __name__ } ' )
24
26
25
27
26
28
@plugins .event_priority (100 )
27
- def on_pre_build ( config , ** kwargs ):
29
+ def on_files ( files , config , ** kwargs ):
28
30
log .info ("generating conformance" )
29
31
30
32
vers = getConformancePaths ()
33
+ # Iterate over the list of versions. Exclude the pre 1.0 versions.
31
34
for v in vers [3 :]:
32
35
33
36
confYamls = getYaml (v )
34
37
releaseVersion = v .split (os .sep )[- 2 ]
35
- generate_conformance_tables (confYamls , releaseVersion )
38
+ file = generate_conformance_tables (confYamls , releaseVersion , config )
39
+
40
+ if file :
41
+ existing_file = files .get_file_from_path (file .src_uri )
42
+ if existing_file :
43
+ # Remove the existing file that is likely present in the
44
+ # repository
45
+ files .remove (existing_file )
46
+
47
+ # Add the generated file to the site
48
+ files .append (file )
49
+
50
+ return files
36
51
37
52
38
53
desc = """
@@ -51,7 +66,10 @@ def on_pre_build(config, **kwargs):
51
66
52
67
53
68
54
- def generate_conformance_tables (reports , currVersion ):
69
+ def generate_conformance_tables (reports , currVersion , mkdocsConfig ):
70
+
71
+ # Enable Pandas copy-on-write
72
+ pandas .options .mode .copy_on_write = True
55
73
56
74
gateway_tls_table = pandas .DataFrame ()
57
75
gateway_grpc_table = pandas .DataFrame ()
@@ -79,7 +97,8 @@ def generate_conformance_tables(reports, currVersion):
79
97
if entries .Project < 3 :
80
98
return
81
99
82
- with open ('site-src/implementations/' + versionFile + '.md' , 'w' ) as f :
100
+ try :
101
+ f = StringIO ()
83
102
84
103
f .write (desc )
85
104
f .write ("\n \n " )
@@ -90,7 +109,7 @@ def generate_conformance_tables(reports, currVersion):
90
109
f .write ("## Gateway Profile\n \n " )
91
110
f .write ("### HTTPRoute\n \n " )
92
111
f .write (gateway_http_table .to_markdown ()+ '\n \n ' )
93
- if currVersion != 'v1.0.0' :
112
+ if currVersion != 'v1.0.0' :
94
113
f .write ('### GRPCRoute\n \n ' )
95
114
f .write (gateway_grpc_table .to_markdown ()+ '\n \n ' )
96
115
f .write ('### TLSRoute\n \n ' )
@@ -100,6 +119,20 @@ def generate_conformance_tables(reports, currVersion):
100
119
f .write ("### HTTPRoute\n \n " )
101
120
f .write (mesh_http_table .to_markdown ())
102
121
122
+ file_contents = f .getvalue ()
123
+ finally :
124
+ f .close ()
125
+
126
+ new_file = File (
127
+ src_dir = None ,
128
+ dest_dir = mkdocsConfig ['site_dir' ],
129
+ path = f'implementations/{ versionFile } .md' ,
130
+ use_directory_urls = mkdocsConfig ['use_directory_urls' ],
131
+ )
132
+ new_file .content_string = file_contents
133
+ new_file .generated_by = f'{ __name__ } '
134
+
135
+ return new_file
103
136
104
137
def generate_profiles_report (reports , route ,version ):
105
138
@@ -114,7 +147,7 @@ def generate_profiles_report(reports, route,version):
114
147
'version' ,'mode' , 'extended.supportedFeatures' ]].T
115
148
http_table .columns = http_table .iloc [0 ]
116
149
http_table = http_table [1 :].T
117
-
150
+
118
151
for row in http_table .itertuples ():
119
152
if type (row ._4 ) is list :
120
153
for feat in row ._4 :
@@ -130,8 +163,8 @@ def generate_profiles_report(reports, route,version):
130
163
131
164
132
165
pathTemp = "conformance/reports/*/"
133
- allVersions = []
134
- reportedImplementationsPath = []
166
+ allVersions = set ()
167
+ reportedImplementationsPath = set ()
135
168
136
169
# returns v1.0.0 and greater, since that's when reports started being generated in the comparison table
137
170
@@ -141,9 +174,10 @@ def getConformancePaths():
141
174
report_path = versions [- 1 ]+ "**"
142
175
for v in versions :
143
176
vers = v .split (os .sep )[- 2 ]
144
- allVersions .append (vers )
145
- reportedImplementationsPath .append (v + "**" )
146
- return reportedImplementationsPath
177
+ allVersions .add (vers )
178
+ reportedImplementationsPath .add (v + "**" )
179
+
180
+ return sorted (list (reportedImplementationsPath ))
147
181
148
182
149
183
def getYaml (conf_path ):
@@ -154,11 +188,12 @@ def getYaml(conf_path):
154
188
if fnmatch (p , "*.yaml" ):
155
189
156
190
x = load_yaml (p )
157
- profiles = pandas .json_normalize (
158
- x , record_path = ['profiles' ], meta = ["mode" ,"implementation" ], errors = 'ignore' )
191
+ if 'profiles' in x :
192
+ profiles = pandas .json_normalize (
193
+ x , record_path = ['profiles' ], meta = ["mode" ,"implementation" ], errors = 'ignore' )
159
194
160
- implementation = pandas .json_normalize (profiles .implementation )
161
- yamls .append (pandas .concat ([implementation , profiles ], axis = 1 ))
195
+ implementation = pandas .json_normalize (profiles .implementation )
196
+ yamls .append (pandas .concat ([implementation , profiles ], axis = 1 ))
162
197
163
198
yamls = pandas .concat (yamls )
164
199
return yamls
0 commit comments