22from ansys .dpf .core .dpf_operator import available_operator_names
33from ansys .dpf .core .core import load_library
44import argparse
5- import os
65from jinja2 import Template
6+ from pathlib import Path
77
88def initialize_server (ansys_path = None ):
99 server = dpf .start_local_server (ansys_path = ansys_path )
@@ -13,65 +13,74 @@ def initialize_server(ansys_path=None):
1313 print (f"Server Config: { server .config } " )
1414 print (f"Server version: { dpf .global_server ().version } " )
1515 print ("Loading Composites Plugin" )
16- load_library (os .path .join (server .ansys_path , "dpf" , "plugins" , "dpf_composites" , "composite_operators.dll" ))
16+ load_library (
17+ Path (server .ansys_path ) / "dpf" / "plugins" / "dpf_composites" / "composite_operators.dll"
18+ )
1719 print ("Loading Acoustics Plugin" )
18- load_library (os . path . join (server .ansys_path , "Acoustics" , "SAS" , "ads" , "dpf_sound.dll" ) )
20+ load_library (Path (server .ansys_path ) / "Acoustics" / "SAS" / "ads" / "dpf_sound.dll" )
1921 return server
2022
23+
2124def fetch_doc_info (server , operator_name ):
2225 spec = dpf .Operator .operator_specification (op_name = operator_name , server = server )
2326 input_info = []
2427 output_info = []
2528 configurations_info = []
2629 for input_pin in spec .inputs :
2730 input = spec .inputs [input_pin ]
28- input_info .append ({
29- "pin_number" : input_pin ,
30- "name" : input .name ,
31- "types" : [str (t ) for t in input ._type_names ],
32- "document" : input .document ,
33- "optional" : input .optional ,
34- })
31+ input_info .append (
32+ {
33+ "pin_number" : input_pin ,
34+ "name" : input .name ,
35+ "types" : [str (t ) for t in input ._type_names ],
36+ "document" : input .document ,
37+ "optional" : input .optional ,
38+ }
39+ )
3540 for output_pin in spec .outputs :
3641 output = spec .outputs [output_pin ]
37- output_info .append ({
38- "pin_number" : output_pin ,
39- "name" : output .name ,
40- "types" : [str (t ) for t in output ._type_names ],
41- "document" : output .document ,
42- "optional" : output .optional ,
43- })
42+ output_info .append (
43+ {
44+ "pin_number" : output_pin ,
45+ "name" : output .name ,
46+ "types" : [str (t ) for t in output ._type_names ],
47+ "document" : output .document ,
48+ "optional" : output .optional ,
49+ }
50+ )
4451 for configuration_key in spec .config_specification :
4552 configuration = spec .config_specification [configuration_key ]
46- configurations_info .append ({
47- "name" : configuration .name ,
48- "types" : [str (t ) for t in configuration .type_names ],
49- "document" : configuration .document ,
50- "default_value" : configuration .default_value_str ,
51- })
53+ configurations_info .append (
54+ {
55+ "name" : configuration .name ,
56+ "types" : [str (t ) for t in configuration .type_names ],
57+ "document" : configuration .document ,
58+ "default_value" : configuration .default_value_str ,
59+ }
60+ )
5261 properties = spec .properties
5362 if "plugin" in properties :
5463 plugin = properties ["plugin" ]
5564 else :
5665 plugin = "N/A"
5766 try :
58- scripting_name = properties [' scripting_name' ]
59- full_name = properties [' category' ] + "." + properties [' scripting_name' ]
67+ scripting_name = properties [" scripting_name" ]
68+ full_name = properties [" category" ] + "." + properties [" scripting_name" ]
6069 except KeyError :
6170 scripting_name = None
6271 full_name = None
6372 try :
64- user_name = properties [' user_name' ]
73+ user_name = properties [" user_name" ]
6574 except KeyError :
6675 user_name = operator_name
6776 try :
68- category = properties [' category' ]
77+ category = properties [" category" ]
6978 op_friendly_name = category + ": " + user_name
7079 except KeyError :
7180 category = ""
7281 op_friendly_name = user_name
7382 try :
74- license = properties [' license' ]
83+ license = properties [" license" ]
7584 except KeyError :
7685 license = "None"
7786 scripting_info = {
@@ -89,9 +98,10 @@ def fetch_doc_info(server, operator_name):
8998 "outputs" : output_info ,
9099 "configurations" : configurations_info ,
91100 "scripting_info" : scripting_info ,
92- "exposure" : properties [' exposure' ],
101+ "exposure" : properties [" exposure" ],
93102 }
94103
104+
95105def get_plugin_operators (server , plugin_name ):
96106 operators = available_operator_names (server )
97107 plugin_operators = []
@@ -101,26 +111,30 @@ def get_plugin_operators(server, plugin_name):
101111 plugin_operators .append (operator_name )
102112 return plugin_operators
103113
114+
104115def generate_operator_doc (server , operator_name , include_private ):
105116 operator_info = fetch_doc_info (server , operator_name )
106117 if not include_private and operator_info ["exposure" ] == "private" :
107118 return
108- script_dir = os . path . dirname (__file__ )
109- root_dir = os . path . dirname ( script_dir )
110- template_dir = os . path . join (root_dir , ' doc' , ' source' , ' operators_doc' )
111- with open (os . path . join (template_dir , ' operator_doc_template.md' ), 'r' ) as file :
119+ script_path = Path (__file__ )
120+ root_dir = script_path . parent . parent
121+ template_dir = Path (root_dir ) / " doc" / " source" / " operators_doc"
122+ with Path . open (Path (template_dir ) / " operator_doc_template.md" , "r" ) as file :
112123 template = Template (file .read ())
113-
124+
114125 output = template .render (operator_info )
115126 if "::" in operator_name :
116127 operator_name = operator_name .replace ("::" , "_" )
117- with open (os . path . join (template_dir , f"{ operator_name } .md" ), 'w' ) as file :
128+ with Path . open (Path (template_dir ) / f"{ operator_name } .md" , "w" ) as file :
118129 file .write (output )
119130
131+
120132def main ():
121133 parser = argparse .ArgumentParser (description = "Fetch available operators" )
122134 parser .add_argument ("--plugin" , help = "Filter operators by plugin" )
123- parser .add_argument ("--ansys_path" , default = None , help = "Path to Ansys DPF Server installation directory" )
135+ parser .add_argument (
136+ "--ansys_path" , default = None , help = "Path to Ansys DPF Server installation directory"
137+ )
124138 parser .add_argument ("--include_private" , action = "store_true" , help = "Include private operators" )
125139 args = parser .parse_args ()
126140 desired_plugin = args .plugin
@@ -133,5 +147,6 @@ def main():
133147 for operator_name in operators :
134148 generate_operator_doc (server , operator_name , args .include_private )
135149
150+
136151if __name__ == "__main__" :
137- main ()
152+ main ()
0 commit comments