Skip to content

Commit

Permalink
[console] Use a more modern approach to running script files, to
Browse files Browse the repository at this point in the history
avoid 'unclosed file' warnings dumped whenever script files
are run through the Python console
  • Loading branch information
nyalldawson committed Jan 18, 2022
1 parent 4844d4a commit d00356a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/console/console_editor.py
Expand Up @@ -462,8 +462,8 @@ def runScriptCode(self):
tmpFile = self.createTempFile()
filename = tmpFile

self.parent.pc.shell.runCommand("exec(open('{0}'.encode('{1}')).read())"
.format(filename.replace("\\", "/"), sys.getfilesystemencoding()))
self.parent.pc.shell.runCommand("exec(Path('{0}').read_text())"
.format(filename.replace("\\", "/")))

def runSelectedCode(self): # spellok
cmd = self.selectedText()
Expand Down
2 changes: 1 addition & 1 deletion python/console/console_sci.py
Expand Up @@ -40,7 +40,7 @@

from .ui_console_history_dlg import Ui_HistoryDialogPythonConsole

_init_commands = ["import sys", "import os", "import re", "import math", "from qgis.core import *",
_init_commands = ["import sys", "import os", "from pathlib import Path", "import re", "import math", "from qgis.core import *",
"from qgis.gui import *", "from qgis.analysis import *", "from qgis._3d import *",
"import processing", "import qgis.utils",
"from qgis.utils import iface", "from qgis.PyQt.QtCore import *", "from qgis.PyQt.QtGui import *",
Expand Down

0 comments on commit d00356a

Please sign in to comment.