From 62a2913497a866754ae96d57ef445d8cec6e89b2 Mon Sep 17 00:00:00 2001 From: Yuting Jiang Date: Mon, 13 Feb 2023 08:20:07 +0000 Subject: [PATCH] Executor - Support SuperBench Executor running on Windows (#475) **Description** Support SuperBench Executor running on Windows. **Major Revision** - Lazy import ansible related module --- superbench/common/utils/lazy_import.py | 13 +++++++++++++ superbench/runner/__init__.py | 4 +++- superbench/runner/runner.py | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/superbench/common/utils/lazy_import.py b/superbench/common/utils/lazy_import.py index 77df9af3a..a5b3b17ab 100644 --- a/superbench/common/utils/lazy_import.py +++ b/superbench/common/utils/lazy_import.py @@ -50,3 +50,16 @@ def __dir__(self): """ self._import() return dir(self._module) + + def __call__(self, *args, **kwargs): + """Override __call__. + + Args: + *args (list): Arguments. + **kwargs (dict): Keyword arguments. + + Returns: + Any: The return value of the function. + """ + self._import() + return self._module(*args, **kwargs) diff --git a/superbench/runner/__init__.py b/superbench/runner/__init__.py index c6f09561a..9b6c71781 100644 --- a/superbench/runner/__init__.py +++ b/superbench/runner/__init__.py @@ -3,9 +3,11 @@ """SuperBench runner module.""" -from superbench.runner.ansible import AnsibleClient +from superbench.common.utils.lazy_import import LazyImport from superbench.runner.runner import SuperBenchRunner +AnsibleClient = LazyImport('superbench.runner.ansible', 'AnsibleClient') + __all__ = [ 'AnsibleClient', 'SuperBenchRunner', diff --git a/superbench/runner/runner.py b/superbench/runner/runner.py index d2d1f1332..29d114b14 100644 --- a/superbench/runner/runner.py +++ b/superbench/runner/runner.py @@ -16,10 +16,12 @@ from omegaconf import ListConfig, OmegaConf from superbench.common.utils import SuperBenchLogger, logger, gen_ibstat, gen_traffic_pattern_host_groups -from superbench.runner.ansible import AnsibleClient +from superbench.common.utils.lazy_import import LazyImport from superbench.benchmarks import ReduceType, Reducer from superbench.monitor import MonitorRecord +AnsibleClient = LazyImport('superbench.runner.ansible', 'AnsibleClient') + class SuperBenchRunner(): """SuperBench runner class."""