Generic method of calling a SimpleITK Example 'main' routine Run the specified func_name on the module_name Example and pass it the provided args to it. :param module_name: name of the Example module :param func_name: name of the module_name function to call :param args: list o
(module_name: str, func_name: str, args: list)
| 47 | |
| 48 | |
| 49 | def run_example(module_name: str, func_name: str, args: list) -> dict: |
| 50 | """Generic method of calling a SimpleITK Example 'main' routine |
| 51 | |
| 52 | Run the specified func_name on the module_name Example and |
| 53 | pass it the provided args to it. |
| 54 | |
| 55 | :param module_name: name of the Example module |
| 56 | :param func_name: name of the module_name function to call |
| 57 | :param args: list of arguments to pass to func_name |
| 58 | :return: A dictionary of keywords to Images |
| 59 | """ |
| 60 | |
| 61 | with set_directory(f"../../Examples/"): |
| 62 | try: |
| 63 | example_module = importlib.import_module(f"{module_name}.{module_name}") |
| 64 | except (ImportError,) as ex: |
| 65 | raise ValueError( |
| 66 | f"Unknown module: {module_name}.{module_name} current directory {os.getcwd()}" |
| 67 | ) from ex |
| 68 | |
| 69 | try: |
| 70 | main_func = getattr(example_module, func_name) |
| 71 | except AttributeError: |
| 72 | raise RuntimeError( |
| 73 | f"Unknown attribute: {func_name} in {example_module} --- {example_module.__path__}" |
| 74 | ) |
| 75 | |
| 76 | args.insert(0, module_name) |
| 77 | return_dict = main_func(args) |
| 78 | |
| 79 | return return_dict |
nothing calls this directly
no test coverage detected