From cab7c679ffe255a8e73ab6f01b8faf5bdd4a4579 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Tue, 26 Nov 2024 01:03:29 +1300 Subject: [PATCH] chore: reformat multi-line statements (#60) Refactor some multi-line statements. This was mostly automated by temporarily toggling this control in pyproject.toml: [tool.ruff.format] skip-magic-trailing-comma = true then selecting some commits that condense multi-line statements to single, while rejecting other statements that are better represented over multiple lines. --- autotest/conftest.py | 5 +- autotest/test_interface.py | 10 +--- autotest/test_mf6_examples.py | 3 +- examples/notebooks/Head_Monitor_Example.ipynb | 5 +- modflowapi/extensions/apimodel.py | 17 +----- modflowapi/extensions/data.py | 20 ++----- modflowapi/extensions/pakbase.py | 60 +++---------------- scripts/update_version.py | 12 +--- 8 files changed, 25 insertions(+), 107 deletions(-) diff --git a/autotest/conftest.py b/autotest/conftest.py index 1cb1485..3845255 100644 --- a/autotest/conftest.py +++ b/autotest/conftest.py @@ -99,9 +99,8 @@ def simulation_name_from_model_path(p): for ix in idxs[::-1]: models.append(model_namfiles.pop(ix)) - models += list( - sorted(model_namfiles) - ) # sort remaining models in alphabetical order (gwe < gwt < prt) + # sort remaining models in alphabetical order (gwe < gwt < prt) + models += list(sorted(model_namfiles)) simulations.append(models) print( f"Simulation {model_name} has {len(models)} model(s):\n" diff --git a/autotest/test_interface.py b/autotest/test_interface.py index 7b44006..e7eb336 100644 --- a/autotest/test_interface.py +++ b/autotest/test_interface.py @@ -7,11 +7,7 @@ from modflow_devtools.misc import set_dir from modflowapi import Callbacks, ModflowApi, run_simulation -from modflowapi.extensions.pakbase import ( - AdvancedPackage, - ArrayPackage, - ListPackage, -) +from modflowapi.extensions.pakbase import AdvancedPackage, ArrayPackage, ListPackage data_pth = Path("../examples/data") pytestmark = pytest.mark.extensions @@ -386,9 +382,7 @@ def callback(sim, step): rhs3 = wel.rhs np.testing.assert_allclose( - rhs, - rhs3, - err_msg="set advanced var method not working properly", + rhs, rhs3, err_msg="set advanced var method not working properly" ) npf = model.npf diff --git a/autotest/test_mf6_examples.py b/autotest/test_mf6_examples.py index cdeaa8c..ff0b731 100644 --- a/autotest/test_mf6_examples.py +++ b/autotest/test_mf6_examples.py @@ -28,8 +28,7 @@ def test_mf6_example_simulations(function_tmpdir, mf6_example_namfiles): function_tmpdir = Path(function_tmpdir / "workspace") copytree( - src=namfile.parent.parent if nested else namfile.parent, - dst=function_tmpdir, + src=namfile.parent.parent if nested else namfile.parent, dst=function_tmpdir ) def callback(sim, step): diff --git a/examples/notebooks/Head_Monitor_Example.ipynb b/examples/notebooks/Head_Monitor_Example.ipynb index 32c61bb..d3376c6 100644 --- a/examples/notebooks/Head_Monitor_Example.ipynb +++ b/examples/notebooks/Head_Monitor_Example.ipynb @@ -23,10 +23,7 @@ "import numpy as np\n", "from flopy.discretization import StructuredGrid\n", "from flopy.plot import PlotMapView\n", - "from IPython.display import (\n", - " clear_output,\n", - " display,\n", - ")\n", + "from IPython.display import clear_output, display\n", "\n", "# remove this import if adapted to python script\n", "from modflowapi import Callbacks, run_simulation" diff --git a/modflowapi/extensions/apimodel.py b/modflowapi/extensions/apimodel.py index 761b64e..5008ba6 100644 --- a/modflowapi/extensions/apimodel.py +++ b/modflowapi/extensions/apimodel.py @@ -1,19 +1,8 @@ import numpy as np -from .pakbase import ( - AdvancedPackage, - ArrayPackage, - ListPackage, - package_factory, -) - -gridshape = { - "dis": ["nlay", "nrow", "ncol"], - "disu": [ - "nlay", - "ncpl", - ], -} +from .pakbase import AdvancedPackage, ArrayPackage, ListPackage, package_factory + +gridshape = {"dis": ["nlay", "nrow", "ncol"], "disu": ["nlay", "ncpl"]} class ApiMbase: diff --git a/modflowapi/extensions/data.py b/modflowapi/extensions/data.py index d9a1413..b9bbb60 100644 --- a/modflowapi/extensions/data.py +++ b/modflowapi/extensions/data.py @@ -34,15 +34,9 @@ def __init__(self, parent, var_addrs=None, mf6=None): self._nodevars = ("nodelist", "nexg", "maxats") self._boundvars = ("bound",) - self._maxbound = [ - 0, - ] - self._nbound = [ - 0, - ] - self._naux = [ - 0, - ] + self._maxbound = [0] + self._nbound = [0] + self._naux = [0] self._auxnames = [] self._dtype = [] self._reduced_to_var_addr = {} @@ -432,12 +426,8 @@ def __init__(self, parent, var_addrs=None, mf6=None): self.var_addrs = var_addrs self.mf6 = mf6 - self._maxbound = [ - 0, - ] - self._nbound = [ - 0, - ] + self._maxbound = [0] + self._nbound = [0] self._reduced_to_var_addr = {} self._set_arrays() diff --git a/modflowapi/extensions/pakbase.py b/modflowapi/extensions/pakbase.py index 10ad234..0cf2e12 100644 --- a/modflowapi/extensions/pakbase.py +++ b/modflowapi/extensions/pakbase.py @@ -18,13 +18,7 @@ "nbound", "maxbound", "nodelist", - ( - "bound", - ( - "elev", - "cond", - ), - ), + ("bound", ("elev", "cond")), "naux", "auxname_cst", "auxvar", @@ -33,14 +27,7 @@ "nbound", "maxbound", "nodelist", - ( - "bound", - ( - "surface", - "rate", - "depth", - ), - ), + ("bound", ("surface", "rate", "depth")), # "pxdp:NSEG", "petm:NSEG" "naux", "auxname_cst", @@ -50,13 +37,7 @@ "nbound", "maxbound", "nodelist", - ( - "bound", - ( - "bhead", - "cond", - ), - ), + ("bound", ("bhead", "cond")), "naux", "auxname_cst", "auxvar", @@ -149,15 +130,7 @@ "gwt-gwt": ["nexg", "nodem1", "nodem2", "cl1", "cl2", "ihc", "hwva"], "gwe-gwe": ["nexg", "nodem1", "nodem2", "cl1", "cl2", "ihc", "hwva"], # simulation - "ats": [ - "maxats", - "iperats", - "dt0", - "dtmin", - "dtmax", - "dtadj", - "dtfailadj", - ], + "ats": ["maxats", "iperats", "dt0", "dtmin", "dtmax", "dtadj", "dtfailadj"], "tdis": [ "nper", "itmuni", @@ -194,10 +167,7 @@ "iscl", "iord", ], - "sln-ems": [ - "icnvg", - "ttsoln", - ], + "sln-ems": ["icnvg", "ttsoln"], } @@ -508,12 +478,7 @@ def __setattr__(self, item, value): Method that enables dynamic variable setting and distributes modflow variable storage and updates to the data object class """ - if item in ( - "model", - "pkg_name", - "pkg_type", - "var_addrs", - ): + if item in ("model", "pkg_name", "pkg_type", "var_addrs"): super().__setattr__(item, value) elif item.startswith("_"): @@ -604,12 +569,7 @@ def __setattr__(self, item, value): Method that enables dynamic variable setting and distributes modflow variable storage and updates to the data object class """ - if item in ( - "model", - "pkg_name", - "pkg_type", - "var_addrs", - ): + if item in ("model", "pkg_name", "pkg_type", "var_addrs"): super().__setattr__(item, value) elif item.startswith("_"): @@ -756,10 +716,6 @@ def __init__(self, obj, model, pkg_type, pkg_name, sim_package=False): cls_str = "".join(pkg_type.split("-")) cls_str = f"{cls_str[0].upper()}{cls_str[1:]}" - package = type( - f"Api{cls_str}Package", - (basepackage,), - {"__init__": __init__}, - ) + package = type(f"Api{cls_str}Package", (basepackage,), {"__init__": __init__}) return package diff --git a/scripts/update_version.py b/scripts/update_version.py index 332478b..e49a5a6 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -31,7 +31,7 @@ def update_version_py(timestamp: datetime, version: Version): with open(_version_py_path, "w") as f: f.write( f"# {_project_name} version file automatically " - + f"created using...{basename(__file__)}\n" + f"created using...{basename(__file__)}\n" ) f.write(f"# created on...{timestamp.strftime('%B %d, %Y %H:%M:%S')}\n") f.write(f'__version__ = "{version}"\n') @@ -48,10 +48,7 @@ def update_citation_cff(version: Version): log_update(_citation_cff_path, version) -def update_version( - timestamp: datetime = datetime.now(), - version: Version = None, -): +def update_version(timestamp: datetime = datetime.now(), version: Version = None): lock_path = Path(_version_py_path.name + ".lock") try: lock = FileLock(lock_path) @@ -88,10 +85,7 @@ def update_version( ), ) parser.add_argument( - "-v", - "--version", - required=False, - help="Specify the release version", + "-v", "--version", required=False, help="Specify the release version" ) parser.add_argument( "-g",