def func(f): if not sphinx_doc(): return f full_cmd = f.__name__.replace("__", " ") if not f.__doc__: f.__doc__ = "" f.__doc__ += """ .. role:: python(code) :language: python :Command: ``{full_cmd}`` :Description: {description} """.format(full_cmd=full_cmd, description=description) if argument: f.__doc__ += """ :Argument: {argument} """.format(argument=argument) if len(options) > 0: f.__doc__ += """ **Options**: {options} """.format(options="\n ".join(options_str.split("\n"))) return f
def func(f): if not sphinx_doc(): return f full_cmd = f.__name__.replace("__", " ") if not f.__doc__: f.__doc__ = "" f.__doc__ += """ .. role:: python(code) :language: python :Command: ``{full_cmd}`` :Description: {description} """.format(full_cmd=full_cmd, description=description) if argument: f.__doc__ += """ :Argument: {argument} """.format(argument=argument) if len(options) > 0: f.__doc__ += """ **Options**: {options} """.format(options="\n ".join(options_str.split("\n"))) return f
def _update_doc(self): """ Update the class documentation """ if sphinx_doc(): self.__doc__ = self.__doc__.split( ".. code: yaml")[0] + """.. code: yaml """ + "\n ".join( self.type_scheme.get_default_yaml().split("\n"))
def register(cls, name: str, klass: type, misc_type: Type): assert issubclass(klass, AbstractRunDriver) super().register(name, klass, misc_type) if not sphinx_doc(): return klass.__doc__ += """ Block configuration format for the run configuration: .. code-block:: yaml {yaml} """.format(yaml="\n ".join(klass.block_type_scheme.string_representation().split("\n")))
def register(cls, name: str, klass: type, misc_type: Type): assert issubclass(klass, AbstractRunDriver) super().register(name, klass, misc_type) if not sphinx_doc(): return klass.__doc__ += """ Block configuration format for the run configuration: .. code-block:: yaml {yaml} """.format(yaml="\n ".join( klass.block_type_scheme.string_representation().split("\n")))
except TypeError as err: logging.error(err) import traceback logging.debug("".join( traceback.format_exception(None, err, err.__traceback__))) exit(1) @cli.command(short_help=command_docs["setup"]) @cmd_option(misc_commands["setup"]) def setup(**kwargs): temci__setup(**kwargs) @document_func(command_docs["setup"], misc_commands["setup"]) def temci__setup(build_kernel_modules: bool): from temci.setup.setup import make_scripts make_scripts(build_kernel_modules) if sphinx_doc(): Settings.__doc__ += """ The whole configuration file has the following structure: """ + get_doc_for_type_scheme(Settings().type_scheme) if __name__ == "__main__": # for testing purposes only cli()
def register(cls, name: str, klass: type, misc_type: Type, activate_by_default: bool = None, deprecated: bool = False): """ Registers a new class. The constructor of the class gets as first argument the misc settings. :param name: common name of the registered class :param klass: actual class :param misc_type: type scheme of the {name}_misc settings :param misc_default: default value of the {name}_misc settings :param deprecated: is the registered class deprecated and should not be used? """ if deprecated: Settings().get_type_scheme( cls.settings_key_path).unknown_keys = True return def format_str_list(val: t.List[str], sep: str = "and") -> str: return join_strs(list(map(repr, val)), sep) misc_type_empty = misc_type == Dict() or misc_type == Dict({}) misc_default = misc_type.get_default() description = None use_key_path = "/".join([cls.settings_key_path, cls.use_key]) misc_key = "{}_misc".format("/".join([cls.settings_key_path, name])) if klass.__doc__ is not None: header = "" # "Description of {} (class {}):\n".format(name, klass.__qualname__) lines = str(klass.__doc__.strip()).split("\n") lines = map(lambda x: " " + x.strip(), lines) description = Description(header + "\n".join(lines)) klass.__description__ = description.description misc_type //= description else: klass.__description__ = "" logging.error("Class level documentation for {} is missing".format( klass.__name__)) Settings().modify_setting(misc_key, misc_type) if cls.use_list: if not Settings().validate_key_path(use_key_path.split("/")) \ or isinstance(Settings().get_type_scheme(use_key_path), Any): use_key_type = (StrList() | Exact(name)) use_key_type.typecheck_default = False Settings().modify_setting( use_key_path, use_key_type // Default(cls.default) if cls.default is not None else use_key_type) else: use_key_list = Settings().get_type_scheme(use_key_path) assert isinstance(use_key_list, StrList) use_key_list |= Exact(name) use_key_list = Settings().get_type_scheme(use_key_path) use_key_list // Description("Possible {} are {}".format( cls.plugin_synonym[1], format_str_list(use_key_list.allowed_values))) active_path = "{}_active".format("/".join( [cls.settings_key_path, name])) if not Settings().validate_key_path(active_path.split("/")): Settings().modify_setting( active_path, BoolOrNone() // Default(activate_by_default)) Settings().get_type_scheme(active_path) // Description( "Enable: " + klass.__description__) else: if not Settings().validate_key_path(use_key_path.split("/")) \ or not isinstance(Settings().get_type_scheme(use_key_path), ExactEither): use_key_type = ExactEither(name) use_key_type.typecheck_default = False Settings().modify_setting( use_key_path, use_key_type // Default(cls.default) if cls.default else use_key_type) else: Settings().modify_setting( use_key_path, Settings().get_type_scheme(use_key_path) | Exact(name)) use_key_type = Settings().get_type_scheme(use_key_path) use_key_type // Description("Possible {} are {}".format( cls.plugin_synonym[1], format_str_list( use_key_type.exp_values))) cls.registry[name] = klass if not sphinx_doc(): return use_text = "" cls_use_text = "" if cls.use_list: use_text = "To use this {plugin} add its name (`{name}`) to the list at settings key `{key}` or " \ "set `{active}` to true."\ .format(plugin=cls.plugin_synonym[0], name=name, key=use_key_path, active="{}_active".format("/".join([cls.settings_key_path, name]))) cls_use_text = "The used {plugins} can be configured by editing the list under the settings key `{key}`."\ .format(plugins=cls.plugin_synonym[1], key=use_key_path) else: use_text = "To use this {plugin} set the currently used {plugin} (at key `{key}`) to its name (`{name}`)."\ .format(plugin=cls.plugin_synonym[0], name=name, key=use_key_path) cls_use_text = "The used {plugin} can be configured by editing the settings key `{key}`."\ .format(plugin=cls.plugin_synonym[0], key=use_key_path) other_plugins_text = "" used_type = Settings().get_type_scheme(use_key_path) possible_plugins = used_type.allowed_values if cls.use_list else used_type.exp_values # type: t.List[str] possbible_p_wo_self = [x for x in possible_plugins if x != name] if len(possible_plugins) == 2: other_plugins_text = "Another usable {plugin} is `{p}`.".format( plugin=cls.plugin_synonym[0], p=possbible_p_wo_self[0]) if len(possible_plugins) > 2: other_plugins_text = "Other usable {plugins} are {p}.".format( plugins=cls.plugin_synonym[1], p=join_strs(["`{}`".format(x) for x in possbible_p_wo_self])) default_plugins_text = "" if cls.default: if cls.use_list and len(cls.default) > 1: p = join_strs(["`{}`".format(x) for x in cls.default]) default_plugins_text = "The default {plugins} are {p}.".format( plugins=cls.plugin_synonym[1], p=p) else: default = cls.default[0] if cls.use_list else cls.default default_plugins_text = "The default {plugin} is `{p}`.".format( plugin=cls.plugin_synonym[0], p=default) if not misc_type_empty: klass.__doc__ += """ Configuration format: .. code-block:: yaml {default_yaml} This {plugin} can be configured under the settings key `{misc_key}`. """.format(default_yaml="\n ".join( misc_type.get_default_yaml().split("\n")), misc_key=misc_key, plugin=cls.plugin_synonym[0]) klass.__doc__ += """ {use_text} {other} {default} """.format(use_text=use_text, other=other_plugins_text, default=default_plugins_text) if not hasattr(cls, "__old_documentation__"): cls.__old_documentation__ = cls.__doc__ or "" cls.__doc__ = cls.__old_documentation__ cls.__doc__ += """ {use_text} {possible} """.format(use_text=cls_use_text, possible=Settings().get_type_scheme(use_key_path).description)
exit(1) @cli.command(short_help=command_docs["setup"]) def setup(): temci__setup() @document_func(command_docs["setup"]) def temci__setup(): from temci.setup.setup import make_scripts make_scripts() if sphinx_doc(): Settings.__doc__ += """ The whole configuration file has the following structure: """ + get_doc_for_type_scheme( Settings().type_scheme ) if __name__ == "__main__": # for testing purposes only sys.argv[1:] = ["short", "exec", "-wd", "ls", "--max_runs", "120", "--min_runs", "100"] # sys.argv[1:] = ["exec", "-wd", "ls", "-wd", "ls ..", "-wd", "ls /tmp", "--min_runs", "5", "--max_runs", "5", # "--out", "ls_100.yaml", "--stop_start"]
def register(cls, name: str, klass: type, misc_type: Type): """ Registers a new class. The constructor of the class gets as first argument the misc settings. :param name: common name of the registered class :param klass: actual class :param misc_type: type scheme of the {name}_misc settings :param misc_default: default value of the {name}_misc settings """ def format_str_list(val: t.List[str], sep: str = "and") -> str: return join_strs(list(map(repr, val)), sep) misc_type_empty = misc_type == Dict() or misc_type == Dict({}) misc_default = misc_type.get_default() description = None use_key_path = "/".join([cls.settings_key_path, cls.use_key]) misc_key = "{}_misc".format("/".join([cls.settings_key_path, name])) if klass.__doc__ is not None: header = ""# "Description of {} (class {}):\n".format(name, klass.__qualname__) lines = str(klass.__doc__.strip()).split("\n") lines = map(lambda x: " " + x.strip(), lines) description = Description(header + "\n".join(lines)) klass.__description__ = description.description misc_type //= description else: klass.__description__ = "" logging.error("Class level documentation for {} is missing".format(klass.__name__)) Settings().modify_setting(misc_key, misc_type) if cls.use_list: if not Settings().validate_key_path(use_key_path.split("/")) \ or isinstance(Settings().get_type_scheme(use_key_path), Any): use_key_type = (StrList() | Exact(name)) use_key_type.typecheck_default = False Settings().modify_setting(use_key_path, use_key_type // Default(cls.default) if cls.default else use_key_type) else: use_key_list = Settings().get_type_scheme(use_key_path) assert isinstance(use_key_list, StrList) use_key_list |= Exact(name) use_key_list = Settings().get_type_scheme(use_key_path) use_key_list // Description("Possible {} are {}".format(cls.plugin_synonym[1], format_str_list(use_key_list.allowed_values))) active_path = "{}_active".format("/".join([cls.settings_key_path, name])) if not Settings().validate_key_path(active_path.split("/")): Settings().modify_setting(active_path, BoolOrNone() // Default(None)) Settings().get_type_scheme(active_path) // Description("Enable: " + klass.__description__) else: if not Settings().validate_key_path(use_key_path.split("/")) \ or not isinstance(Settings().get_type_scheme(use_key_path), ExactEither): use_key_type = ExactEither(name) use_key_type.typecheck_default = False Settings().modify_setting(use_key_path, use_key_type // Default(cls.default) if cls.default else use_key_type) else: Settings().modify_setting(use_key_path, Settings().get_type_scheme(use_key_path) | Exact(name)) use_key_type = Settings().get_type_scheme(use_key_path) use_key_type // Description("Possible {} are {}".format(cls.plugin_synonym[1], format_str_list(use_key_type.exp_values))) cls.registry[name] = klass if not sphinx_doc(): return use_text = "" cls_use_text = "" if cls.use_list: use_text = "To use this {plugin} add it's name (`{name}`) to the list at settings key `{key}` or " \ "set `{active}` to true."\ .format(plugin=cls.plugin_synonym[0], name=name, key=use_key_path, active="{}_active".format("/".join([cls.settings_key_path, name]))) cls_use_text = "The used {plugins} can be configured by editing the list under the settings key `{key}`."\ .format(plugins=cls.plugin_synonym[1], key=use_key_path) else: use_text = "To use this {plugin} set the currently used {plugin} (at key `{key}`) to its name (`{name}`)."\ .format(plugin=cls.plugin_synonym[0], name=name, key=use_key_path) cls_use_text = "The used {plugin} can be configured by editing the settings key `{key}`."\ .format(plugin=cls.plugin_synonym[0], key=use_key_path) other_plugins_text = "" used_type = Settings().get_type_scheme(use_key_path) possible_plugins = used_type.allowed_values if cls.use_list else used_type.exp_values # type: t.List[str] possbible_p_wo_self = [x for x in possible_plugins if x != name] if len(possible_plugins) == 2: other_plugins_text = "Another usable {plugin} is `{p}`.".format(plugin=cls.plugin_synonym[0], p=possbible_p_wo_self[0]) if len(possible_plugins) > 2: other_plugins_text = "Other usable {plugins} are {p}.".format(plugins=cls.plugin_synonym[1], p=join_strs(["`{}`".format(x) for x in possbible_p_wo_self])) default_plugins_text = "" if cls.default: if cls.use_list and len(cls.default) > 1: p = join_strs(["`{}`".format(x) for x in cls.default]) default_plugins_text = "The default {plugins} are {p}.".format(plugins=cls.plugin_synonym[1], p=p) else: default = cls.default[0] if cls.use_list else cls.default default_plugins_text = "The default {plugin} is `{p}`.".format(plugin=cls.plugin_synonym[0], p=default) if not misc_type_empty: klass.__doc__ += """ Configuration format: .. code-block:: yaml {default_yaml} This {plugin} can be configured under the settings key `{misc_key}`. """.format(default_yaml="\n ".join(misc_type.get_default_yaml().split("\n")), misc_key=misc_key, plugin=cls.plugin_synonym[0]) klass.__doc__ += """ {use_text} {other} {default} """.format(use_text=use_text, other=other_plugins_text, default=default_plugins_text) if not hasattr(cls, "__old_documentation__"): cls.__old_documentation__ = cls.__doc__ or "" cls.__doc__ = cls.__old_documentation__ cls.__doc__ += """ {use_text} {possible} """.format( use_text=cls_use_text, possible=Settings().get_type_scheme(use_key_path).description )