Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix SIM115: Simplify if statement in t.list and PTH201 in v.fill.holes #5063

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ ignore = [
"scripts/r.tileset/r.tileset.py" = ["SIM115"]
"scripts/v.*/v.*.py" = ["SIM115"]
"scripts/wxpyimgview/wxpyimgview_gui.py" = ["SIM115"]
"temporal/t.list/t.list.py" = ["SIM115"]
"temporal/t.rast.algebra/testsu*/*_algebra_arithmetic.py" = ["FLY002"]
"temporal/t.rast.colors/t.rast.colors.py" = ["SIM115"]
"temporal/t.rast.series/t.rast.series.py" = ["SIM115"]
Expand All @@ -372,8 +371,6 @@ ignore = [
"temporal/t.register/testsu*/*_raster_mapmetadata.py" = ["FLY002"]
"temporal/t.register/testsuite/test_t_register_raster.py" = ["FLY002"]
"temporal/t.register/testsuite/test_t_register_raster_file.py" = ["FLY002"]
"temporal/t.remove/t.remove.py" = ["SIM115"]
"vector/v.fill.holes/examples.ipynb" = ["PTH201"]

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
# Declare a custom aliases, checked with rule ICN001
Expand Down
124 changes: 59 additions & 65 deletions temporal/t.list/t.list.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import sys

import grass.script as gs
from contextlib import nullcontext

############################################################################

Expand Down Expand Up @@ -119,73 +120,66 @@ def main():
if gs.verbosity() > 0 and not outpath:
sys.stderr.write("----------------------------------------------\n")

if outpath:
outfile = open(outpath, "w")

for ttype in temporal_type.split(","):
time = "absolute time" if ttype == "absolute" else "relative time"

stds_list = tgis.get_dataset_list(type, ttype, columns, where, order, dbif=dbif)

# Use the correct order of the mapsets, hence first the current mapset, then
# alphabetic ordering
mapsets = tgis.get_tgis_c_library_interface().available_mapsets()

# Print for each mapset separately
for key in mapsets:
if key in stds_list.keys():
rows = stds_list[key]

if rows:
if gs.verbosity() > 0 and not outpath:
if issubclass(sp.__class__, tgis.AbstractMapDataset):
sys.stderr.write(
_(
"Time stamped %s maps with %s available in mapset "
"<%s>:\n"
# Replace separate "if outpath" and "else" blocks with a unified context manager:
with (
open(outpath, "w")
if (outpath and outpath != "-")
else nullcontext(sys.stdout) as out_file
):
for ttype in temporal_type.split(","):
time = "absolute time" if ttype == "absolute" else "relative time"

stds_list = tgis.get_dataset_list(
type, ttype, columns, where, order, dbif=dbif
)

mapsets = tgis.get_tgis_c_library_interface().available_mapsets()

for key in mapsets:
if key in stds_list.keys():
rows = stds_list[key]

if rows:
if gs.verbosity() > 0 and (not outpath or outpath == "-"):
if issubclass(sp.__class__, tgis.AbstractMapDataset):
sys.stderr.write(
_(
"Time stamped %s maps with %s available in mapset "
"<%s>:\n"
)
% (sp.get_type(), time, key)
)
% (sp.get_type(), time, key)
)
else:
sys.stderr.write(
_(
"Space time %s datasets with %s available in "
"mapset <%s>:\n"
)
% (sp.get_new_map_instance(None).get_type(), time, key)
)

# Print the column names if requested
if colhead and first:
output = ""
count = 0
for key in rows[0].keys():
if count > 0:
output += separator + str(key)
else:
output += str(key)
count += 1
if outpath:
outfile.write("{st}\n".format(st=output))
else:
print(output)
first = False

for row in rows:
output = ""
count = 0
for col in row:
if count > 0:
output += separator + str(col)
else:
output += str(col)
count += 1
if outpath:
outfile.write("{st}\n".format(st=output))
else:
print(output)
if outpath:
outfile.close()
sys.stderr.write(
_(
"Space time %s datasets with %s available in "
"mapset <%s>:\n"
)
% (
sp.get_new_map_instance(None).get_type(),
time,
key,
)
)

if colhead and first:
output = ""
count = 0
for col_key in rows[0].keys():
output += (separator if count > 0 else "") + str(
col_key
)
count += 1
out_file.write("{st}\n".format(st=output))
first = False

for row in rows:
output = ""
count = 0
for col in row:
output += (separator if count > 0 else "") + str(col)
count += 1
out_file.write("{st}\n".format(st=output))
dbif.close()


Expand Down
2 changes: 1 addition & 1 deletion vector/v.fill.holes/examples.ipynb
arohanajit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"metadata": {},
"outputs": [],
"source": [
"work_dir = Path(\".\")\n",
"work_dir = Path()\n",
"conftest.import_data(\n",
" path=work_dir,\n",
" areas_name=\"data\",\n",
Expand Down
Loading