Skip to content

Commit

Permalink
refactor: fix long lines to resolve check E501 (#2368)
Browse files Browse the repository at this point in the history
This refactor resolves long line checks. See ruff check code E501 for more.
  • Loading branch information
mwtoews authored Nov 14, 2024
1 parent 12a3bcd commit bb9824e
Show file tree
Hide file tree
Showing 59 changed files with 255 additions and 161 deletions.
14 changes: 8 additions & 6 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def close_plot(request):

@pytest.fixture(scope="session", autouse=True)
def patch_macos_ci_matplotlib():
# use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure
# e.g. https://github.com/modflowpy/flopy/runs/7748574375?check_suite_focus=true#step:9:57
# use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist
# node failure
if is_in_ci() and system().lower() == "darwin":
import matplotlib

Expand All @@ -86,7 +86,7 @@ def patch_macos_ci_matplotlib():
def pytest_runtest_makereport(item, call):
# this is necessary so temp dir fixtures can
# inspect test results and check for failure
# (see https://doc.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures)
# (see https://doc.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures) # noqa

outcome = yield
rep = outcome.get_result()
Expand All @@ -101,16 +101,18 @@ def pytest_addoption(parser):
"--show-plots",
action="store_true",
default=False,
help="Show any figure windows created by test cases. (Useful to display plots for visual inspection, "
"but automated tests should probably also check patch collections or figure & axis properties.)",
help="Show any figure windows created by test cases. (Useful to display "
"plots for visual inspection, but automated tests should probably also "
"check patch collections or figure & axis properties.)",
)

# for test_generate_classes.py
parser.addoption(
"--ref",
action="append",
type=str,
help="Include extra refs to test. Useful for testing branches on a fork, e.g. <your GitHub username>/modflow6/<your branch>.",
help="Include extra refs to test. Useful for testing branches on a fork, "
"e.g. <your GitHub username>/modflow6/<your branch>.",
)


Expand Down
3 changes: 2 additions & 1 deletion autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4085,7 +4085,8 @@ def test006_gwf3(function_tmpdir, example_data_path):
save_folder.mkdir()
sim.set_sim_path(save_folder)

# write with "copy_external_files" turned off so external files do not get copied to new location
# write with "copy_external_files" turned off so external files
# do not get copied to new location
sim.write_simulation(ext_file_action=ExtFileAction.copy_none)

# store strt in an external binary file
Expand Down
3 changes: 2 additions & 1 deletion autotest/regression/test_modflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ def test_mf2005_lake(function_tmpdir, namfile, mf2005_test_path):

fn0 = join(ws, Path(namfile).name)

# write free format files - won't run without resetting to free format - evt external file issue
# write free format files -
# won't run without resetting to free format - evt external file issue
m.free_format_input = True

# rewrite files
Expand Down
22 changes: 10 additions & 12 deletions autotest/test_cellbudgetfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_cellbudgetfile_build_index_compact(example_data_path):
52,
)
assert list_recorddict[-1] == (
(1, 1097, b"FLOW LOWER FACE ", 20, 40, -3, 1, 1.0, 1.0, 1097.0, b"", b"", b"", b""),
(1, 1097, b"FLOW LOWER FACE ", 20, 40, -3, 1, 1.0, 1.0, 1097.0, b"", b"", b"", b""), # noqa
42648784,
)
# fmt: on
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_cellbudgetfile_build_index_mf6(example_data_path):
assert list_recorddict[-1] == (
(120, 4, b" EVT", 10, 15, -3, 6,
0.08333333333333333, 10.000000000000002, 30.99999999999983,
b"GWF_1 ", b"GWF_1 ", b"GWF_1 ", b"EVT "),
b"GWF_1 ", b"GWF_1 ", b"GWF_1 ", b"EVT "), # noqa
13414144,
)
# fmt: on
Expand Down Expand Up @@ -515,11 +515,10 @@ def test_cellbudgetfile_readrecord(example_data_path):
for idx, kk in enumerate(kstpkper):
t0 = v.get_data(kstpkper=kk, text=record.strip())[0]
t1 = v.get_data(idx=indices[idx], text=record)[0]
assert np.array_equal(
t0, t1
), "binary budget item {0} read using kstpkper != binary budget item {0} read using idx".format(
record
)
assert np.array_equal(t0, t1), (
"binary budget item {0} read using kstpkper != "
"binary budget item {0} read using idx"
).format(record)

