@@ -48,6 +48,13 @@ 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 zulipt_bot registry" ,
56
+ )
57
+
51
58
parser .add_argument ("--provision" , action = "store_true" , help = "install dependencies for the bot" )
52
59
53
60
args = parser .parse_args ()
@@ -109,36 +116,45 @@ def exit_gracefully_if_bot_config_file_does_not_exist(bot_config_file: Optional[
109
116
def main () -> None :
110
117
args = parse_args ()
111
118
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
-
119
+ if args .registry :
120
120
try :
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"
132
- )
133
- print (dep_err_msg .format (bot_name = bot_name , deps_list = deps_list ))
121
+ lib_module = finder .import_module_from_zulip_bot_registry (args .bot )
122
+ except finder .DuplicateRegisteredBotName :
123
+ print ("ERROR: Found duplicate entries for bot name in zulip bot registry. Exiting now." )
134
124
sys .exit (1 )
135
- else :
136
- lib_module = finder .import_module_by_name (args .bot )
137
125
if lib_module :
138
- bot_name = lib_module .__name__
126
+ bot_name = args .bot
127
+ else :
128
+ result = finder .resolve_bot_path (args .bot )
129
+ if result :
130
+ bot_path , bot_name = result
131
+ sys .path .insert (0 , os .path .dirname (bot_path ))
132
+
139
133
if args .provision :
140
- print ("ERROR: Could not load bot's module for '{}'. Exiting now." )
134
+ provision_bot (os .path .dirname (bot_path ), args .force )
135
+
136
+ try :
137
+ lib_module = finder .import_module_from_source (bot_path .as_posix (), bot_name )
138
+ except ImportError :
139
+ req_path = os .path .join (os .path .dirname (bot_path ), "requirements.txt" )
140
+ with open (req_path ) as fp :
141
+ deps_list = fp .read ()
142
+
143
+ dep_err_msg = (
144
+ "ERROR: The following dependencies for the {bot_name} bot are not installed:\n \n "
145
+ "{deps_list}\n "
146
+ "If you'd like us to install these dependencies, run:\n "
147
+ " zulip-run-bot {bot_name} --provision"
148
+ )
149
+ print (dep_err_msg .format (bot_name = bot_name , deps_list = deps_list ))
141
150
sys .exit (1 )
151
+ else :
152
+ lib_module = finder .import_module_by_name (args .bot )
153
+ if lib_module :
154
+ bot_name = lib_module .__name__
155
+ if args .provision :
156
+ print ("ERROR: Could not load bot's module for '{}'. Exiting now." )
157
+ sys .exit (1 )
142
158
143
159
if lib_module is None :
144
160
print ("ERROR: Could not load bot module. Exiting now." )
0 commit comments