From 537bc991ace0ecf662cd0f8632605f49ef2164c1 Mon Sep 17 00:00:00 2001 From: Tim Brooks <41971846+timryanb@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:27:18 -0500 Subject: [PATCH] flake fixes --- .github/workflows/flake8.yml | 2 +- mphys/core/distributed_summer.py | 1 - mphys/network/remote_component.py | 2 +- mphys/network/server.py | 6 +++--- mphys/utils/docs/_utils/docutil.py | 9 ++++----- mphys/utils/docs/_utils/run_sub.py | 3 +-- mphys/utils/docs/_utils/upload_doc_version.py | 2 -- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index 414097e1..514778f7 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -18,6 +18,6 @@ jobs: # use both MDO Lab standard config - name: Code style (flake8) run: | - pip install flake8==3.9.2 + pip install flake8 wget https://raw.githubusercontent.com/mdolab/.github/master/.flake8 -O .flake8_mdolab python -m flake8 mphys --append-config .flake8_mdolab --count --show-source --statistics \ No newline at end of file diff --git a/mphys/core/distributed_summer.py b/mphys/core/distributed_summer.py index 88e95ada..d9a8b03d 100644 --- a/mphys/core/distributed_summer.py +++ b/mphys/core/distributed_summer.py @@ -1,4 +1,3 @@ -import numpy as np import openmdao.api as om from mphys.core.distributed_converter import DistributedVariableDescription diff --git a/mphys/network/remote_component.py b/mphys/network/remote_component.py index 78e2c287..8928cb88 100644 --- a/mphys/network/remote_component.py +++ b/mphys/network/remote_component.py @@ -295,7 +295,7 @@ def _dump_json(self, remote_dict: dict, command: str): if not os.path.isdir(save_dir): try: os.mkdir(save_dir) - except: + except OSError: pass # may have been created by now, by a parallel server if self._doing_derivative_evaluation(command): filename = f"{save_dir}/{self.name}_{dict_type}_derivative{len(self.times_gradient)}.json" diff --git a/mphys/network/server.py b/mphys/network/server.py index 7c70ef36..16c05ed4 100644 --- a/mphys/network/server.py +++ b/mphys/network/server.py @@ -57,7 +57,7 @@ def _load_the_model(self): self.prob = om.Problem() self.prob.model = self.get_om_group_function_pointer() if self.ignore_setup_warnings: - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): self.prob.setup(mode="rev") else: self.prob.setup(mode="rev") @@ -71,7 +71,7 @@ def _load_the_model(self): def _run_model(self): if self.ignore_runtime_warnings: - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): self.prob.run_model() else: self.prob.run_model() @@ -82,7 +82,7 @@ def _run_model(self): def _compute_totals(self): of, wrt = self._get_derivative_inputs_outputs() if self.ignore_runtime_warnings: - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): self.derivatives = self.prob.compute_totals(of=of, wrt=wrt) else: self.derivatives = self.prob.compute_totals(of=of, wrt=wrt) diff --git a/mphys/utils/docs/_utils/docutil.py b/mphys/utils/docs/_utils/docutil.py index dd944adc..0bad2db4 100644 --- a/mphys/utils/docs/_utils/docutil.py +++ b/mphys/utils/docs/_utils/docutil.py @@ -709,7 +709,7 @@ def dedent(src): lstrip = line.lstrip() if lstrip: # keep going if first line(s) are blank. tab = len(line) - len(lstrip) - return "\n".join(l[tab:] for l in lines[i:]) + return "\n".join(s[tab:] for s in lines[i:]) return "" @@ -764,9 +764,8 @@ def run_code( if cls is None: use_mpi = False else: - try: - import mpi4py - except ImportError: + mpi4py_found = importlib.util.find_spec("mpi4py") is not None + if not mpi4py_found: use_mpi = False else: N_PROCS = getattr(cls, "N_PROCS", 1) @@ -899,7 +898,7 @@ def run_code( except unittest.SkipTest as skip: output = str(skip) skipped = True - except Exception as exc: + except Exception: output = "Running of embedded code {} in docs failed due to: \n\n{}".format( path, traceback.format_exc() ) diff --git a/mphys/utils/docs/_utils/run_sub.py b/mphys/utils/docs/_utils/run_sub.py index ed57a88f..37e1fa20 100644 --- a/mphys/utils/docs/_utils/run_sub.py +++ b/mphys/utils/docs/_utils/run_sub.py @@ -8,11 +8,10 @@ import sys import traceback -import numpy as np from openmdao.utils.general_utils import printoptions if __name__ == "__main__": - import openmdao.utils.mpi # this will activate use_proc_files + import openmdao.utils.mpi # noqa: F401, this will activate use_proc_files try: module_path = os.environ.get("OPENMDAO_CURRENT_MODULE", "").strip() diff --git a/mphys/utils/docs/_utils/upload_doc_version.py b/mphys/utils/docs/_utils/upload_doc_version.py index 63928505..077d8d62 100644 --- a/mphys/utils/docs/_utils/upload_doc_version.py +++ b/mphys/utils/docs/_utils/upload_doc_version.py @@ -1,5 +1,3 @@ -import os -import pipes import subprocess import sys