Commit fb41d071 authored by Yanghan Wang's avatar Yanghan Wang Committed by Facebook GitHub Bot
Browse files

add check to `import_runner`

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/450

move checking logic into `import_runner`, simplfy `_is_lightning_task`

Reviewed By: mcimpoi

Differential Revision: D42105853

fbshipit-source-id: 5fd51865a01f2cbac38aaedcac49207c26172ab9
parent 7bed2910
...@@ -40,8 +40,19 @@ def create_runner( ...@@ -40,8 +40,19 @@ def create_runner(
return runner_class(*args, **kwargs) return runner_class(*args, **kwargs)
def import_runner(class_full_name: str) -> Type[Union[BaseRunner, DefaultTask]]: def import_runner(
class_full_name: str, check: bool = True
) -> Type[Union[BaseRunner, DefaultTask]]:
runner_module_name, runner_class_name = class_full_name.rsplit(".", 1) runner_module_name, runner_class_name = class_full_name.rsplit(".", 1)
runner_module = importlib.import_module(runner_module_name) runner_module = importlib.import_module(runner_module_name)
runner_class = getattr(runner_module, runner_class_name) runner_class = getattr(runner_module, runner_class_name)
if check and not (
issubclass(runner_class, BaseRunner) ^ issubclass(runner_class, DefaultTask)
):
raise ValueError(
f"The runner must be subclass of either `BaseRunner` or `DefaultTaks`,"
f" found: {runner_class}"
)
return runner_class return runner_class
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment