mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Merge pull request #5337 from dmarteau/qgis_utils_refactoring
Disable message hook and import override at runtime
This commit is contained in:
commit
efb84fd2ca
@ -23,3 +23,6 @@ services:
|
||||
- TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
|
||||
- TRAVIS_CONFIG=${TRAVIS_CONFIG}
|
||||
- TRAVIS=${TRAVIS}
|
||||
- QGIS_DISABLE_MESSAGE_HOOKS=1
|
||||
- QGIS_NO_OVERRIDE_IMPORT=1
|
||||
|
||||
|
@ -50,7 +50,7 @@ class TestAlg(QgsProcessingAlgorithm):
|
||||
def displayName(self):
|
||||
return 'testalg'
|
||||
|
||||
def initAlgorithm(self):
|
||||
def initAlgorithm(self, config=None):
|
||||
pass
|
||||
|
||||
def createInstance(self):
|
||||
|
@ -33,6 +33,7 @@ from qgis.PyQt.QtWidgets import QPushButton, QApplication
|
||||
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes
|
||||
from qgis.gui import QgsMessageBar
|
||||
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
import glob
|
||||
@ -76,7 +77,8 @@ def showWarning(message, category, filename, lineno, file=None, line=None):
|
||||
)
|
||||
|
||||
|
||||
warnings.showwarning = showWarning
|
||||
if not os.environ.get('QGIS_DISABLE_MESSAGE_HOOKS'):
|
||||
warnings.showwarning = showWarning
|
||||
|
||||
|
||||
def showException(type, value, tb, msg, messagebar=False):
|
||||
@ -204,7 +206,8 @@ def uninstallErrorHook():
|
||||
|
||||
|
||||
# install error hook() on module load
|
||||
installErrorHook()
|
||||
if not os.environ.get('QGIS_DISABLE_MESSAGE_HOOKS'):
|
||||
installErrorHook()
|
||||
|
||||
# initialize 'iface' object
|
||||
iface = None
|
||||
@ -683,7 +686,8 @@ def _import(name, globals={}, locals={}, fromlist=[], level=None):
|
||||
return mod
|
||||
|
||||
|
||||
if _uses_builtins:
|
||||
builtins.__import__ = _import
|
||||
else:
|
||||
__builtin__.__import__ = _import
|
||||
if not os.environ.get('QGIS_NO_OVERRIDE_IMPORT'):
|
||||
if _uses_builtins:
|
||||
builtins.__import__ = _import
|
||||
else:
|
||||
__builtin__.__import__ = _import
|
||||
|
Loading…
x
Reference in New Issue
Block a user