# idx can be either an int or a list of ints
s9 = v.get_data(idx=9)
Expand Down Expand Up @@ -577,11 +576,10 @@ def test_cellbudgetfile_readrecord_waux(example_data_path):
for idx, kk in enumerate(kstpkper):
t0 = v.get_data(kstpkper=kk, text=record.strip())[0]
t1 = v.get_data(idx=indices[idx], text=record)[0]
assert np.array_equal(
t0, t1
), "binary budget item {0} read using kstpkper != binary budget item {0} read using idx".format(
record
)
assert np.array_equal(t0, t1), (
"binary budget item {0} read using kstpkper != "
"binary budget item {0} read using idx"
).format(record)
v.close()


Expand Down
3 changes: 2 additions & 1 deletion autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,8 @@ def test_vtk_pathline(function_tmpdir, example_data_path):


def grid2disvgrid(nrow, ncol):
"""Simple function to create disv verts and iverts for a regular grid of size nrow, ncol"""
"""Simple function to create disv verts and iverts for a regular grid of
size nrow, ncol"""

def lower_left_point(i, j, ncol):
return i * (ncol + 1) + j
Expand Down
8 changes: 5 additions & 3 deletions autotest/test_get_modflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
flopy_dir = get_project_root_path()
get_modflow_script = flopy_dir / "flopy" / "utils" / "get_modflow.py"
bindir_options = {
"flopy": Path(expandvars(r"%LOCALAPPDATA%\flopy")) / "bin"
if system() == "Windows"
else Path.home() / ".local" / "share" / "flopy" / "bin",
"flopy": (
Path(expandvars(r"%LOCALAPPDATA%\flopy")) / "bin"
if system() == "Windows"
else Path.home() / ".local" / "share" / "flopy" / "bin"
),
"python": Path(sys.prefix) / ("Scripts" if system() == "Windows" else "bin"),
"home": Path.home() / ".local" / "bin",
}
Expand Down
16 changes: 8 additions & 8 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
import pyproj


epsg_3070_proj4_str = (
"+proj=tmerc +lat_0=0 +lon_0=-90 +k=0.9996 +x_0=520000 "
"+y_0=-4480000 +datum=NAD83 +units=m +no_defs "
)


@pytest.fixture
def minimal_unstructured_grid_info():
d = {
Expand Down Expand Up @@ -579,10 +585,7 @@ def test_unstructured_from_gridspec_comments(example_data_path):
(None, None),
(26916, "EPSG:26916"),
("epsg:5070", "EPSG:5070"),
(
"+proj=tmerc +lat_0=0 +lon_0=-90 +k=0.9996 +x_0=520000 +y_0=-4480000 +datum=NAD83 +units=m +no_defs ",
"EPSG:3070",
),
(epsg_3070_proj4_str, "EPSG:3070"),
pytest.param(4269, None, marks=pytest.mark.xfail),
),
)
Expand Down Expand Up @@ -649,10 +652,7 @@ def do_checks(g):
(None, None),
(26916, "EPSG:26916"),
("epsg:5070", "EPSG:5070"),
(
"+proj=tmerc +lat_0=0 +lon_0=-90 +k=0.9996 +x_0=520000 +y_0=-4480000 +datum=NAD83 +units=m +no_defs ",
"EPSG:3070",
),
(epsg_3070_proj4_str, "EPSG:3070"),
("ESRI:102733", "ESRI:102733"),
pytest.param(4269, None, marks=pytest.mark.xfail),
),
Expand Down
4 changes: 3 additions & 1 deletion autotest/test_lgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def singleModel(
# Variables for the BAS package
ibound = np.ones((nlay, nrow, ncol), dtype=np.int32)
if iChild > 0:
iBndBnd = 59 # code for child cell to be linked to parent; value assigned to ibflg in the LGR-data
# code for child cell to be linked to parent;
# value assigned to ibflg in the LGR-data
iBndBnd = 59
else:
iBndBnd = -1
ibound[:, 0, :] = iBndBnd
Expand Down
10 changes: 6 additions & 4 deletions autotest/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,10 @@ def test_binary_read(function_tmpdir):
bf, data_shape, data_size, np.float64, modelgrid
)[0]

