diff --git a/gui/wxpython/gmodeler/panels.py b/gui/wxpython/gmodeler/panels.py index 509da20a1b8..a62b8dd6f8e 100644 --- a/gui/wxpython/gmodeler/panels.py +++ b/gui/wxpython/gmodeler/panels.py @@ -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 ( @@ -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() diff --git a/pyproject.toml b/pyproject.toml index b22dd3a2e09..7bc73f55711 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]