atomiq.tools.atomiq_component_creator

A helper program to create components for the components db dictionary.

main screen

Attributes

Classes

ComponentEntry

Class representing a component configured in the components dictionary

ArgumentEntry

This class represents an argument of a component init function.

PrettyValue

Pretty printable value which implements a rich representation and a

InteractiveBuilder

Implements an interactive cli builder for configuring components and

Functions

import_components(modules)

Imports all submodules from a module to make components inside that module

class_from_name_only(sstr)

Inferes a type from a name string by searching in all imported modules for the class name sstr

class_from_full_string(sstr)

Generate a class Type from a full string.

get_inheritors(klass)

Recursively gets all loaded classes which are abstracting from class klass

get_recursive_args(klass[, kwargs_modifications, ...])

Analyzes the call signature of the __init__ function of klass to find which arguments are mandatory.

editable_default_input(prompt, default)

Helper function to generate a cli prompt with default input which can be

generate_atomiq_class_doc_link(target_class)

Helper function to generate a link to the atomiq gitlab pages documentation of a given class target_class.

selection_gui(func)

Decorator function for interactive screens allowing for going back a

get_argparser()

main()

Module Contents

atomiq.tools.atomiq_component_creator.console
atomiq.tools.atomiq_component_creator.ABBREVIATIONS
atomiq.tools.atomiq_component_creator.COMPONENT_MODULES = ['atomiq.components']
atomiq.tools.atomiq_component_creator.import_components(modules)[source]

Imports all submodules from a module to make components inside that module visible to the component creator tool.

Parameters:

modules (List) -- List of modules, can be either strings or the modules itself

Return type:

None

atomiq.tools.atomiq_component_creator.class_from_name_only(sstr)[source]

Inferes a type from a name string by searching in all imported modules for the class name sstr If multiple types are found, the most likely one is chosen based on an assesment of the parent module. If no type with the given name is found returns None.

Parameters:

sstr (str) -- name of the class to search for

Return type:

Optional[Type]

atomiq.tools.atomiq_component_creator.class_from_full_string(sstr)[source]

Generate a class Type from a full string.

Parameters:

sstr (str) -- a full class path like e.g. "atomiq.components.sinara.suservo.SUServoModulatedLaser"

Return type:

Type

atomiq.tools.atomiq_component_creator.get_inheritors(klass)[source]

Recursively gets all loaded classes which are abstracting from class klass

Parameters:

klass (Type)

Return type:

List[Type]

atomiq.tools.atomiq_component_creator.get_recursive_args(klass, kwargs_modifications=None, optionals=False)[source]

Analyzes the call signature of the __init__ function of klass to find which arguments are mandatory. This is performed recursively through all base classes.

Parameters:
  • kwargs_modifications (Optional[List]) -- List of kwargs defined in an __init__ function which are passed down to parent classes

  • optionals (bool) -- If True return optional args, if false return mandatory args

  • klass (Type)

Return type:

List

atomiq.tools.atomiq_component_creator.editable_default_input(prompt, default)[source]

Helper function to generate a cli prompt with default input which can be edited by the user

Parameters:
  • prompt (str) -- Non-editable text to show

  • default (str) -- Editable default value

Return type:

str

Helper function to generate a link to the atomiq gitlab pages documentation of a given class target_class. Returns None if the class does not belong to atomiq.

Parameters:

target_class (Type)

Return type:

Optional[str]

class atomiq.tools.atomiq_component_creator.ComponentEntry(name, target_class)[source]

Class representing a component configured in the components dictionary

Parameters:
  • name (str) -- name of the component as in the components dict

  • target_class (Type) -- type of the target class

target_class
class_name
name
required_args
optional_args
static init_from_template_dict(name, component_dict)[source]

Initializes a component from a single component dictionary entry as saved in the components database or a template.

Parameters:
  • name (str) -- name of the component

  • component_dict (dict[str, Any]) -- single component component dict entry

Return type:

ComponentEntry

populate_from_template_dict(component_dict)[source]

Populate a component recursively from a component dictionary as saved in the components database or a template

Parameters:

component_dict (dict[str, Any]) -- full component dict

Return type:

None

property configured

Returns true if all required arguments of this and all its subcomponents are set

generate_component_dict(component_dict)[source]

Generate a component dict entry for this component and all child components recursively. The entry is directly added to the dict passed in component_dict.

Parameters:

component_dict (dict[str, Any]) -- dictionary this component is added to

Return type:

None

get_undefined_args()[source]

Returns a list of all required arguments of this and all its subcomponents which are not yet defined/set

Return type:

List

get_fixed_args()[source]

Returns a list of all arguments of this and all its subcomponents which are defined by a fixed value (not a subcomponent)

