@@ -98,7 +98,22 @@ def __init__(self, name_map):
9898
9999
100100def to_py_name (name , name_map = None ):
101- """Convert to a Python-compatible name."""
101+ """
102+ Return a Python-compatible name for a command using the global name map.
103+
104+ Parameters
105+ ----------
106+ name : str
107+ Name of the command.
108+
109+ name_map : dict
110+ Dictionary containing the name map.
111+
112+ Returns
113+ -------
114+ str
115+ Python-compatible command name.
116+ """
102117 if name_map is not None :
103118 global NAME_MAP_GLOB
104119 NAME_MAP_GLOB = name_map
@@ -109,7 +124,19 @@ def to_py_name(name, name_map=None):
109124
110125
111126def get_iter_values (name : str ):
112- """Get the values of an iterator."""
127+ """
128+ Get the values of an iterator.
129+
130+ Parameters
131+ ----------
132+ name : str
133+ Name of the parameter containing the iterator.
134+
135+ Returns
136+ -------
137+ tuple(str, int)
138+ Tuple containing the name of the iterator and the iteration value.
139+ """
113140 output = re .search (r"([a-zA-Z_]*)(\d*)" , name .strip ())
114141 groups = output .groups ()
115142 name = groups [0 ]
@@ -140,7 +167,19 @@ def get_quant_iter_pos(name: str) -> tuple:
140167
141168
142169def to_py_arg_name (name : str ) -> str :
143- """Python-compatible term"""
170+ """
171+ Return a Python-compatible name for an argument.
172+
173+ Parameters
174+ ----------
175+ name : str
176+ Name of the argument.
177+
178+ Returns
179+ -------
180+ str
181+ Python-compatible argument name.
182+ """
144183 initial_arg = str (name ).lower ().strip ()
145184 arg = initial_arg
146185 if arg in ["--" , "–" , "" ]:
@@ -180,8 +219,29 @@ def to_py_arg_name(name: str) -> str:
180219def get_complete_args_from_initial_arg (
181220 initial_args : List [str ], elipsis_args : List [str ]
182221) -> List [str ]:
183- # elipsis_args = ['Cname1', ' Cname2',' …'] or ['Cname1', '...', 'Cname6']
184- # initial_args = ['energytype', 'cname1', 'cname2', 'cname3', 'cname4', 'cname5', 'cname6']
222+ """
223+ Get the complete argument list from a list with elipsis.
224+
225+ Parameters
226+ ----------
227+ initial_args : list
228+ List of initial arguments.
229+
230+ elipsis_args : list
231+ List of containing the elipsed arguments.
232+
233+ Returns
234+ -------
235+ list
236+ List of complete pythonnic arguments.
237+
238+ Examples
239+ --------
240+ >>> initial_args = ['energytype', 'cname1', 'cname2', 'cname3', 'cname4', 'cname5', 'cname6']
241+ >>> elipsis_args = ['Cname1', ' Cname2',' …']
242+ >>> get_complete_args_from_initial_arg(initial_args, elipsis_args)
243+ ['cname1', 'cname2', 'cname3', 'cname4', 'cname5', 'cname6']
244+ """
185245
186246 first_arg_name = to_py_arg_name (elipsis_args [0 ])
187247 name_without_iter , first_num = get_iter_values (first_arg_name )
@@ -209,20 +269,107 @@ def is_elipsis(name: str) -> bool:
209269
210270
211271def str_types (types , join_str : str ) -> str :
212- """String representation of the parameter types."""
272+ """
273+ String representation of the parameter types.
274+
275+ Parameters
276+ ----------
277+ types : list
278+ List of types.
279+
280+ join_str : str
281+ String to join the types.
282+
283+ Returns
284+ -------
285+ str
286+ String representation of the parameter types.
287+
288+ Examples
289+ --------
290+ >>> types = [str, int, float]
291+ >>> str_types(types, " | ")
292+ 'str | int | float'
293+
294+ >>> types = [str, int]
295+ >>> str_types(types, " or ")
296+ 'str or int'
297+ """
213298 ptype_str = join_str .join ([parm_type .__name__ for parm_type in types ])
214299 return ptype_str
215300
216301
217302def to_py_signature (py_arg_name , types ) -> str :
218- """Return the Python signature of the argument."""
303+ """
304+ Return the Python signature of the argument.
305+
306+ Parameters
307+ ----------
308+ py_arg_name : str
309+ Python-compatible argument name.
310+
311+ types : list
312+ List of types.
313+
314+ Returns
315+ -------
316+ str
317+ Python signature of the argument.
318+
319+ Examples
320+ --------
321+ >>> py_arg_name = 'energytype'
322+ >>> types = [str, int, float]
323+ >>> to_py_signature(py_arg_name, types)
324+ 'energytype: str | int | float = ""'
325+ """
219326 if py_arg_name != "" :
220327 kwarg = f'{ py_arg_name } : { str_types (types , " | " )} = ""'
221328 else :
222329 kwarg = None
223330 return kwarg
224331
225332
333+ def resize_length (text , max_length = 100 , initial_indent = "" , subsequent_indent = "" , list = False ):
334+ """
335+ Resize the length of a text.
336+
337+ Parameters
338+ ----------
339+ text : str
340+ Text to resize.
341+
342+ max_length : int
343+ Maximum length of the text to be resized.
344+
345+ initial_indent : str
346+ Initial indentation of the text.
347+
348+ subsequent_indent : str
349+ Subsequent indentation of the text.
350+
351+ return_list : bool
352+ If set to True, the function returns a list of strings.
353+ Default is False.
354+
355+ Returns
356+ -------
357+ str or list
358+ Resized text.
359+ """
360+ text = text .replace (" ." , "." )
361+ wrapper = textwrap .TextWrapper (
362+ width = max_length ,
363+ break_long_words = False ,
364+ initial_indent = initial_indent ,
365+ subsequent_indent = subsequent_indent ,
366+ )
367+ if list is False :
368+ return wrapper .fill (text = text )
369+ else :
370+ return wrapper .wrap (text = text )
371+
372+
226373# ############################################################################
227374# Element class
228375# ############################################################################
@@ -428,21 +575,6 @@ def tag(self):
428575 return self ._element .tag
429576
430577
431- def resize_length (text , max_length = 100 , initial_indent = "" , subsequent_indent = "" , list = False ):
432- """Resize the length of a text."""
433- text = text .replace (" ." , "." )
434- wrapper = textwrap .TextWrapper (
435- width = max_length ,
436- break_long_words = False ,
437- initial_indent = initial_indent ,
438- subsequent_indent = subsequent_indent ,
439- )
440- if list is False :
441- return wrapper .fill (text = text )
442- else :
443- return wrapper .wrap (text = text )
444-
445-
446578class ItemizedList (Element ):
447579 """Provides the itemized list element."""
448580
@@ -861,7 +993,7 @@ def source(self):
861993
862994 def to_rst (self , indent = "" , max_length = 100 ):
863995 """Return a string to enable converting the element to an RST format."""
864- header = f"\n \n { indent } .. code::\n \n "
996+ header = f"\n \n { indent } .. code:: apdl \n \n "
865997 source_code = re .sub (r"[^\S\r\n]" , " " , self .source ) # Remove extra whitespaces
866998 rst_item = header + textwrap .indent (source_code , prefix = indent + " " * 3 ) + "\n "
867999 return rst_item
0 commit comments