def read_bbarfile(bbarfile_path, overrides): debug(f"Using bbarfile \"{bbarfile_path}\"", condition=bbarfile_path) bbarfile_path = bbarfile_path or default_bbarfile_name debug(f"Command line override parameters: {overrides}", condition=overrides) check_valid_file(bbarfile_path) defaults = toml.loads(bbarfile_defaults) try: bbarfile_data = toml.load(bbarfile_path) bbarfile_data = deep_dict_union(defaults, bbarfile_data) bbarfile_data = apply_user_overrides(bbarfile_data, overrides) bset = BBAR_Project(bbarfile_data) if not bset.initialized: raise ("Unknown error") except toml.decoder.TomlDecodeError as e: raise BBARFile_Error( f"Error parsing bbarfile TOML in \"{bbarfile_path}\":\n\t{e}") except Exception as e: raise (e) #raise BBARFile_Error(f"Error reading or parsing bbarfile \"{bbarfile_path}\":\n\t{e}") return bset
def __init__(self, storage_path=default_storage_path): if storage_path is not None: self.storage_path = storage_path if os.path.isfile(self.storage_path): debug(f"Loading {self.storage_path}") self.state = toml.load(self.storage_path) else: self.state = {}
def on_analyze(self): debug("Analyzing output files.")
def on_scan(self): debug("Scanning for SLURM output files.") self.bbar_project.scan_for_results()
def on_enter_completed(self): self.store.set_status(self.current_state.value) debug("Status set to completed")
def on_enter_running(self): self.store.set_status(self.current_state.value) debug("Status set to running")
def on_enter_generated(self): self.store.set_status(self.current_state.value) debug("Status set to generated")
def on_enter_init(self): self.store.set_status(self.current_state.value) debug("Status set to init")
def decorator(metric): debug(f"Registering metric {name}") _PLUGINS[system_plugin_importpath][name] = MetricPlugin(name=name, metric=metric) return metric
def get_metric(name, importpath=system_metrics_plugin_importpath): """Get a given plugin""" debug(f"Trying to register metric {importpath}.{name}") importlib.import_module(f"{importpath}.{name}") return _METRICS[importpath][name].metric
def get_report(name, importpath=system_reports_plugin_importpath): """Get a given plugin""" debug(f"Trying to register report {importpath}.{name}") importlib.import_module(f"{importpath}.{name}") return _ANALYZER_PLUGINS[importpath][name].report
def decorator(report): debug(f"Registering report {name}") _PLUGINS[system_plugin_importpath][name] = ReportPlugin(name=name, report=report) return report
def get(name, importpath=system_plugin_importpath): """Get a given plugin""" debug(f"Trying to register scheduler {importpath}.{name}") importlib.import_module(f"{importpath}.{name}") return _PLUGINS[importpath][name].scheduler
def decorator(scheduler): debug(f"Registering scheduler {name}") _PLUGINS[system_plugin_importpath][name] = SchedulerPlugin( name=name, scheduler=scheduler) return scheduler
import importlib from collections import namedtuple from bbar.logging import debug debug(f"plugin __file__: {__file__}") SchedulerPlugin = namedtuple("Plugin", ("name", "scheduler")) system_plugin_importpath = "bbar.scheduler" _PLUGINS = {system_plugin_importpath: {}} def register_scheduler(name): """Decorator factory for registering a new plugin""" def decorator(scheduler): debug(f"Registering scheduler {name}") _PLUGINS[system_plugin_importpath][name] = SchedulerPlugin( name=name, scheduler=scheduler) return scheduler return decorator def register_custom_scheduler(name): """Decorator factory for registering user plugins """ #Not implemented yet, checkout https://realpython.com/python-import/#example-a-package-of-plugins pass def list_plugins(): """List all plugins""" return sorted(list(_PLUGINS))