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

CI(deps): Update ruff to v0.9.3 #4982

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# renovate: datasource=pypi depName=bandit
BANDIT_VERSION: "1.8.2"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.9.2"
RUFF_VERSION: "0.9.3"

runs-on: ${{ matrix.os }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.2
rev: v0.9.3
hooks:
# Run the linter.
- id: ruff
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/animation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
HashCmds,
)
from animation.data import AnimationData
from itertools import starmap


class AnimationController(wx.EvtHandler):
Expand Down Expand Up @@ -369,7 +368,7 @@ def _updateAnimations(self, activeIndices, mapNamesDict=None):
if anim.viewMode == "3d":
regions = [None] * len(regions)
self.animations[i].SetFrames(
list(starmap(HashCmds, zip(anim.cmdMatrix, regions)))
list(map(HashCmds, anim.cmdMatrix, regions))
)
self.animations[i].SetActive(True)
else:
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,10 @@ def StoreEnvVariable(key, value=None, envFile=None):
return
expCmd = "set" if windows else "export"

for key, value in environ.items():
fd.write("%s %s=%s\n" % (expCmd, key, value))
fd.writelines("%s %s=%s\n" % (expCmd, key, value) for key, value in environ.items())

# write also skipped lines
for line in lineSkipped:
fd.write(line + os.linesep)
fd.writelines(line + os.linesep for line in lineSkipped)

fd.close()

Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ def SetSrcEnv(self, location, mapset):

try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
f.writelines(
line[0] + ": " + line[1] + "\n" for line in self.gisrc_dict.items()
)
finally:
f.close()

Expand Down Expand Up @@ -2769,8 +2770,7 @@ def MakeVGroup(self):

