[enh] use rich.console.print_exception

This commit is contained in:
Laurent Peuch 2021-06-15 00:49:32 +02:00
parent 2c74d2f108
commit f802d8139c
4 changed files with 9 additions and 12 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from rich import traceback from rich import traceback
from rich.console import Console
from moulinette.core import ( from moulinette.core import (
MoulinetteError, MoulinetteError,
@ -44,10 +45,11 @@ msignals = MoulinetteSignals()
msettings = dict() msettings = dict()
m18n = Moulinette18n() m18n = Moulinette18n()
console = Console()
# pretty traceback using rich # pretty traceback using rich
traceback.install(show_locals=True, extra_lines=6) traceback.install(show_locals=True, extra_lines=6)
# Package functions # Package functions

View file

@ -11,7 +11,7 @@ from time import time
from collections import OrderedDict from collections import OrderedDict
from importlib import import_module from importlib import import_module
from moulinette import m18n, msignals from moulinette import m18n, msignals, console
from moulinette.cache import open_cachefile from moulinette.cache import open_cachefile
from moulinette.globals import init_moulinette_env from moulinette.globals import init_moulinette_env
from moulinette.core import ( from moulinette.core import (
@ -570,9 +570,7 @@ class ActionsMap(object):
) )
func = getattr(mod, func_name) func = getattr(mod, func_name)
except (AttributeError, ImportError) as e: except (AttributeError, ImportError) as e:
import traceback console.print_exception()
traceback.print_exc()
error_message = "unable to load function %s.%s because: %s" % ( error_message = "unable to load function %s.%s because: %s" % (
namespace, namespace,
func_name, func_name,

View file

@ -5,6 +5,7 @@ import logging
import hashlib import hashlib
import hmac import hmac
from moulinette import console
from moulinette.cache import open_cachefile, get_cachedir, cachefile_exists from moulinette.cache import open_cachefile, get_cachedir, cachefile_exists
from moulinette.core import MoulinetteError, MoulinetteAuthenticationError from moulinette.core import MoulinetteError, MoulinetteAuthenticationError
@ -115,9 +116,7 @@ class BaseAuthenticator(object):
s_id, s_token = token s_id, s_token = token
self._store_session(s_id, s_token) self._store_session(s_id, s_token)
except Exception as e: except Exception as e:
import traceback console.print_exception()
traceback.print_exc()
logger.exception("unable to store session because %s", e) logger.exception("unable to store session because %s", e)
else: else:
logger.debug("session has been stored") logger.debug("session has been stored")

View file

@ -6,7 +6,7 @@ import argparse
import copy import copy
from collections import deque, OrderedDict from collections import deque, OrderedDict
from moulinette import msettings, m18n from moulinette import msettings, m18n, console
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
logger = logging.getLogger("moulinette.interface") logger = logging.getLogger("moulinette.interface")
@ -357,9 +357,7 @@ class _CallbackAction(argparse.Action):
mod = __import__(mod_name, globals=globals(), level=0, fromlist=[func_name]) mod = __import__(mod_name, globals=globals(), level=0, fromlist=[func_name])
func = getattr(mod, func_name) func = getattr(mod, func_name)
except (AttributeError, ImportError): except (AttributeError, ImportError):
import traceback console.print_exception()
traceback.print_exc()
raise ValueError("unable to import method {0}".format(self.callback_method)) raise ValueError("unable to import method {0}".format(self.callback_method))
self._callback = func self._callback = func