Return type:

List

get_modified_args()[source]

Returns all arguments which are either required or kwargs which differ from their default value

Return type:

List

set_base_name(old_value, new_value)[source]

Set the base name of this component and all its subcomponents

Parameters:
  • old_value (str) -- old base name used to identify the base name in the full name

  • new_value (str) -- new base name with which the string old_value is replaced

Return type:

None

class atomiq.tools.atomiq_component_creator.ArgumentEntry(arg, parent)[source]

This class represents an argument of a component init function.

Parameters:
  • arg (inspect.Parameter) -- argument of a component as given by introspection of the component

  • parent (ComponentEntry) -- the component this argument is part of

_value = None
unit = None
optional = False
default = None
raw_arg
name
target_class = None
parent
property configured

Is true if the set value is not None or, if the value is a subcomponent, this component is fully configured

property value

Current set value of the argument. When setting this argument, the value is automatically cast to the correct type as required by this argument"

get_print_value()[source]

Get a nice representation of the argument value usable with the rich module and in correct representation for writing to a components dict

Return type:

PrettyValue

get_print_default()[source]

Get a nice representation of the default argument value usable with the rich module and in correct representation for writing to a components dict

Return type:

PrettyValue

class atomiq.tools.atomiq_component_creator.PrettyValue(value, unit)[source]

Pretty printable value which implements a rich representation and a representation compatible with the components dict syntax

value
unit
__repr__(*args)[source]
__rich__(*args)[source]
atomiq.tools.atomiq_component_creator.selection_gui(func)[source]

Decorator function for interactive screens allowing for going back a screen, auto clearing the console on screen change and going back a screen on error.

Parameters:

func (Callable)

Return type:

Callable

class atomiq.tools.atomiq_component_creator.InteractiveBuilder(config)[source]

Implements an interactive cli builder for configuring components and getting information on the current configuration status. The implementation uses the rich package to print to the command line

Parameters:

config (dict[str, Any]) -- parsed atomiq tool config dictionary as defined in atomiq_tools.toml

base_name

base name string of the root component which is added to all subcomponents

base_component

Type of the root component (e.q. atomiq.components.sinara.suservo.SUServoModulatedLaser)

base_name: str
base_component: Type
_last_screens = []
config
start_from_class(target_class, name)[source]

Start the cli tool from a single, non configured component

Parameters:
  • target_class (Type) -- Type of the target component class

  • name (str) -- name of the root component, used as a base name for all subcomponents

Return type:

None

go_back(index=-2)[source]

Go back by index steps in the cli screen history.

Parameters:

index (int) -- determines how far to go back in screen history. The default of -2 corresponds to the last screen, since -1 is the current screen

Return type:

None

generate_name(component_type)[source]

Generate a component name based on its class of the form {class_name}_{base_name}. If an abbreviation is found in the config["abbreviations"] dict, the abbreviation is used as name prefix

Parameters:

component_type (str) -- name of the component class type

Return type:

str

save_template(f_name)[source]

Save the current component dict as a template as a python file

Parameters:

f_name (str) -- Name of the output file

Return type:

None

load_template(f_name)[source]

Start the cli by loading and populating components from a template file

Parameters:

f_name (str) -- Name of the imput template file

Return type:

None

generate_component_dict()[source]

Generate a component dict by recursively gathering all configured component entries

get_undefined_args()[source]

Returns a list of all required arguments of all configured components which are not yet defined/set

Return type:

list

get_fixed_args()[source]

Returns a list of all arguments of all configured components which are either set to a excplicit value or are optional args differing from their default value

Return type:

list

set_base_name(value)[source]

Recursively set the base name of all configured components

Parameters:

value (str)

Return type:

None

print_class_selection(config_class)[source]

CLI screen for displaying and editing a component

Parameters:

config_class (ComponentEntry) -- Component to configure in this screen

Return type:

None

print_arg_possibilities(arg)[source]

CLI screen for displaying and choosing from possible components for a given argument of another component. Possible components are all classes which inherit from the type of the argument entry. All loaded modules are searched for possible matches.

Parameters:
  • ArgumentEntry -- Argument for which a component should be chosen.

  • arg (ArgumentEntry)

Return type:

None

tree_view()[source]

CLI screen which shows the relations of the currently configured components in a tree-style diagram

Return type:

None

print_undefined_args()[source]

CLI screen to display all required args which are not (yet) set/defined

Return type:

None

print_fixed_args()[source]

CLI screen to display all args which are set to a excplicit value (not another component)

atomiq.tools.atomiq_component_creator.get_argparser()[source]
Return type:

ArgumentParser

atomiq.tools.atomiq_component_creator.main()[source]