The generate_content.py
module#
Summary#
Adjust the method name to find docstring in XML. |
|
Replace C# types with Python types. |
|
Crawl Loaded assemblies to get Namespaces. |
|
Crawl Loaded assemblies to get Namespaces. |
|
Replace incorrect special characters in strings. |
|
Get the documentation file from assembly, or None if it doesn't exist. |
|
Get information from methods and store it in the Method object. |
|
Get all the namespaces and filtered types in the assembly given by assembly_name. |
|
Get information from properties and store it in the Property object. |
|
Check if an object is a namespace. |
|
Recursively iterates through all namespaces in assembly. |
|
Get a dictionary of doc entities from the Assembly documentation file. |
|
Generate Python stubs for an assembly. |
|
Remove backticks from a given string. |
|
Write a class. |
|
Write docstring of class or enum with the given indentation level, if available. |
|
Write an enum. |
|
Write an enum field. |
|
Write a method. |
|
Write a docstring for classes and enums that do not contain a docstring in the XML file. |
|
Write a docstring for methods and properties that do not contain a docstring in the XML file. |
|
Write a module. |
|
Write a property. |
Description#
Module containing routine to generate python stubs for an assembly.
Module detail#
- generate_content.adjust_method_name_xml(method_name: str)#
Adjust the method name to find docstring in XML.
- Parameters:
- method_name: str
The method name
- generate_content.c_types_to_python(type_str)#
Replace C# types with Python types.
- Parameters:
- type_str: str
String containing C# type.
- generate_content.crawl_loaded_references(assembly: System.Reflection.RuntimeAssembly, type_filter: Callable = None) dict #
Crawl Loaded assemblies to get Namespaces.
- Parameters:
- assembly: System.Reflection.RuntimeAssembly
An assembly. For example, Ansys.ACT.WB1.
- type_filter: typing.Callable
Whether or not the type is published
- Returns:
dict
Dictionary of namespaces in the assembly
- generate_content.dump_types(namespaces: dict)#
Crawl Loaded assemblies to get Namespaces.
- Parameters:
- namespaces: dict
Dictionary of namespaces in the assembly
- generate_content.fix_str(input_str: str)#
Replace incorrect special characters in strings.
- Parameters:
- input_str: str
A string that could contain backticks
- Returns:
str
A string that doesn't have special characters
- generate_content.get_doc(assembly: System.Reflection.RuntimeAssembly)#
Get the documentation file from assembly, or None if it doesn't exist.
- Parameters:
- assembly: “System.Reflection.RuntimeAssembly”
An assembly. For example, Ansys.ACT.WB1.
- generate_content.get_methods(class_type: Any, doc: Dict[str, DocMember], type_filter: Callable = None) List[Method] #
Get information from methods and store it in the Method object.
- Parameters:
- class_type: typing.Any
The class type.
- doc: typing.Dict[str, DocMember]
A DocMember or string that holds information about the method.
- type_filter: typing.Callable = None
Whether or not the type is published.
- Returns:
typing.List
[Method
]A list of methods
- generate_content.get_namespaces(assembly: System.Reflection.RuntimeAssembly, type_filter: Callable = None) Dict #
Get all the namespaces and filtered types in the assembly given by assembly_name.
- Parameters:
- assembly: “System.Reflection.RuntimeAssembly”
An assembly
- type_filter:
Whether or not the type is published
- Returns:
typing.Dict
A dictionary of published namespaces within the assembly
- generate_content.get_properties(class_type: Any, doc: Dict[str, DocMember], type_filter: Callable = None) List[Property] #
Get information from properties and store it in the Property object.
- Parameters:
- class_type: typing.Any
The class type.
- doc: typing.Dict[str, DocMember]
A DocMember or string that holds information about the property.
- type_filter: typing.Callable = None
Whether or not the type is published.
- Returns:
typing.List
[Property
]A list of properties
- generate_content.is_namespace(something)#
Check if an object is a namespace.
- Parameters:
- something: object
Object to check if it's a namespace
- Returns:
- bool
True if object is Namespace: Module False if object is not Namespace: Module
- generate_content.iter_module(module, type_filter: Callable = None)#
Recursively iterates through all namespaces in assembly.
- Parameters:
- module: System.Reflection.RuntimeAssembly
An assembly module
- type_filter: typing.Callable
Whether or not the type is published
- Returns:
str
The namespace in the assembly file
- generate_content.load_doc(xml_path: str) xml.etree.ElementTree #
Get a dictionary of doc entities from the Assembly documentation file.
- Parameters:
- xml_path: str
The path to the XML file
- Returns:
ElementTree
An element tree of the information from the assembly XML file
- generate_content.make(outdir: str, assembly_name: str, type_filter: Callable = None) None #
Generate Python stubs for an assembly.
- Parameters:
- outdir: str
The directory where modules are being written to.
- assembly_name: str
The name of the assembly
- type_filter: typing.Callable
Whether or not a type is published
- generate_content.remove_backtick(input_str: str)#
Remove backticks from a given string.
- Parameters:
- input_str: str
A string that could contain backticks
- Returns:
str
A string without backticks
- generate_content.write_class(buffer: TextIO, class_type: Any, namespace: str, doc: Dict[str, DocMember], type_filter: Callable = None) None #
Write a class.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the class
- class_type: typing.Any
The class type object
- namespace: str
The namespace of the class being written
- doc: typing.Dict[str, DocMember]
A DocMember or string that holds information about the class.
- type_filter: typing.Callable = None
Whether or not the type is published
- generate_content.write_docstring(buffer: TextIO, doc_member: DocMember | None, indent_level=1) None #
Write docstring of class or enum with the given indentation level, if available.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- doc_member: typing.Optional[DocMember]
A member's name, summary, params, remarks, and examples
- indent_level: int
1
to write one indent
- generate_content.write_enum(buffer: TextIO, enum_type: Any, namespace: str, doc: Dict[str, DocMember], type_filter: Callable = None) None #
Write an enum.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- enum_type: typing.Any
The enum type
- namespace: str
The namespace of the enum
- doc: typing.Dict[str, DocMember]
A DocMember or string that holds information about the enum.
- type_filter: typing.Callable = None
Whether or not the type is published.
- generate_content.write_enum_field(buffer: TextIO, field: Any, indent_level: int = 1) None #
Write an enum field.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- field: typing.Any
The field information from System.Reflection.MdFieldInfo
- indent_level: int
1
to write one indent
- generate_content.write_method(buffer: TextIO, method: Method, indent_level: int = 1) None #
Write a method.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the method
- method: Method
A Method object
- indent_level: int
1
to indent a line once
- generate_content.write_missing_class_enum_docstring(buffer, name, obj_type)#
Write a docstring for classes and enums that do not contain a docstring in the XML file.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- name: str
The name of an interface
- obj_type: str
The object type of the interface
- generate_content.write_missing_prop_method_docstring(buffer, obj, obj_type, indent_level)#
Write a docstring for methods and properties that do not contain a docstring in the XML file.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- obj: generate_content.Method or generate_content.Property
A method or property object
- obj_type: type
The object type of the interface
- indent_level: int
1
to indent a line once
- generate_content.write_module(namespace: str, mod_types: List, doc: Dict[str, DocMember], outdir: str, type_filter: Callable = None) None #
Write a module.
- Parameters:
- mod_type: typing.Any
The module type object
- doc: typing.Dict[str, DocMember]
A DocMember or string that holds information about the class.
- outdir: str
The path of the file that contains the module.
- type_filter: typing.Callable = None
Whether or not the type is published
- generate_content.write_property(buffer: TextIO, prop: Property, indent_level: int = 1) None #
Write a property.
- Parameters:
- buffer: typing.TextIO
The buffer for writing the docstring
- prop: Property
A Property object containing information about the property
- indent_level: int
1
to write one indent
- generate_content.C_TO_PYTHON#
- generate_content.ENUM_VALUE_REPLACEMENTS#
- generate_content.EXCLUDED_TYPES_LIST = ['System.IAsyncResult', 'System.IDisposable', 'System.Func', 'System.Delegate']#