reflections
tergite_autocalibration.utils.misc.reflections
Classes:
| Name | Description |
|---|---|
ASTParser |
Parser for the abstract syntax tree. This is to allow inferring more information from |
Functions:
| Name | Description |
|---|---|
find_inheriting_classes_ast_recursive |
Recursively finds all classes in a directory and its subdirectories that inherit |
get_class_attributes |
Current implementation only supports to return lists, but can easily be extended. |
import_class_from_file |
Imports a class from a given file path. |
ASTParser
Parser for the abstract syntax tree. This is to allow inferring more information from the sourcecode itself.
Methods:
| Name | Description |
|---|---|
get_init_attribute_names |
Returns all the attributes from the init function of a class |
find_inheriting_classes_ast_recursive
find_inheriting_classes_ast_recursive(directory: Union[str, Path], base_class_name: str = None) -> dict
Recursively finds all classes in a directory and its subdirectories that inherit from the specified base class using AST parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
The root directory to search for classes. |
required |
base_class_name
|
str
|
The name of the base class to check inheritance. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary where keys are file paths, and values are lists of class names inheriting from base_class_name. |
get_class_attributes
Current implementation only supports to return lists, but can easily be extended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
Path to the file that contains the class. |
required |
class_name
|
str
|
Name of the class to parse. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, List[str]]
|
A dictionary that maps the class attribute name to their values. |
import_class_from_file
Imports a class from a given file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
The name of the class to import. |
required |
file_path
|
str
|
The path to the file containing the class. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Type |
Type
|
The class type if found, otherwise raises an AttributeError or FileNotFoundError. |