diff --git a/.github/workflows/python-code-quality.yml b/.github/workflows/python-code-quality.yml index 31819c081aa..8c49211705f 100644 --- a/.github/workflows/python-code-quality.yml +++ b/.github/workflows/python-code-quality.yml @@ -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: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 49674d971cb..9834ad4f121 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/gui/wxpython/animation/controller.py b/gui/wxpython/animation/controller.py index 808e9b20ef4..6cf3269eeb1 100644 --- a/gui/wxpython/animation/controller.py +++ b/gui/wxpython/animation/controller.py @@ -36,7 +36,6 @@ HashCmds, ) from animation.data import AnimationData -from itertools import starmap class AnimationController(wx.EvtHandler): @@ -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: diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 9ae88cb05a4..a1722fec64b 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -871,12 +871,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() diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 43bbfdc1b8e..ddeb19c7302 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -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() @@ -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() diff --git a/gui/wxpython/gmodeler/panels.py b/gui/wxpython/gmodeler/panels.py index fbdc2048620..e567706cd19 100644 --- a/gui/wxpython/gmodeler/panels.py +++ b/gui/wxpython/gmodeler/panels.py @@ -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, diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 56adf91775b..a658897a5fb 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -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() @@ -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() diff --git a/gui/wxpython/lmgr/workspace.py b/gui/wxpython/lmgr/workspace.py index dd83c1a6f22..6bad27d7674 100644 --- a/gui/wxpython/lmgr/workspace.py +++ b/gui/wxpython/lmgr/workspace.py @@ -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, diff --git a/gui/wxpython/mapwin/buffered.py b/gui/wxpython/mapwin/buffered.py index 7e42ebc57c9..fe2a5b0ae69 100644 --- a/gui/wxpython/mapwin/buffered.py +++ b/gui/wxpython/mapwin/buffered.py @@ -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]) @@ -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]) diff --git a/gui/wxpython/photo2image/ip2i_manager.py b/gui/wxpython/photo2image/ip2i_manager.py index dc5713e961a..9f78d717fee 100644 --- a/gui/wxpython/photo2image/ip2i_manager.py +++ b/gui/wxpython/photo2image/ip2i_manager.py @@ -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() diff --git a/gui/wxpython/wxplot/dialogs.py b/gui/wxpython/wxplot/dialogs.py index cdb74c64a9e..d1564d4fc8a 100755 --- a/gui/wxpython/wxplot/dialogs.py +++ b/gui/wxpython/wxplot/dialogs.py @@ -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""" diff --git a/gui/wxpython/wxplot/profile.py b/gui/wxpython/wxplot/profile.py index e0994f1a8a5..5b63f3cabab 100644 --- a/gui/wxpython/wxplot/profile.py +++ b/gui/wxpython/wxplot/profile.py @@ -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() diff --git a/lib/gis/testsuite/test_gis_lib_getl.py b/lib/gis/testsuite/test_gis_lib_getl.py index 1ac9907f3d9..dec5c0b40a2 100644 --- a/lib/gis/testsuite/test_gis_lib_getl.py +++ b/lib/gis/testsuite/test_gis_lib_getl.py @@ -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: diff --git a/lib/init/grass.py b/lib/init/grass.py index c2ac803e6a2..befec465b3a 100755 --- a/lib/init/grass.py +++ b/lib/init/grass.py @@ -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): @@ -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() diff --git a/python/grass/gunittest/multireport.py b/python/grass/gunittest/multireport.py index 5a0350f1786..9deb0528ada 100644 --- a/python/grass/gunittest/multireport.py +++ b/python/grass/gunittest/multireport.py @@ -413,13 +413,13 @@ def main_page( ) ) page.write("") - for image, caption in itertools.izip(images, captions): - page.write( - "