bluemira.codes.utilities ======================== .. py:module:: bluemira.codes.utilities .. autoapi-nested-parse:: Utility functions for interacting with external codes Classes ------- .. autoapisummary:: bluemira.codes.utilities.Model bluemira.codes.utilities.LogPipe Functions --------- .. autoapisummary:: bluemira.codes.utilities.read_mock_json_or_raise bluemira.codes.utilities.get_code_interface bluemira.codes.utilities.is_code_available bluemira.codes.utilities.code_guard bluemira.codes.utilities.create_mapping bluemira.codes.utilities.run_subprocess Module Contents --------------- .. py:class:: Model(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: bluemira.codes.utilities.Model :parts: 1 :private-bases: Base Model Enum .. py:method:: info() :classmethod: Show Model options .. py:method:: _missing_(value) :classmethod: .. py:function:: read_mock_json_or_raise(file_path: str, name: str) -> dict[str, float] Read json file or raise CodesError :raises CodesError: Cannot open mock file .. py:function:: get_code_interface(module: str) -> types.ModuleType Dynamically import code interface :param module: module to import :returns: Code module .. py:function:: is_code_available(code_module: str) -> bool Check if a code is available :param code_module: The name of the code module to check. :returns: True if the code is available, False otherwise. .. py:function:: code_guard(code_module: str, add_message: str = '') Import guard for a code at runtime. :param code_module: The name of the code module to check. :raises ImportError: If the code is not available (installed). .. py:function:: create_mapping(in_mappings=None, out_mappings=None, io_mappings=None, none_mappings=None) -> dict[str, Any] Creates mappings for external codes :returns: A mapping from bluemira names to an external code ParameterMapping .. py:class:: LogPipe(loglevel: str, flush_callable: collections.abc.Callable[[str], bool] = lambda line: False, flush_printer: collections.abc.Callable[[str], None] | None = None) Bases: :py:obj:`threading.Thread` .. autoapi-inheritance-diagram:: bluemira.codes.utilities.LogPipe :parts: 1 :private-bases: Capture logs for subprocesses https://codereview.stackexchange.com/questions/6567/redirecting-subprocesses-output-stdout-and-stderr-to-the-logging-module :param loglevel: print or error flush printing .. py:attribute:: logfunc .. py:attribute:: logfunc_flush .. py:attribute:: flush_callable .. py:attribute:: pipe .. py:method:: fileno() :returns: The write file descriptor of the pipe .. py:method:: run() Run the thread and pipe it all into the logger. .. py:method:: close() Close the write end of the pipe. .. py:function:: run_subprocess(command: list[str], run_directory: str = '.', flush_callable: collections.abc.Callable[[str], bool] = lambda line: False, flush_printer: collections.abc.Callable[[str], None] | None = None, **kwargs) -> int Run a subprocess terminal command piping the output into bluemira's logs. :param command: The arguments of the command to run. :param run_directory: The directory to run the command in. Default is current working directory. :param \*\*kwargs: Arguments passed directly to subprocess.Popen. :returns: **return_code** -- The return code of the subprocess. :rtype: int