5454]
5555
5656# ####################################
57- # Run bikeshed build
57+ # Post-process all versions
5858# ####################################
5959
6060
61- def bikeshed ():
61+
62+ from pathlib import Path
63+
64+ from json_schema_for_humans .generate import (
65+ generate_from_filename ,
66+ GenerationConfiguration ,
67+ )
68+
69+
70+ def get_version_index_html (* , version : str , schmea_fnames : list [Path ]) -> str :
71+ schemas_list = "\n " .join (
72+ [f"<li><a href={ p .name } >{ p .stem } </a> </li>" for p in schmea_fnames ]
73+ )
74+ return f"""
75+ <!DOCTYPE html>
76+ <html lang="en">
77+ <head>
78+ <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Overpass:300,400,600,800">
79+ <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
80+ <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
81+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
82+ <link rel="stylesheet" type="text/css" href="schema_doc.css">
83+ <script src="https://use.fontawesome.com/facf9fa52c.js"></script>
84+ <script src="schema_doc.min.js"></script>
85+ <meta charset="utf-8"/>
86+
87+
88+ <title>OME-zarr version { version } </title>
89+ </head>
90+ <body onload="anchorOnLoad();" id="root">
91+
92+ <div class="breadcrumbs"></div> <h1>Version { version } </h1><br/>
93+ <ul>
94+ { schemas_list }
95+ </ul>
96+ </body>
97+ </html>
98+ """
99+
100+
101+ def get_index_html (* , versions : list [str ]) -> str :
102+ versions_list = "\n " .join (
103+ [f"<li><a href={ v } /index.html>{ v } </a> </li>" for v in versions ]
104+ )
105+ return f"""
106+ <!DOCTYPE html>
107+ <html lang="en">
108+ <head>
109+ <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Overpass:300,400,600,800">
110+ <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
111+ <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
112+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
113+ <link rel="stylesheet" type="text/css" href="schema_doc.css">
114+ <script src="https://use.fontawesome.com/facf9fa52c.js"></script>
115+ <script src="schema_doc.min.js"></script>
116+ <meta charset="utf-8"/>
117+
118+
119+ <title>OME-zarr JSON schema specifications</title>
120+ </head>
121+ <body onload="anchorOnLoad();" id="root">
122+
123+ <div class="breadcrumbs"></div> <h1>OME-zarr JSON schema specifications</h1><br/>
124+ <p> Nicely rendered JSON schemas generated directly from the <a href=https://ngff.openmicroscopy.org/specifications/index.html>OME-zarr specifications</a>.</p>
125+ <p> Generated using <a href=https://coveooss.github.io/json-schema-for-humans>json-schema-for-humans</a>.</p>
126+ <ul>
127+ { versions_list }
128+ </ul>
129+ </body>
130+ </html>
131+ """
132+
133+
134+ def gen_version (version ):
135+ version_path = Path (version )
136+ schema_path = version_path / "schemas"
137+ for schema_file in sorted (schema_path .glob ("*.schema" )):
138+ print (schema_file )
139+ generate_from_filename (
140+ schema_file ,
141+ result_file_name = schema_path / schema_file .with_suffix (".html" ).name ,
142+ config = GenerationConfiguration (template_name = "js" , with_footer = False ),
143+ )
144+
145+ schema_fnames = [
146+ p
147+ for p in sorted (schema_path .glob ("*.html" ))
148+ if p .name != "index.html"
149+ ]
150+ with open (schema_path / "index.html" , "w" ) as f :
151+ f .write (
152+ get_version_index_html (version = version , schmea_fnames = schema_fnames )
153+ )
154+
155+
156+ def post_process ():
62157 import glob
63158 import os
64159 import shutil
65160 import subprocess
66161
67- for index_file in ["latest/index.bs" ] + glob .glob ("[0-9]*/index.bs" ):
162+ versions = ["latest" ] + glob .glob ("[0-9]*" )
163+ for version in versions :
164+
165+ # Run bikeshed
166+ index_file = f"{ version } /index.bs"
68167 output_file = index_file .replace ("bs" , "html" )
69168 output_dir = os .path .dirname (output_file )
70169 target_dir = os .path .join ("_bikeshed" , output_dir )
@@ -81,13 +180,21 @@ def bikeshed():
81180
82181 if run_bikeshed :
83182 subprocess .check_call (
84- f"bikeshed spec { index_file } { output_file } " , shell = True
183+ f"bikeshed spec { index_file } { output_file } " , shell = True ,
85184 )
86185
87186 if os .path .exists (target_dir ):
88187 shutil .rmtree (target_dir )
89188 shutil .copytree (output_dir , target_dir )
90189
190+ # Run json-schema-for-humans
191+ try :
192+ d = os .getcwd ()
193+ os .chdir ("_bikeshed" )
194+ gen_version (version )
195+ finally :
196+ os .chdir (d )
197+
91198
92- bikeshed ()
93- del bikeshed
199+ post_process ()
200+ del post_process
0 commit comments