Skip to content

Commit

Permalink
chore: reformat multi-line statements (#60)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mwtoews authored Nov 25, 2024
1 parent 1b408be commit cab7c67
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 107 deletions.
5 changes: 2 additions & 3 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 2 additions & 8 deletions autotest/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions autotest/test_mf6_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions examples/notebooks/Head_Monitor_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 3 additions & 14 deletions modflowapi/extensions/apimodel.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
20 changes: 5 additions & 15 deletions modflowapi/extensions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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()

Expand Down
60 changes: 8 additions & 52 deletions modflowapi/extensions/pakbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
"nbound",
"maxbound",
"nodelist",
(
"bound",
(
"elev",
"cond",
),
),
("bound", ("elev", "cond")),
"naux",
"auxname_cst",
"auxvar",
Expand All @@ -33,14 +27,7 @@
"nbound",
"maxbound",
"nodelist",
(
"bound",
(
"surface",
"rate",
"depth",
),
),
("bound", ("surface", "rate", "depth")),
# "pxdp:NSEG", "petm:NSEG"
"naux",
"auxname_cst",
Expand All @@ -50,13 +37,7 @@
"nbound",
"maxbound",
"nodelist",
(
"bound",
(
"bhead",
"cond",
),
),
("bound", ("bhead", "cond")),
"naux",
"auxname_cst",
"auxvar",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -194,10 +167,7 @@
"iscl",
"iord",
],
"sln-ems": [
"icnvg",
"ttsoln",
],
"sln-ems": ["icnvg", "ttsoln"],
}


Expand Down Expand Up @@ -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("_"):
Expand Down Expand Up @@ -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("_"):
Expand Down Expand Up @@ -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
12 changes: 3 additions & 9 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit cab7c67

Please sign in to comment.