Skip to content

Commit

Permalink
style: SIM115 / FURB103: Replace explicit file open/close with Path.w…
Browse files Browse the repository at this point in the history
…rite_text() (#5134)

added context manager for panels.py
  • Loading branch information
arohanajit authored Feb 21, 2025
1 parent 21933d1 commit 5a59faf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 6 additions & 8 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,15 +1770,13 @@ def OnRun(self, event):
"""Run Python script"""
self.filename = grass.tempfile()
try:
fd = open(self.filename, "w")
fd.write(self.body.GetText())
Path(self.filename).write_text(self.body.GetText())
except OSError as e:
GError(_("Unable to launch Python script. %s") % e, parent=self)
return
finally:
fd.close()
mode = stat.S_IMODE(os.lstat(self.filename)[stat.ST_MODE])
os.chmod(self.filename, mode | stat.S_IXUSR)

mode = stat.S_IMODE(os.lstat(self.filename)[stat.ST_MODE])
os.chmod(self.filename, mode | stat.S_IXUSR)

for item in self.parent.GetModel().GetItems():
if (
Expand All @@ -1787,12 +1785,12 @@ def OnRun(self, event):
> 0
):
self.parent._gconsole.RunCmd(
[fd.name, "--ui"], skipInterface=False, onDone=self.OnDone
[self.filename, "--ui"], skipInterface=False, onDone=self.OnDone
)
break
else:
self.parent._gconsole.RunCmd(
[fd.name], skipInterface=True, onDone=self.OnDone
[self.filename], skipInterface=True, onDone=self.OnDone
)

event.Skip()
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ ignore = [
"**.py" = ["PYI066"]
"*/testsuite/**.py" = ["PT009", "PT027"]
"gui/wxpython/gcp/manager.py" = ["PTH208"]
"gui/wxpython/gmodeler/panels.py" = ["SIM115"]
"gui/wxpython/gui_core/dialogs.py" = ["PTH208"]
"gui/wxpython/gui_core/forms.py" = ["SIM115"]
"gui/wxpython/gui_core/goutput.py" = ["SIM115"]
Expand Down

0 comments on commit 5a59faf

Please sign in to comment.