import logging import os import sys # Check and gracefully fail if the user needs to install a 3rd-party dep. libnames = ['appdirs', 'configobj', 'colorlog'] def check_env_has_dependencies(libnames): rc = True for libname in libnames: try: __import__(libname) except ModuleNotFoundError as ex: print('missing third-part library: ', ex, file=sys.stderr) rc = False return rc if not check_env_has_dependencies(libnames): print('refusing to load program without installed dependencies', file=sys.stderr) raise ImportError('python environment needs third-party dependencies installed') # Logger for before the application and logging config is loaded # - used to log before logging is configured _log_fmt = '%(levelname)-7s:%(message)s' _logger_name = 'app_skellington' _bootstrap_logger = logging.getLogger(_logger_name) _bootstrap_logger.setLevel(1000) _bootstrap_logger.propagate = False # NOTE(MG) Pretty sure the logger has the default handler too at this point. # It's been related to some issues with the logger double-printing messages. _bootstrap_logger.addHandler(logging.NullHandler())