@@ -48,13 +48,6 @@ def parse_args() -> argparse.Namespace:
48
48
help = "try running the bot even if dependencies install fails" ,
49
49
)
50
50
51
- parser .add_argument (
52
- "--registry" ,
53
- "-r" ,
54
- action = "store_true" ,
55
- help = "run the bot via zulip_bots registry" ,
56
- )
57
-
58
51
parser .add_argument ("--provision" , action = "store_true" , help = "install dependencies for the bot" )
59
52
60
53
args = parser .parse_args ()
@@ -116,50 +109,49 @@ def exit_gracefully_if_bot_config_file_does_not_exist(bot_config_file: Optional[
116
109
def main () -> None :
117
110
args = parse_args ()
118
111
119
- if args .registry :
112
+ result = finder .resolve_bot_path (args .bot )
113
+ if result :
114
+ bot_path , bot_name = result
115
+ sys .path .insert (0 , os .path .dirname (bot_path ))
116
+
117
+ if args .provision :
118
+ provision_bot (os .path .dirname (bot_path ), args .force )
119
+
120
120
try :
121
- bot_source , lib_module = finder .import_module_from_zulip_bot_registry (args .bot )
122
- except finder .DuplicateRegisteredBotName as error :
123
- print (
124
- f'ERROR: Found duplicate entries for "{ error } " in zulip bots registry.\n '
125
- "Make sure that you don't install bots using the same entry point. Exiting now."
121
+ lib_module = finder .import_module_from_source (bot_path .as_posix (), bot_name )
122
+ except ImportError :
123
+ req_path = os .path .join (os .path .dirname (bot_path ), "requirements.txt" )
124
+ with open (req_path ) as fp :
125
+ deps_list = fp .read ()
126
+
127
+ dep_err_msg = (
128
+ "ERROR: The following dependencies for the {bot_name} bot are not installed:\n \n "
129
+ "{deps_list}\n "
130
+ "If you'd like us to install these dependencies, run:\n "
131
+ " zulip-run-bot {bot_name} --provision"
126
132
)
133
+ print (dep_err_msg .format (bot_name = bot_name , deps_list = deps_list ))
127
134
sys .exit (1 )
128
- if lib_module :
129
- bot_name = args .bot
135
+ bot_source = "source"
130
136
else :
131
- result = finder .resolve_bot_path (args .bot )
132
- if result :
133
- bot_path , bot_name = result
134
- sys .path .insert (0 , os .path .dirname (bot_path ))
135
-
137
+ lib_module = finder .import_module_by_name (args .bot )
138
+ if lib_module and hasattr (lib_module , "handler_class" ):
139
+ bot_name = lib_module .__name__
140
+ bot_source = "named module"
136
141
if args .provision :
137
- provision_bot (os .path .dirname (bot_path ), args .force )
138
-
142
+ print ("ERROR: Could not load bot's module for '{}'. Exiting now." )
143
+ sys .exit (1 )
144
+ else :
139
145
try :
140
- lib_module = finder .import_module_from_source (bot_path .as_posix (), bot_name )
141
- except ImportError :
142
- req_path = os .path .join (os .path .dirname (bot_path ), "requirements.txt" )
143
- with open (req_path ) as fp :
144
- deps_list = fp .read ()
145
-
146
- dep_err_msg = (
147
- "ERROR: The following dependencies for the {bot_name} bot are not installed:\n \n "
148
- "{deps_list}\n "
149
- "If you'd like us to install these dependencies, run:\n "
150
- " zulip-run-bot {bot_name} --provision"
146
+ bot_source , lib_module = finder .import_module_from_zulip_bot_registry (args .bot )
147
+ except finder .DuplicateRegisteredBotName as error :
148
+ print (
149
+ f'ERROR: Found duplicate entries for "{ error } " in zulip bots registry.\n '
150
+ "Make sure that you don't install bots using the same entry point. Exiting now."
151
151
)
152
- print (dep_err_msg .format (bot_name = bot_name , deps_list = deps_list ))
153
152
sys .exit (1 )
154
- bot_source = "source"
155
- else :
156
- lib_module = finder .import_module_by_name (args .bot )
157
153
if lib_module :
158
- bot_name = lib_module .__name__
159
- bot_source = "named module"
160
- if args .provision :
161
- print ("ERROR: Could not load bot's module for '{}'. Exiting now." )
162
- sys .exit (1 )
154
+ bot_name = args .bot
163
155
164
156
if lib_module is None :
165
157
print ("ERROR: Could not load bot module. Exiting now." )
0 commit comments