Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit a9bf314

Browse files
authored
Merge pull request #59 from jammons/make_plugin_imports_work_in_windows
Change to using sys.path and other windows compatibility changes
2 parents 14442f3 + a8ee0a4 commit a9bf314

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

rtmbot/core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, config):
3131
self.token = config.get('SLACK_TOKEN')
3232

3333
# set working directory for loading plugins or other files
34-
working_directory = os.path.dirname(sys.argv[0])
34+
working_directory = os.path.abspath(os.path.dirname(sys.argv[0]))
3535
self.directory = self.config.get('BASE_PATH', working_directory)
3636
if not self.directory.startswith('/'):
3737
path = '{}/{}'.format(os.getcwd(), self.directory)
@@ -109,13 +109,14 @@ def crons(self):
109109
plugin.do_jobs()
110110

111111
def load_plugins(self):
112-
for plugin in glob.glob(self.directory + '/plugins/*'):
112+
plugin_dir = os.path.join(self.directory, 'plugins')
113+
for plugin in glob.glob(os.path.join(plugin_dir, '*')):
113114
sys.path.insert(0, plugin)
114-
sys.path.insert(0, self.directory + '/plugins/')
115-
for plugin in glob.glob(self.directory + '/plugins/*.py') + \
116-
glob.glob(self.directory + '/plugins/*/*.py'):
115+
sys.path.insert(0, plugin_dir)
116+
for plugin in glob.glob(os.path.join(plugin_dir, '*.py')) + \
117+
glob.glob(os.path.join(plugin_dir, '*', '*.py')):
117118
logging.info(plugin)
118-
name = plugin.split('/')[-1][:-3]
119+
name = plugin.split(os.sep)[-1][:-3]
119120
if name in self.config:
120121
logging.info("config found for: " + name)
121122
plugin_config = self.config.get(name, {})

0 commit comments

Comments
 (0)