assert np.allclose(
arr, arr2
), f"Binary read for layered structured failed with {'Path' if isinstance(binfile, Path) else 'str'}"
assert np.allclose(arr, arr2), (
"Binary read for layered structured failed with "
+ ("Path" if isinstance(binfile, Path) else "str")
)

binfile = function_tmpdir / "structured_flat.hds"
with open(binfile, "wb") as foo:
Expand Down Expand Up @@ -2335,7 +2336,8 @@ def test_remove_model(function_tmpdir, example_data_path):
files = list(function_tmpdir.glob("*"))
assert not any("model2" in f.name for f in files)

# there should be no model or solver entry for the child model in the simulation namefile
# there should be no model or solver entry for the child model
# in the simulation namefile
lines = open(function_tmpdir / "mfsim.nam").readlines()
lines = [l.lower().strip() for l in lines]
assert not any("model2" in l for l in lines)
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_model_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,5 +1295,6 @@ def build_gwt_model(sim, gwtname, rch_package):
diff = np.nansum(diff)
if diff > 10.25:
raise AssertionError(
f"Difference between output arrays: {diff :.2f} greater than tolerance"
"Difference between output arrays: "
f"{diff :.2f} greater than tolerance"
)
5 changes: 3 additions & 2 deletions autotest/test_modflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_modflow_load(namfile, example_data_path):
pytest.param(
_example_data_path / "freyberg_multilayer_transient" / "freyberg.nam",
{
"proj4": "+proj=utm +zone=14 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
"proj4": "+proj=utm +zone=14 +ellps=WGS84 +datum=WGS84 +units=m +no_defs", # noqa
"angrot": 15.0,
"xoffset": 622241.1904510253,
"yoffset": 3343617.741737109,
Expand Down Expand Up @@ -1225,7 +1225,8 @@ def test_load_with_list_reader(function_tmpdir):
["recarray", "dataframe", "dict_of_recarray", "dict_of_dataframe"],
)
def test_pkg_data_containers(function_tmpdir, container):
"""Test various containers for package data (list, ndarray, recarray, dataframe, dict of such)"""
"""Test various containers for package data
(list, ndarray, recarray, dataframe, dict of such)"""

nlay = 1
nrow = 10
Expand Down
6 changes: 4 additions & 2 deletions autotest/test_mp6.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ def test_data_pass_no_modflow(function_tmpdir, alt):
@pytest.mark.parametrize("alt", [True, False])
def test_data_pass_with_modflow(function_tmpdir, alt):
"""
test that user specified head files etc. are preferred over files from the modflow model
test that user specified head files etc. are preferred
over files from the modflow model
"""

ml, ctx = get_mf2005_model("data_pass", function_tmpdir, alt)
Expand Down Expand Up @@ -760,7 +761,8 @@ def test_data_pass_with_modflow(function_tmpdir, alt):
@pytest.mark.parametrize("alt", [True, False])
def test_just_from_model(function_tmpdir, alt):
"""
test that user specified head files etc. are preferred over files from the modflow model
test that user specified head files etc. are preferred
over files from the modflow model
"""

ml, ctx = get_mf2005_model("data_pass", function_tmpdir, alt)
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_particlegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def test_pgroup_release_data():
)
assert type(pgrd2.releaseinterval) == type(ripg2), (
f"mp7: pgroup with releaseoption 2 returned "
f"type(releaseinterval)={type(pgrd2.releaseinterval)}. Should remain as {type(ripg2)}"
f"type(releaseinterval)={type(pgrd2.releaseinterval)}. "
f"Should remain as {type(ripg2)}"
)
assert len(pgrd3.releasetimes) == nripg3, (
f"mp7: pgroup with releaseoption 3 returned "
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_plot_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def test_cross_section_bc_UZF_3lay(example_data_path):

def structured_square_grid(side: int = 10, thick: int = 10):
"""
Creates a basic 1-layer structured grid with the given thickness and number of cells per side
Creates a basic 1-layer structured grid with the given thickness and number of
cells per side
Parameters
----------
side : The number of cells per side
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_specific_discharge.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def specific_discharge_comprehensive(function_tmpdir):

@pytest.mark.mf6
@pytest.mark.xfail(
reason="occasional Unexpected collection type: <class 'matplotlib.collections.LineCollection'>"
reason="occasional Unexpected collection type: <class 'matplotlib.collections.LineCollection'>" # noqa
)
def test_specific_discharge_mf6(mf6_model):
# build and run MODFLOW 6 model
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_template_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def test_tpl_layered(function_tmpdir):
partype = "hk"
parname = "HK_LAYER_1-3"

# Span indicates that the hk parameter applies as a multiplier to layers 0 and 2 (MODFLOW layers 1 and 3)
# Span indicates that the hk parameter applies as a multiplier to layers 0 and 2
# (MODFLOW layers 1 and 3)
span = {"layers": [0, 2]}

# These parameters have not affect yet, but may in the future
Expand Down
3 changes: 2 additions & 1 deletion autotest/test_uzf.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path):
for i, a in enumerate(a1):
assert a == l2[i]

# load uzf test problem for nwt model with 'nwt_11_fmt'-style options and 'open/close' array types
# load uzf test problem for nwt model with 'nwt_11_fmt'-style options
# and 'open/close' array types
tpth = uzf_test_path / "load_uzf_for_nwt"
[shutil.copy(os.path.join(tpth, f), os.path.join(ws, f)) for f in os.listdir(tpth)]
m3 = Modflow("UZFtest3", version="mfnwt", verbose=True)
Expand Down
2 changes: 1 addition & 1 deletion flopy/discretization/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def map_polygons(self):

def get_lni(self, nodes):
"""
Get the layer index and within-layer node index (both 0-based) for the given nodes
Get the 0-based layer index and within-layer node index for the given nodes
Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion flopy/discretization/unstructuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,8 @@ def split_line():
verts_provided = len(line) - 6
if verts_declared != verts_provided:
raise ValueError(
f"Cell {nn} declares {verts_declared} vertices but provides {verts_provided}"
f"Cell {nn} declares {verts_declared} vertices "
f"but provides {verts_provided}"
)

verts = [int(vert) - 1 for vert in line[6 : 6 + verts_declared]]
Expand Down
5 changes: 4 additions & 1 deletion flopy/export/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def __init__(self, sciencebase_id, model):
if "publisher" in d.get("type").lower()
][0]
self.publisher_email = self.sb["provenance"]["linkProcess"].get("processedBy")
self.publisher_url = "https://www2.usgs.gov/water/" # self.sb['provenance']['linkProcess'].get('linkReference')
# TODO: should publisher_url be obtained from linkReference?
# publisher_url = self.sb['provenance']['linkProcess'].get('linkReference')
publisher_url = "https://www2.usgs.gov/water/"
self.publisher_url = publisher_url
self.geospatial_bounds_crs = "EPSG:4326"
self.geospatial_lat_min = self.bounds.get("minY")
self.geospatial_lat_max = self.bounds.get("maxY")
Expand Down
9 changes: 6 additions & 3 deletions flopy/export/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ def initialize_file(self, time_values=None):
delc.comments = (
"This is the row spacing that applied to the UNROTATED grid. "
"This grid HAS been rotated before being saved to NetCDF. "
"To compute the unrotated grid, use the origin point and this array."
"To compute the unrotated grid, use the origin point and "
"this array."
)

