diff --git a/openfl/federated/__init__.py b/openfl/federated/__init__.py index ea24e0ddfa2..369ca3b54f7 100644 --- a/openfl/federated/__init__.py +++ b/openfl/federated/__init__.py @@ -4,23 +4,23 @@ """openfl.federated package.""" -import importlib +from importlib import util from openfl.federated.data import DataLoader # NOQA from openfl.federated.plan import Plan # NOQA from openfl.federated.task import TaskRunner # NOQA -if importlib.util.find_spec("tensorflow") is not None: +if util.find_spec("tensorflow") is not None: from openfl.federated.data import FederatedDataSet # NOQA from openfl.federated.data import KerasDataLoader, TensorFlowDataLoader from openfl.federated.task import FederatedModel # NOQA from openfl.federated.task import KerasTaskRunner, TensorFlowTaskRunner -if importlib.util.find_spec("torch") is not None: +if util.find_spec("torch") is not None: from openfl.federated.data import FederatedDataSet # NOQA from openfl.federated.data import PyTorchDataLoader from openfl.federated.task import FederatedModel # NOQA from openfl.federated.task import PyTorchTaskRunner -if importlib.util.find_spec("xgboost") is not None: +if util.find_spec("xgboost") is not None: from openfl.federated.data import FederatedDataSet # NOQA from openfl.federated.data import XGBoostDataLoader from openfl.federated.task import FederatedModel # NOQA diff --git a/openfl/federated/data/__init__.py b/openfl/federated/data/__init__.py index 91bb604b62e..67cfcc094e7 100644 --- a/openfl/federated/data/__init__.py +++ b/openfl/federated/data/__init__.py @@ -4,26 +4,26 @@ """Data package.""" -import importlib +from importlib import util from warnings import catch_warnings, simplefilter with catch_warnings(): simplefilter(action="ignore", category=FutureWarning) - if importlib.util.find_spec("tensorflow") is not None: + if util.find_spec("tensorflow") is not None: # ignore deprecation warnings in command-line interface import tensorflow # NOQA from openfl.federated.data.loader import DataLoader # NOQA -if importlib.util.find_spec("tensorflow") is not None: +if util.find_spec("tensorflow") is not None: from openfl.federated.data.federated_data import FederatedDataSet # NOQA from openfl.federated.data.loader_keras import KerasDataLoader # NOQA from openfl.federated.data.loader_tf import TensorFlowDataLoader # NOQA -if importlib.util.find_spec("torch") is not None: +if util.find_spec("torch") is not None: from openfl.federated.data.federated_data import FederatedDataSet # NOQA from openfl.federated.data.loader_pt import PyTorchDataLoader # NOQA -if importlib.util.find_spec("xgboost") is not None: +if util.find_spec("xgboost") is not None: from openfl.federated.data.federated_data import FederatedDataSet # NOQA from openfl.federated.data.loader_xgb import XGBoostDataLoader # NOQA diff --git a/openfl/federated/task/__init__.py b/openfl/federated/task/__init__.py index 8b29264128d..bdb6313e61c 100644 --- a/openfl/federated/task/__init__.py +++ b/openfl/federated/task/__init__.py @@ -4,24 +4,24 @@ """Task package.""" -import importlib +from importlib import util from warnings import catch_warnings, simplefilter with catch_warnings(): simplefilter(action="ignore", category=FutureWarning) - if importlib.util.find_spec("tensorflow") is not None: + if util.find_spec("tensorflow") is not None: # ignore deprecation warnings in command-line interface import tensorflow # NOQA from openfl.federated.task.runner import TaskRunner # NOQA -if importlib.util.find_spec("tensorflow") is not None: +if util.find_spec("tensorflow") is not None: from openfl.federated.task.fl_model import FederatedModel # NOQA from openfl.federated.task.runner_keras import KerasTaskRunner # NOQA from openfl.federated.task.runner_tf import TensorFlowTaskRunner # NOQA -if importlib.util.find_spec("torch") is not None: +if util.find_spec("torch") is not None: from openfl.federated.task.fl_model import FederatedModel # NOQA from openfl.federated.task.runner_pt import PyTorchTaskRunner # NOQA -if importlib.util.find_spec("xgboost") is not None: +if util.find_spec("xgboost") is not None: from openfl.federated.task.fl_model import FederatedModel # NOQA from openfl.federated.task.runner_xgb import XGBoostTaskRunner # NOQA diff --git a/openfl/native/native.py b/openfl/native/native.py index 14c9cda9c94..c9a44cd64f8 100644 --- a/openfl/native/native.py +++ b/openfl/native/native.py @@ -7,11 +7,11 @@ This file defines openfl entrypoints to be used directly through python (not CLI) """ -import importlib import json import logging import os from copy import copy +from importlib import util from logging import basicConfig, getLogger from pathlib import Path from sys import path @@ -164,7 +164,7 @@ def setup_logging(level="INFO", log_file=None): """ # Setup logging - if importlib.util.find_spec("tensorflow") is not None: + if util.find_spec("tensorflow") is not None: import tensorflow as tf # pylint: disable=import-outside-toplevel tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) diff --git a/openfl/pipelines/__init__.py b/openfl/pipelines/__init__.py index f8e7b3e549e..1e549fd3c43 100644 --- a/openfl/pipelines/__init__.py +++ b/openfl/pipelines/__init__.py @@ -1,6 +1,6 @@ # Copyright 2022 VMware, Inc. # SPDX-License-Identifier: Apache-2.0 -import importlib +from importlib import util from openfl.pipelines.kc_pipeline import KCPipeline from openfl.pipelines.no_compression_pipeline import NoCompressionPipeline @@ -9,5 +9,5 @@ from openfl.pipelines.stc_pipeline import STCPipeline from openfl.pipelines.tensor_codec import TensorCodec -if importlib.util.find_spec("torch") is not None: +if util.find_spec("torch") is not None: from openfl.pipelines.eden_pipeline import EdenPipeline # NOQA diff --git a/openfl/utilities/optimizers/keras/__init__.py b/openfl/utilities/optimizers/keras/__init__.py index 39f450df051..2ae100ebcc1 100644 --- a/openfl/utilities/optimizers/keras/__init__.py +++ b/openfl/utilities/optimizers/keras/__init__.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -import importlib +from importlib import util -if importlib.util.find_spec("tensorflow") is not None: +if util.find_spec("tensorflow") is not None: from openfl.utilities.optimizers.keras.fedprox import FedProxOptimizer # NOQA diff --git a/openfl/utilities/optimizers/torch/__init__.py b/openfl/utilities/optimizers/torch/__init__.py index a6cd0c95f6c..77e989cdd40 100644 --- a/openfl/utilities/optimizers/torch/__init__.py +++ b/openfl/utilities/optimizers/torch/__init__.py @@ -3,8 +3,8 @@ """PyTorch optimizers package.""" -import importlib +from importlib import util -if importlib.util.find_spec("torch") is not None: +if util.find_spec("torch") is not None: from openfl.utilities.optimizers.torch.fedprox import FedProxAdam # NOQA from openfl.utilities.optimizers.torch.fedprox import FedProxOptimizer # NOQA