From 122f1ef2354928a5838025b465be881ba5c3f39f Mon Sep 17 00:00:00 2001 From: KYUNGMO TAK Date: Fri, 8 May 2026 14:26:29 +0900 Subject: [PATCH] Modified if modules are not install, pass --- Custom_Lib.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Custom_Lib.py b/Custom_Lib.py index 9cc6277..2f14f7b 100644 --- a/Custom_Lib.py +++ b/Custom_Lib.py @@ -1,30 +1,51 @@ __version__ = "1.0.3" -# --- custom --- +# --- required modules --- from custom_lib import my_file_config from custom_lib import my_logger from custom_lib import my_uuid -# 20260507 tak add my_image -from custom_lib import my_image -# 20260508 tak add my_crawling -from custom_lib import my_crawling MODULES = [ my_file_config, my_logger, my_uuid, - my_image, - my_crawling ] -def print_versions(): - for module in MODULES: +# --- optional modules --- +OPTIONAL_MODULES = [] +MISSING_MODULES = [] + +def _try_import_optional(module_path): + try: + module = __import__(f"custom_lib.{module_path}", fromlist=["*"]) + OPTIONAL_MODULES.append(module) + return True + except ImportError: + MISSING_MODULES.append(module_path.split(".")[1]) + return False + + +# 20260507 tak add my_image +_try_import_optional("image.my_image") + +# 20260508 tak add my_crawling +_try_import_optional("crawling.my_crawling") + +def print_modules(): + for module in MODULES + OPTIONAL_MODULES: version = getattr(module, "__version__", "unknown") print(f"# [MODULE] {module.__name__} v{version}") +def print_missing_modules(): + for module in MISSING_MODULES: + print(f"# [MISSING] {module}") + def init(): print("\n" + "#" * 60) print(f"# Custom_Lib v{__version__}") print("=" * 60) - print_versions() + + print_modules() + print_missing_modules() + print("#" * 60) \ No newline at end of file