# delr
Expand All @@ -893,7 +894,8 @@ def initialize_file(self, time_values=None):
delr.comments = (
"This is the col spacing that applied to the UNROTATED grid. "
"This grid HAS been rotated before being saved to NetCDF. "
"To compute the unrotated grid, use the origin point and this array."
"To compute the unrotated grid, use the origin point and "
"this array."
)

# Workaround for CF/CDM.
Expand Down Expand Up @@ -1267,7 +1269,8 @@ def add_sciencebase_metadata(self, id, check=True):
return md

def _check_vs_sciencebase(self, md):
"""Check that model bounds read from flopy are consistent with those in ScienceBase."""
"""Check that model bounds read from flopy are consistent with
those in ScienceBase."""
xmin, ymin, xmax, ymax = self.bounds
tol = 1e-5
assert md.geospatial_lon_min - xmin < tol
Expand Down
3 changes: 2 additions & 1 deletion flopy/export/shapefile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def model_attributes_to_shapefile(
if a.array.shape == horz_shape:
if hasattr(a, "shape"):
if a.shape[1] is None: # usg unstructured Util3d
# return a flattened array, with a.name[0] (a per-layer list)
# return a flattened array,
# with a.name[0] (a per-layer list)
array_dict[a.name[0]] = a.array
else:
array_dict[a.name] = a.array
Expand Down
Loading

0 comments on commit bb9824e

Please sign in to comment.