Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 'importlib' has no attribute 'util' #1180

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading