Skip to content

Commit

Permalink
Fix for 'importlib' has no attribute 'util' (#1180)
Browse files Browse the repository at this point in the history
* fix for AttributeError: module 'importlib' has no attribute 'util'

Signed-off-by: yes <[email protected]>

* formatting fix

Signed-off-by: yes <[email protected]>

---------

Signed-off-by: yes <[email protected]>
  • Loading branch information
tanwarsh authored Nov 30, 2024
1 parent a26bdb2 commit c25d144
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions openfl/federated/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions openfl/federated/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions openfl/federated/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions openfl/native/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions openfl/pipelines/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions openfl/utilities/optimizers/keras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions openfl/utilities/optimizers/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c25d144

Please sign in to comment.