Skip to content

Commit

Permalink
Merge pull request #5337 from dmarteau/qgis_utils_refactoring
Browse files Browse the repository at this point in the history
Disable message hook and import override at runtime
  • Loading branch information
rldhont committed Oct 20, 2017
2 parents 13a00aa + 40b916c commit efb84fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .docker/docker-compose.travis.yml
Expand Up @@ -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

2 changes: 1 addition & 1 deletion python/plugins/processing/tests/QgisAlgorithmsTest.py
Expand Up @@ -50,7 +50,7 @@ def name(self):
def displayName(self):
return 'testalg'

def initAlgorithm(self):
def initAlgorithm(self, config=None):
pass

def createInstance(self):
Expand Down
16 changes: 10 additions & 6 deletions python/utils.py
Expand Up @@ -33,6 +33,7 @@
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes
from qgis.gui import QgsMessageBar

import os
import sys
import traceback
import glob
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit efb84fd

Please sign in to comment.