From e31d41ca7c5c7d59dfc6f1be008fc4ec5d141972 Mon Sep 17 00:00:00 2001 From: Sean Breckenridge Date: Thu, 28 Oct 2021 22:22:15 -0700 Subject: [PATCH] warn w/ module name, tell user how to disable warn --- my/core/source.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/my/core/source.py b/my/core/source.py index 3f5f19e..e2529eb 100644 --- a/my/core/source.py +++ b/my/core/source.py @@ -44,8 +44,19 @@ def import_source( res = factory_func(**kwargs) yield from res except ModuleNotFoundError: - # TODO: check if module_name is disabled and don't send warning - warn(f"Module {factory_func.__qualname__} could not be imported, or isn't configured propertly") + from . import core_config as CC + suppressed_in_conf = False + if module_name is not None and CC.config._is_module_active(module_name) is False: + suppressed_in_conf = True + if not suppressed_in_conf: + if module_name is None: + warn(f"Module {factory_func.__qualname__} could not be imported, or isn't configured propertly") + else: + warn(f"""Module {module_name} ({factory_func.__qualname__}) could not be imported, or isn't configured propertly\nTo hide this message, add {module_name} to your core config disabled_classes, like: + +class core: + disabled_modules = [{repr(module_name)}] +""") yield from default return wrapper return decorator