@@ -186,10 +186,11 @@ def get_keywords_to_generate(kwd_name: typing.Optional[str] = None) -> typing.Li
186
186
return keywords
187
187
188
188
189
- def generate_classes (lib_path : str , kwd_name : typing .Optional [str ] = None ) -> None :
189
+ def generate_classes (lib_path : str , kwd_name : typing .Optional [str ] = None , autodoc_output_path : str = "" ) -> None :
190
190
"""Generates the keyword classes, importer, and type-mapper
191
191
if kwd_name is not None, this only generates that particular keyword class
192
192
"""
193
+ autodoc_entries = []
193
194
env = Environment (loader = get_loader (), trim_blocks = True , lstrip_blocks = True )
194
195
if not os .path .exists (os .path .join (lib_path , "auto" )):
195
196
os .mkdir (os .path .join (lib_path , "auto" ))
@@ -200,7 +201,16 @@ def generate_classes(lib_path: str, kwd_name: typing.Optional[str] = None) -> No
200
201
continue
201
202
if data_model .is_aliased (name ):
202
203
continue
203
- generate_class (env , lib_path , item )
204
+ classname , filename = generate_class (env , lib_path , item )
205
+ autodoc_entries .append ((classname , filename ))
206
+
207
+ if autodoc_output_path :
208
+ os .makedirs (autodoc_output_path , exist_ok = True )
209
+ rst_template = env .get_template ("autodoc_rst.jinja" )
210
+ combined_rst = rst_template .render (entries = autodoc_entries )
211
+ combined_filepath = os .path .join (autodoc_output_path , "index.rst" )
212
+ with open (combined_filepath , "w" , encoding = "utf-8" ) as f :
213
+ f .write (combined_rst )
204
214
keywords_list .extend (get_undefined_alias_keywords (keywords_list ))
205
215
if kwd_name == None :
206
216
generate_entrypoints (env , lib_path , keywords_list )
@@ -224,6 +234,12 @@ def load_inputs(this_folder, args):
224
234
def run_codegen (args ):
225
235
output = args .output
226
236
this_folder = get_this_folder ()
237
+ autodoc_path = args .autodoc_path
238
+ if not autodoc_path :
239
+ autodoc_path = this_folder .parent / "doc" / "source" / "_autosummary"
240
+ if not os .path .exists (autodoc_path ):
241
+ os .makedirs (autodoc_path )
242
+ autodoc_path = str (autodoc_path .resolve ())
227
243
if args .output == "" :
228
244
output = this_folder .parent / "src" / "ansys" / "dyna" / "core" / "keywords" / "keyword_classes"
229
245
output = str (output .resolve ())
@@ -232,16 +248,15 @@ def run_codegen(args):
232
248
if args .clean :
233
249
clean (output )
234
250
return
235
-
236
251
load_inputs (this_folder , args )
237
252
if args .keyword == "" :
238
253
kwd = None
239
254
print (f"Generating code for all keywords" )
240
- generate_classes (output )
255
+ generate_classes (output , autodoc_output_path = autodoc_path )
241
256
else :
242
257
kwd = args .keyword
243
258
print (f"Generating code for { kwd } " )
244
- generate_classes (output , kwd )
259
+ generate_classes (output , kwd , autodoc_output_path = autodoc_path )
245
260
246
261
247
262
def parse_args ():
@@ -276,6 +291,12 @@ def parse_args():
276
291
default = "" ,
277
292
help = "Path to additional cards file, defaults to additional-cards.json in the same folder as this file." ,
278
293
)
294
+ parser .add_argument (
295
+ "autodoc_path" ,
296
+ default = "" ,
297
+ nargs = "?" ,
298
+ help = "Path to the autodoc output folder. Defaults to doc/source/_autosummary." ,
299
+ )
279
300
return parser .parse_args ()
280
301
281
302
0 commit comments