def main(): """Invoke where_tools To add a new tool, simply add a new .py-file with a registered plugin that will be called when the tool is called. """ # Start logging log.init(log_level="info") # First read tool from command line, don't use util.parse_args() as that overrides -h for each tool try: tool = [a for a in sys.argv[1:] if not a.startswith("-")][0] sys.argv.remove(tool) except IndexError: util._print_help_from_doc(__name__) raise SystemExit # Check that tool is available and figure out signature try: sig = plugins.signature(__name__, tool) tool_module = plugins.get(__name__, tool).function.__module__ except exceptions.UnknownPluginError as err: util._print_help_from_doc(__name__) err.args = ( f"{err.args[0]}\n Available tools are {', '.join(plugins.names(__name__))}", ) raise # Parse parameters util.check_help_and_version(doc_module=tool_module) tool_args = dict() for key, param in sig.parameters.items(): if param.annotation is None: raise SystemExit(f"{param} in {tool} tool is not annotated") if param.annotation == "datedoy": if util.check_options("--doy"): date = util.parse_args("doy", doc_module=__name__) else: date = util.parse_args("date", doc_module=__name__) tool_args[key] = date elif param.annotation == "pipeline": tool_args[key] = pipelines.get_from_options() config.read_pipeline(tool_args[key]) elif param.annotation == "option": tool_args[key] = util.read_option_value(f"--{key}") else: tool_args[key] = util.parse_args(param.annotation, doc_module=tool_module) # Call tool plugins.call(__name__, tool, **tool_args)
def function(plugin_name: str) -> Callable: """Function creating new field""" return plugins.get(__name__, plugin_name=plugin_name).function