f = open(self.vgrpfile, mode="w")
try:
for vect in vgrouplist:
f.write(vect + "\n")
f.writelines(vect + "\n" for vect in vgrouplist)
finally:
f.close()

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ def WriteModelFile(self, filename):
try:
mfile = open(filename, "w")
tmpfile.seek(0)
for line in tmpfile.readlines():
mfile.write(line)
mfile.writelines(tmpfile.readlines())
except OSError:
wx.MessageBox(
parent=self,
Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ def SetSrcEnv(self, location, mapset):

try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
f.writelines(
line[0] + ": " + line[1] + "\n" for line in self.gisrc_dict.items()
)
finally:
f.close()

Expand Down Expand Up @@ -2709,8 +2710,7 @@ def MakeVGroup(self):

f = open(self.vgrpfile, mode="w")
try:
for vect in vgrouplist:
f.write(vect + "\n")
f.writelines(vect + "\n" for vect in vgrouplist)
finally:
f.close()

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ def SaveToFile(self, filename):
try:
mfile = open(filename, "wb")
tmpfile.seek(0)
for line in tmpfile.readlines():
mfile.write(line)
mfile.writelines(tmpfile.readlines())
except OSError:
GError(
parent=self.lmgr,
Expand Down
4 changes: 0 additions & 4 deletions gui/wxpython/mapwin/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,6 @@ def OnLeftDown(self, event):
if idlist != []:
self.dragid = idlist[0] # drag whatever is on top

else:
pass
coords = self.Pixel2Cell(self.mouse["begin"])
self.mouseLeftDown.emit(x=coords[0], y=coords[1])

Expand Down Expand Up @@ -1592,8 +1590,6 @@ def OnLeftUp(self, event):
self.textdict[self.dragid]["bbox"] = self.pdc.GetIdBounds(
self.dragid
)
else:
pass
self.dragid = None

self.mouseLeftUpPointer.emit(x=coordinates[0], y=coordinates[1])
Expand Down
5 changes: 3 additions & 2 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ def SetSrcEnv(self, location, mapset):

try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
f.writelines(
line[0] + ": " + line[1] + "\n" for line in self.gisrc_dict.items()
)
finally:
f.close()

Expand Down
2 changes: 0 additions & 2 deletions gui/wxpython/wxplot/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ def OnHistMap(self, event):
self.gselection.Enable()
self.rselection.Disable()
self.rselection.SetValue("")
else:
pass

def OnRasterSelection(self, event):
"""Handler for selecting a single raster map"""
Expand Down
6 changes: 4 additions & 2 deletions gui/wxpython/wxplot/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,10 @@ def SaveProfileToFile(self, event):
dlg.Destroy()
return

for datapair in self.raster[r]["datalist"]:
fd.write("%.6f,%.6f\n" % (float(datapair[0]), float(datapair[1])))
fd.writelines(
"%.6f,%.6f\n" % (float(datapair[0]), float(datapair[1]))
for datapair in self.raster[r]["datalist"]
)

fd.close()

Expand Down
7 changes: 3 additions & 4 deletions lib/gis/testsuite/test_gis_lib_getl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def read_lines_and_assert(self, get_line_function, newline):
"""Write and read lines and then assert they are as expected"""
lines = ["Line 1", "Line 2", "Line 3"]
with open(self.file_path, mode="w", newline=newline) as stream:
for line in lines:
# Python text newline here.
# The specific newline is added by the stream.
stream.write(f"{line}\n")
# Python text newline here.
# The specific newline is added by the stream.
stream.writelines(f"{line}\n" for line in lines)

file_ptr = self.libc.fopen(str(self.file_path).encode("utf-8"), b"r")
if not file_ptr:
Expand Down
6 changes: 2 additions & 4 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ def write_gisrcrc(gisrcrc, gisrc, skip_variable=None):
del lines[number]
number += 1
with open(gisrcrc, "w") as f:
for line in lines:
f.write(line)
f.writelines(lines)


def read_env_file(path):
Expand All @@ -543,8 +542,7 @@ def write_gisrc(kv, filename, append=False):
# use append=True to avoid a race condition between write_gisrc() and
# grass_prompt() on startup (PR #548)
f = open(filename, "a" if append else "w")
for k, v in kv.items():
f.write("%s: %s\n" % (k, v))
f.writelines("%s: %s\n" % (k, v) for k, v in kv.items())
f.close()


Expand Down
12 changes: 6 additions & 6 deletions python/grass/gunittest/multireport.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ def main_page(
)
)
page.write("</tbody></table>")
for image, caption in itertools.izip(images, captions):
page.write(
"<h3>{caption}<h3>"
'<img src="{image}" alt="{caption}" title="{caption}">'.format(
image=image, caption=caption
)
page.writelines(
"<h3>{caption}<h3>"
'<img src="{image}" alt="{caption}" title="{caption}">'.format(
image=image, caption=caption
)
for image, caption in itertools.izip(images, captions)
)
page.write("</body></html>")


Expand Down
14 changes: 8 additions & 6 deletions python/grass/gunittest/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def replace_in_file(file_path, pattern, repl):
# using tmp file to store the replaced content
tmp_file_path = file_path + ".tmp"
with open(file_path) as old_file, open(tmp_file_path, "w") as new_file:
for line in old_file:
new_file.write(re.sub(pattern=pattern, string=line, repl=repl))
new_file.writelines(
re.sub(pattern=pattern, string=line, repl=repl) for line in old_file
)
# remove old file since it must not exist for rename/move
os.remove(file_path)
# replace old file by new file
Expand Down Expand Up @@ -448,8 +449,7 @@ def wrap_stdstream_to_html(infile, outfile, module, stream):
after = "</pre></body></html>"
with open(outfile, "w") as html, open(infile) as text:
html.write(before)
for line in text:
html.write(color_error_line(html_escape(line)))
html.writelines(color_error_line(html_escape(line)) for line in text)
html.write(after)


Expand Down Expand Up @@ -795,8 +795,10 @@ def end_file_test(
file_index.write(files_section)

if supplementary_files:
for f in supplementary_files:
file_index.write('<li><a href="{f}">{f}</a></li>'.format(f=f))
file_index.writelines(
'<li><a href="{f}">{f}</a></li>'.format(f=f)
for f in supplementary_files
)

file_index.write("</ul>")

Expand Down
15 changes: 6 additions & 9 deletions python/grass/gunittest/testsuite/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,14 @@ class TestMd5Sums(TestCase):
@classmethod
def setUpClass(cls):
with open(cls.correct_file_name_platform_nl, "w") as f:
for line in CORRECT_LINES:
# \n should be converted to platform newline
f.write(line + "\n")
# \n should be converted to platform newline
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.correct_file_name_unix_nl, "w") as f:
for line in CORRECT_LINES:
# binary mode will write pure \n
f.write(line + "\n")
# binary mode will write pure \n
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.wrong_file_name, "w") as f:
for line in INCORRECT_LINES:
# \n should be converted to platform newline
f.write(line + "\n")
# \n should be converted to platform newline
f.writelines(line + "\n" for line in INCORRECT_LINES)

@classmethod
def tearDownClass(cls):
Expand Down
2 changes: 0 additions & 2 deletions python/grass/jupyter/timeseriesmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def fill_none_values(names):
for i, name in enumerate(names):
if name == "None":
names[i] = names[i - 1]
else:
pass
return names


Expand Down
3 changes: 1 addition & 2 deletions raster/r.topidx/gridatb_to_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
NODATA_value 9999
"""
)
for inline in inf:
outf.write(inline)
outf.writelines(inf)

inf.close()
outf.close()
24 changes: 12 additions & 12 deletions scripts/d.polar/d.polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ def plot_eps(psout):

(x, y) = outercircle[1]
outf.write("%.2f %.2f moveto\n" % (x * scale + halfframe, y * scale + halfframe))
for x, y in outercircle[2:]:
outf.write(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
)
outf.writelines(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
for x, y in outercircle[2:]
)

t = string.Template(
"""
Expand Down Expand Up @@ -338,10 +338,10 @@ def plot_eps(psout):

(x, y) = sine_cosine_replic[1]
outf.write("%.2f %.2f moveto\n" % (x * scale + halfframe, y * scale + halfframe))
for x, y in sine_cosine_replic[2:]:
outf.write(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
)
outf.writelines(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
for x, y in sine_cosine_replic[2:]
)

t = string.Template(
"""
Expand All @@ -363,10 +363,10 @@ def plot_eps(psout):

(x, y) = vector[1]
outf.write("%.2f %.2f moveto\n" % (x * scale + halfframe, y * scale + halfframe))
for x, y in vector[2:]:
outf.write(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
)
outf.writelines(
"%.2f %.2f lineto\n" % (x * scale + halfframe, y * scale + halfframe)
for x, y in vector[2:]
)

t = string.Template(
"""
Expand Down
3 changes: 1 addition & 2 deletions scripts/db.univar/db.univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def sortfile(infile, outfile):
for i in range(len(lines)):
lines[i] = float(lines[i].rstrip("\r\n"))
lines.sort()
for line in lines:
outf.write(str(line) + "\n")
outf.writelines(str(line) + "\n" for line in lines)

inf.close()
outf.close()
Expand Down
Loading
Loading