From 761ee64e832dcd38dc1b6d0701b48ee468fb7113 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 21 Jan 2025 15:58:29 -0600 Subject: Only use flask modules if flask is present and 'current_app' is set. --- gn_libs/debug.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'gn_libs') diff --git a/gn_libs/debug.py b/gn_libs/debug.py index 6b7173b..c1b896e 100644 --- a/gn_libs/debug.py +++ b/gn_libs/debug.py @@ -1,6 +1,6 @@ """Debug utilities""" import logging -from flask import current_app +import importlib.util __this_module_name__ = __name__ @@ -8,10 +8,16 @@ __this_module_name__ = __name__ # pylint: disable=invalid-name def getLogger(name: str): """Return a logger""" - return ( - logging.getLogger(name) - if not bool(current_app) - else current_app.logger) + flask_spec = importlib.util.find_spec("flask") + if bool(flask_spec): + current_app = importlib.import_module("flask").current_app + return ( + logging.getLogger(name) + if not bool(current_app) + else current_app.logger) + + return logging.getLogger(name) + def __pk__(*args): """Format log entry""" -- cgit v1.2.3