From d440b229b40067562be142a6d6dd48fab94593ff Mon Sep 17 00:00:00 2001 From: yes Date: Thu, 28 Nov 2024 22:55:41 -0800 Subject: [PATCH 1/2] fix for AttributeError: module 'importlib' has no attribute 'util' Signed-off-by: yes --- openfl/federated/__init__.py | 8 ++++---- openfl/federated/data/__init__.py | 10 +++++----- openfl/federated/task/__init__.py | 10 +++++----- openfl/native/native.py | 4 ++-- openfl/pipelines/__init__.py | 4 ++-- openfl/utilities/optimizers/keras/__init__.py | 4 ++-- openfl/utilities/optimizers/torch/__init__.py | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/openfl/federated/__init__.py b/openfl/federated/__init__.py index ea24e0ddfa..71cd12da09 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 91bb604b62..a17501e71c 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 8b29264128..bdb6313e61 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 88b8c5f426..8ee1ed91e9 100644 --- a/openfl/native/native.py +++ b/openfl/native/native.py @@ -7,7 +7,7 @@ This file defines openfl entrypoints to be used directly through python (not CLI) """ -import importlib +from importlib import util import json import logging import os @@ -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 f8e7b3e549..1e549fd3c4 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 39f450df05..2ae100ebcc 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 a6cd0c95f6..77e989cdd4 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 From 0847792f1db881f0d8044e45470508c670148a25 Mon Sep 17 00:00:00 2001 From: yes Date: Fri, 29 Nov 2024 00:53:22 -0800 Subject: [PATCH 2/2] formatting fix Signed-off-by: yes --- openfl/federated/__init__.py | 2 +- openfl/federated/data/__init__.py | 2 +- openfl/native/native.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openfl/federated/__init__.py b/openfl/federated/__init__.py index 71cd12da09..369ca3b54f 100644 --- a/openfl/federated/__init__.py +++ b/openfl/federated/__init__.py @@ -4,7 +4,7 @@ """openfl.federated package.""" -from importlib import util +from importlib import util from openfl.federated.data import DataLoader # NOQA from openfl.federated.plan import Plan # NOQA diff --git a/openfl/federated/data/__init__.py b/openfl/federated/data/__init__.py index a17501e71c..67cfcc094e 100644 --- a/openfl/federated/data/__init__.py +++ b/openfl/federated/data/__init__.py @@ -4,7 +4,7 @@ """Data package.""" -from importlib import util +from importlib import util from warnings import catch_warnings, simplefilter with catch_warnings(): diff --git a/openfl/native/native.py b/openfl/native/native.py index 8ee1ed91e9..c266c73ac8 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) """ -from importlib import util 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