atomiq.tools.atomiq_component_creator ===================================== .. py:module:: atomiq.tools.atomiq_component_creator .. autoapi-nested-parse:: A helper program to create components for the components db dictionary. .. image:: /img/tools/component_creator_1.svg :alt: main screen Attributes ---------- .. autoapisummary:: atomiq.tools.atomiq_component_creator.console atomiq.tools.atomiq_component_creator.ABBREVIATIONS atomiq.tools.atomiq_component_creator.COMPONENT_MODULES Classes ------- .. autoapisummary:: atomiq.tools.atomiq_component_creator.ComponentEntry atomiq.tools.atomiq_component_creator.ArgumentEntry atomiq.tools.atomiq_component_creator.PrettyValue atomiq.tools.atomiq_component_creator.InteractiveBuilder Functions --------- .. autoapisummary:: atomiq.tools.atomiq_component_creator.import_components atomiq.tools.atomiq_component_creator.class_from_name_only atomiq.tools.atomiq_component_creator.class_from_full_string atomiq.tools.atomiq_component_creator.get_inheritors atomiq.tools.atomiq_component_creator.get_recursive_args atomiq.tools.atomiq_component_creator.editable_default_input atomiq.tools.atomiq_component_creator.generate_atomiq_class_doc_link atomiq.tools.atomiq_component_creator.selection_gui atomiq.tools.atomiq_component_creator.get_argparser atomiq.tools.atomiq_component_creator.main Module Contents --------------- .. py:data:: console .. py:data:: ABBREVIATIONS .. py:data:: COMPONENT_MODULES :value: ['atomiq.components'] .. py:function:: import_components(modules) Imports all submodules from a module to make components inside that module visible to the component creator tool. :param modules: List of modules, can be either strings or the modules itself .. py:function:: class_from_name_only(sstr) 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`. :param sstr: name of the class to search for .. py:function:: class_from_full_string(sstr) Generate a class Type from a full string. :param sstr: a full class path like e.g. "atomiq.components.sinara.suservo.SUServoModulatedLaser" .. py:function:: get_inheritors(klass) Recursively gets all loaded classes which are abstracting from class `klass` .. py:function:: get_recursive_args(klass, kwargs_modifications = None, optionals = False) Analyzes the call signature of the __init__ function of `klass` to find which arguments are mandatory. This is performed recursively through all base classes. :param kwargs_modifications: List of kwargs defined in an __init__ function which are passed down to parent classes :param optionals: If True return optional args, if false return mandatory args .. py:function:: editable_default_input(prompt, default) Helper function to generate a cli prompt with default input which can be edited by the user :param prompt: Non-editable text to show :param default: Editable default value .. py:function:: 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`. Returns `None` if the class does not belong to atomiq. .. py:class:: ComponentEntry(name, target_class) Class representing a component configured in the components dictionary :param name: name of the component as in the components dict :param target_class: type of the target class .. py:attribute:: target_class .. py:attribute:: class_name .. py:attribute:: name .. py:attribute:: required_args .. py:attribute:: optional_args .. py:method:: init_from_template_dict(name, component_dict) :staticmethod: Initializes a component from a *single* component dictionary entry as saved in the components database or a template. :param name: name of the component :param component_dict: single component component dict entry .. py:method:: populate_from_template_dict(component_dict) Populate a component recursively from a component dictionary as saved in the components database or a template :param component_dict: full component dict .. py:property:: configured Returns true if all required arguments of this and all its subcomponents are set .. py:method:: generate_component_dict(component_dict) 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`. :param component_dict: dictionary this component is added to .. py:method:: get_undefined_args() Returns a list of all required arguments of this and all its subcomponents which are not yet defined/set .. py:method:: get_fixed_args() Returns a list of all arguments of this and all its subcomponents which are defined by a fixed value (not a subcomponent) .. py:method:: get_modified_args() Returns all arguments which are either required or kwargs which differ from their default value .. py:method:: set_base_name(old_value, new_value) Set the base name of this component and all its subcomponents :param old_value: old base name used to identify the base name in the full name :param new_value: new base name with which the string `old_value` is replaced .. py:class:: ArgumentEntry(arg, parent) This class represents an argument of a component init function. :param arg: argument of a component as given by introspection of the component :param parent: the component this argument is part of .. py:attribute:: _value :value: None .. py:attribute:: unit :value: None .. py:attribute:: optional :value: False .. py:attribute:: default :value: None .. py:attribute:: raw_arg .. py:attribute:: name .. py:attribute:: target_class :value: None .. py:attribute:: parent .. py:property:: configured Is true if the set value is not None or, if the value is a subcomponent, this component is fully configured .. py: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" .. py:method:: get_print_value() Get a nice representation of the argument value usable with the rich module and in correct representation for writing to a components dict .. py:method:: get_print_default() Get a nice representation of the default argument value usable with the rich module and in correct representation for writing to a components dict .. py:class:: PrettyValue(value, unit) Pretty printable value which implements a rich representation and a representation compatible with the components dict syntax .. py:attribute:: value .. py:attribute:: unit .. py:method:: __repr__(*args) .. py:method:: __rich__(*args) .. py:function:: selection_gui(func) 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. .. py:class:: InteractiveBuilder(config) 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 :param config: parsed atomiq tool config dictionary as defined in atomiq_tools.toml .. attribute:: base_name base name string of the root component which is added to all subcomponents .. attribute:: base_component Type of the root component (e.q. `atomiq.components.sinara.suservo.SUServoModulatedLaser`) .. py:attribute:: base_name :type: str .. py:attribute:: base_component :type: Type .. py:attribute:: _last_screens :value: [] .. py:attribute:: config .. py:method:: start_from_class(target_class, name) Start the cli tool from a single, non configured component :param target_class: Type of the target component class :param name: name of the root component, used as a base name for all subcomponents .. py:method:: go_back(index = -2) Go back by `index` steps in the cli screen history. :param index: determines how far to go back in screen history. The default of `-2` corresponds to the last screen, since `-1` is the current screen .. py:method:: generate_name(component_type) 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 :param component_type: name of the component class type .. py:method:: save_template(f_name) Save the current component dict as a template as a python file :param f_name: Name of the output file .. py:method:: load_template(f_name) Start the cli by loading and populating components from a template file :param f_name: Name of the imput template file .. py:method:: generate_component_dict() Generate a component dict by recursively gathering all configured component entries .. py:method:: get_undefined_args() Returns a list of all required arguments of all configured components which are not yet defined/set .. py:method:: get_fixed_args() 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 .. py:method:: set_base_name(value) Recursively set the base name of all configured components .. py:method:: print_class_selection(config_class) CLI screen for displaying and editing a component :param config_class: Component to configure in this screen .. py:method:: print_arg_possibilities(arg) 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. :param ArgumentEntry: Argument for which a component should be chosen. .. py:method:: tree_view() CLI screen which shows the relations of the currently configured components in a tree-style diagram .. py:method:: print_undefined_args() CLI screen to display all required args which are not (yet) set/defined .. py:method:: print_fixed_args() CLI screen to display all args which are set to a excplicit value (not another component) .. py:function:: get_argparser() .. py:function:: main()