From 0b912dd526556782839c3dda5811634cb50beea6 Mon Sep 17 00:00:00 2001 From: Keith Beattie Date: Tue, 19 Nov 2024 16:57:20 -0800 Subject: [PATCH] First pass at removing wildcard imports --- .github/actions/pylint/action.yml | 2 +- foqus_lib/foqus.py | 12 +++++++++--- foqus_lib/framework/foqusOptions/optionList.py | 2 +- foqus_lib/framework/optimizer/SM_Optimizer.py | 11 ++++------- foqus_lib/framework/optimizer/optimization.py | 2 -- foqus_lib/framework/pymodel/matlab_fs.py | 2 +- foqus_lib/framework/pymodel/pymodel.py | 2 -- foqus_lib/unit_test/massBalance_test.py | 4 ++-- foqus_lib/unit_test/nodeVarList_test.py | 5 ++++- foqus_lib/unit_test/nodeVars_test.py | 2 +- foqus_lib/unit_test/turbineLite_test.py | 3 --- 11 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.github/actions/pylint/action.yml b/.github/actions/pylint/action.yml index cd3c74143..8ad76c11b 100644 --- a/.github/actions/pylint/action.yml +++ b/.github/actions/pylint/action.yml @@ -15,6 +15,6 @@ runs: shell: bash run: | echo '::group::Output of pylint' - pylint --rcfile=.pylint/pylintrc --disable=all --enable=E --enable=wrong-import-order,unused-import foqus_lib/ + pylint --rcfile=.pylint/pylintrc --disable=all --enable=E --enable=wrong-import-order,unused-import,wildcard-import foqus_lib/ echo '::endgroup::' diff --git a/foqus_lib/foqus.py b/foqus_lib/foqus.py index d1d7b8286..0fe87635b 100644 --- a/foqus_lib/foqus.py +++ b/foqus_lib/foqus.py @@ -20,11 +20,12 @@ Keith Beattie, Lawrence Berkeley National Labs, 2020 """ +# Imports import argparse import json import logging - -# Imports +import os +import shutil import signal import sys import time @@ -34,7 +35,12 @@ # FOQUS imports import foqus_lib.version.version as ver # foqus version and other info from foqus_lib.framework.listen.listen import foqusListener2 -from foqus_lib.framework.session.session import * +from foqus_lib.framework.session.session import ( + generalSettings, + makeWorkingDirStruct, + makeWorkingDirFiles, + session, +) from foqus_lib.gui.make_shortcut import makeShortcut loadGUI = False diff --git a/foqus_lib/framework/foqusOptions/optionList.py b/foqus_lib/framework/foqusOptions/optionList.py index 713f88a45..5aaba5149 100644 --- a/foqus_lib/framework/foqusOptions/optionList.py +++ b/foqus_lib/framework/foqusOptions/optionList.py @@ -20,7 +20,7 @@ John Eslick, Carnegie Mellon University, 2014 """ -from foqus_lib.framework.foqusOptions.option import * +from foqus_lib.framework.foqusOptions.option import option class optionList(dict): diff --git a/foqus_lib/framework/optimizer/SM_Optimizer.py b/foqus_lib/framework/optimizer/SM_Optimizer.py index 4c75f16fb..0c218f6ce 100644 --- a/foqus_lib/framework/optimizer/SM_Optimizer.py +++ b/foqus_lib/framework/optimizer/SM_Optimizer.py @@ -43,10 +43,7 @@ # Check that the required pyomo, pyDOE, and smt packages are available for the surrogate based optimization plugin and import it. # If not the Surrogate Based Optimization plug-in will not be available. - try: - # add direct imports (in addition to existing wildcard import) - # to make pylint happy without affecting the existing runtime behavior import pyutilib.subprocess.GlobalData from pyomo.environ import ( ConstraintList, @@ -57,13 +54,13 @@ from pyomo.opt import SolverFactory pyutilib.subprocess.GlobalData.DEFINE_SIGNAL_HANDLERS_DEFAULT = False - from pyDOE import * + import pyDOE # pylint: disable=unused-import from smt.sampling_methods import LHS packages_available = True -except ImportError: - logging.getLogger("foqus." + __name__).info( - "Failed to import the required packages for SM Optimizer solver" +except ImportError as ie: + logging.getLogger("foqus." + __name__).warn( + "Failed to import the required packages for SM Optimizer solver: " + str(ie) ) packages_available = False diff --git a/foqus_lib/framework/optimizer/optimization.py b/foqus_lib/framework/optimizer/optimization.py index c23890b62..01b7a565c 100644 --- a/foqus_lib/framework/optimizer/optimization.py +++ b/foqus_lib/framework/optimizer/optimization.py @@ -25,8 +25,6 @@ from foqus_lib.framework.foqusOptions.optionList import optionList -from .problem import * - class optimization(threading.Thread): """ diff --git a/foqus_lib/framework/pymodel/matlab_fs.py b/foqus_lib/framework/pymodel/matlab_fs.py index 8b5d74f73..db4c754d5 100644 --- a/foqus_lib/framework/pymodel/matlab_fs.py +++ b/foqus_lib/framework/pymodel/matlab_fs.py @@ -17,7 +17,7 @@ import subprocess import time -from foqus_lib.framework.pymodel.pymodel import * +from foqus_lib.framework.pymodel.pymodel import pymodel # Check that the MATLAB engine module is available and import it if possible. # If not the MATLAB plug-in cannot be used. diff --git a/foqus_lib/framework/pymodel/pymodel.py b/foqus_lib/framework/pymodel/pymodel.py index 4190ecfd2..25b49ac72 100644 --- a/foqus_lib/framework/pymodel/pymodel.py +++ b/foqus_lib/framework/pymodel/pymodel.py @@ -14,8 +14,6 @@ ################################################################################# from collections import OrderedDict -from foqus_lib.framework.graph.nodeVars import * - class pymodel: def __init__(self): diff --git a/foqus_lib/unit_test/massBalance_test.py b/foqus_lib/unit_test/massBalance_test.py index 9c6bbde9c..25bf4b047 100644 --- a/foqus_lib/unit_test/massBalance_test.py +++ b/foqus_lib/unit_test/massBalance_test.py @@ -15,9 +15,9 @@ import json import os import unittest +import numpy -from foqus_lib.framework.graph.graph import * - +from foqus_lib.framework.graph.graph import Graph class testMassBalance(unittest.TestCase): def loadGraph(self, fname): diff --git a/foqus_lib/unit_test/nodeVarList_test.py b/foqus_lib/unit_test/nodeVarList_test.py index 7883a6ae5..e1aa68d5c 100644 --- a/foqus_lib/unit_test/nodeVarList_test.py +++ b/foqus_lib/unit_test/nodeVarList_test.py @@ -14,7 +14,10 @@ ################################################################################# import unittest -from foqus_lib.framework.graph.nodeVars import * +from foqus_lib.framework.graph.nodeVars import ( + NodeVarList, + NodeVars, +) class testNodeVarListSteady(unittest.TestCase): diff --git a/foqus_lib/unit_test/nodeVars_test.py b/foqus_lib/unit_test/nodeVars_test.py index 073ac6fa0..8c9d73358 100644 --- a/foqus_lib/unit_test/nodeVars_test.py +++ b/foqus_lib/unit_test/nodeVars_test.py @@ -16,7 +16,7 @@ import json import unittest -from foqus_lib.framework.graph.nodeVars import * +from foqus_lib.framework.graph.nodeVars import NodeVars class testNodeVarsSteady(unittest.TestCase): diff --git a/foqus_lib/unit_test/turbineLite_test.py b/foqus_lib/unit_test/turbineLite_test.py index 4006298f7..bfb9b84d6 100644 --- a/foqus_lib/unit_test/turbineLite_test.py +++ b/foqus_lib/unit_test/turbineLite_test.py @@ -14,8 +14,5 @@ ################################################################################# import unittest -from foqus_lib.framework.sim.turbineConfiguration import * - - class turbineLiteTest(unittest.TestCase): pass