From 26bd90b260e55b4afdcf956f86583ca3c7576c66 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Tue, 5 Jun 2018 21:01:04 -0230 Subject: [PATCH] zulip_bots: Display neat error message for missing bot dependencies. We just moved the logic for installing bot dependencies from setup.py to tools/provision. So bot dependencies are not automatically installed anymore as a part of the base package. Now, if there is an import error caused by missing dependency, we display a neat error message asking the user to provision bot dependencies. --- zulip_bots/zulip_bots/run.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index d7e97d1..aa2082d 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -114,7 +114,20 @@ def main() -> None: if args.provision: provision_bot(os.path.dirname(bot_path), args.force) - lib_module = import_module_from_source(bot_path, bot_name) + try: + lib_module = import_module_from_source(bot_path, bot_name) + except ImportError as e: + req_path = os.path.join(os.path.dirname(bot_path), "requirements.txt") + with open(req_path) as fp: + deps_list = fp.read() + + dep_err_msg = ("ERROR: The following dependencies for the {bot_name} bot are not installed:\n\n" + "{deps_list}\n" + "If you'd like us to install these dependencies, run:\n" + " zulip-run-bot {bot_name} --provision") + print(dep_err_msg.format(bot_name=bot_name, deps_list=deps_list)) + sys.exit(1) + if lib_module is None: print("ERROR: Could not load bot module. Exiting now.") sys.exit(1)