File tree Expand file tree Collapse file tree 1 file changed +2
-13
lines changed
zulip_botserver/zulip_botserver Expand file tree Collapse file tree 1 file changed +2
-13
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
2
3
3
import configparser
4
- import importlib .abc
5
- import importlib .util
6
4
import json
7
5
import logging
8
6
import os
18
16
19
17
from zulip import Client
20
18
from zulip_bots import lib
19
+ from zulip_bots .finder import import_module_from_source
21
20
from zulip_botserver .input_parameters import parse_args
22
21
23
22
@@ -112,22 +111,12 @@ def parse_config_file(config_file_path: str) -> configparser.ConfigParser:
112
111
return parser
113
112
114
113
115
- # TODO: Could we use the function from the bots library for this instead?
116
- def load_module_from_file (file_path : str ) -> ModuleType :
117
- # Wrapper around importutil; see https://stackoverflow.com/a/67692/3909240.
118
- spec = importlib .util .spec_from_file_location ("custom_bot_module" , file_path )
119
- lib_module = importlib .util .module_from_spec (spec )
120
- assert isinstance (spec .loader , importlib .abc .Loader )
121
- spec .loader .exec_module (lib_module )
122
- return lib_module
123
-
124
-
125
114
def load_lib_modules (available_bots : List [str ]) -> Dict [str , ModuleType ]:
126
115
bots_lib_module = {}
127
116
for bot in available_bots :
128
117
try :
129
118
if bot .endswith (".py" ) and os .path .isfile (bot ):
130
- lib_module = load_module_from_file (bot )
119
+ lib_module = import_module_from_source (bot , "custom_bot_module" )
131
120
else :
132
121
module_name = "zulip_bots.bots.{bot}.{bot}" .format (bot = bot )
133
122
lib_module = import_module (module_name )
You can’t perform that action at this time.
0 commit comments