The generate_content.py module#

Summary#

DocMember

Docstring member.

Method

Method class.

Param

Param class.

Property

Property class.

adjust_method_name_xml

Adjust the method name to find docstring in XML.

c_types_to_python

Replace C# types with Python types.

crawl_loaded_references

Crawl Loaded assemblies to get Namespaces.

dump_types

Crawl Loaded assemblies to get Namespaces.

fix_str

Replace incorrect special characters in strings.

get_doc

Get the documentation file from assembly, or None if it doesn't exist.

get_methods

Get information from methods and store it in the Method object.

get_namespaces

Get all the namespaces and filtered types in the assembly given by assembly_name.

get_properties

Get information from properties and store it in the Property object.

is_namespace

Check if an object is a namespace.

iter_module

Recursively iterates through all namespaces in assembly.

load_doc

Get a dictionary of doc entities from the Assembly documentation file.

make

Generate Python stubs for an assembly.

remove_backtick

Remove backticks from a given string.

write_class

Write a class.

write_docstring

Write docstring of class or enum with the given indentation level, if available.

write_enum

Write an enum.

write_enum_field

Write an enum field.

write_method

Write a method.

write_missing_class_enum_docstring

Write a docstring for classes and enums that do not contain a docstring in the XML file.

write_missing_prop_method_docstring

Write a docstring for methods and properties that do not contain a docstring in the XML file.

write_module

Write a module.

write_property

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']#