mafw.runner
Provides a container to run configurable and modular analytical tasks.
Classes
|
The MAFw Application. |
- class mafw.runner.MAFwApplication(steering_file: Path | str | None = None, user_interface: UserInterfaceBase | type[UserInterfaceBase] | str | None = None, plugin_manager: PluginManager | None = None)[source]
Bases:
objectThe MAFw Application.
This class takes care of reading a steering file and from the information retrieved construct a
ProcessorListfrom the processor listed there and execute it.It is very practical because any combination of processors can be run without having to write dedicated scripts but simply modifying a steering file.
The application will search for processors not only among the ones available in the MAFw library, but also in all other packages exposing processors via the plugin mechanism.
All parameters in the constructor are optional.
An instance can be created also without the steering_file, but such an instance cannot be executed. The steering file can be provided in a later stage via the
init()method or directly to therun()method.The user interface can be either provided directly in the constructor, or it will be taken from the steering file. In the worst case, the fallback
ConsoleInterfacewill be used.The plugin manager, if not provided, the global plugin manager will be retrieved from the
get_plugin_manager().A simple example is provided here below:
import logging from pathlib import Path from mafw.runner import MAFwApplication log = logging.getLogger(__name__) # put here your steering file steering_file = Path('path_to_my_steering_file.toml') try: # create the app app = MAFwApplication(steering_file) # run it! app.run() except Exception as e: log.error('An error occurred!') log.exception(e)
Constructor parameters:
- Parameters:
steering_file (Path | str, Optional) – The path to the steering file.
user_interface (UserInterfaceBase | type[UserInterfaceBase] | str, Optional) – The user interface to be used by the application.
plugin_manager (PluginManager, Optional) – The plugin manager.
- get_user_interface(user_interface: str) UserInterfaceBase[source]
Retrieves the user interface from the plugin managers.
User interfaces are exposed via the plugin manager.
If the requested user_interface is not available, then the fallback console interface is used.
- Parameters:
user_interface (str) – The name of the user interface to be used. Normally rich or console.
- init(steering_file: Path | str) None[source]
Initializes the application.
This method is normally automatically invoked by the class constructor. It can be called in a later moment to force the parsing of the provided steering file.
- Parameters:
steering_file (Path | str) – The path to the steering file.
- run(steering_file: Path | str | None = None) ProcessorExitStatus[source]
Runs the application.
This method builds the
ProcessorListwith the processors listed in the steering file and launches its execution.A steering file can be provided at this stage if it was not done before.
- Parameters:
steering_file (Path | str, Optional) – The steering file. Defaults to None.
- Raises:
RunnerNotInitialized – if the application has not been initialized. Very likely a steering file was never provided.
UnknownProcessor – if a processor listed in the steering file is not available in the plugin library.
- exit_status
the exit status of the application
- name
the name of the application instance
- plugin_manager
the plugin manager of the application instance