From f1275fc7cab2014b9420f1e43369a0616290023f Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 18 May 2020 22:58:32 +0000 Subject: [PATCH] Evaluate module paths relative to the config file or the code path --- http2irc.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/http2irc.py b/http2irc.py index e6cfd70..bd0133a 100644 --- a/http2irc.py +++ b/http2irc.py @@ -153,8 +153,14 @@ class Config(dict): if isinstance(map_['auth'], str) and ':' not in map_['auth']: raise InvalidConfig(f'Invalid map {key!r} auth: must contain a colon') - if 'module' in map_ and not os.path.isfile(map_['module']): - raise InvalidConfig(f'Module {map_["module"]!r} in map {key!r} is not a file') + if 'module' in map_: + # If the path is relative, try to evaluate it relative to either the config file or this file; some modules are in the repo, but this also allows overriding them. + for basePath in (os.path.dirname(self._filename), os.path.dirname(__file__)): + if os.path.isfile(os.path.join(basePath, map_['module'])): + map_['module'] = os.path.abspath(os.path.join(basePath, map_['module'])) + break + else: + raise InvalidConfig(f'Module {map_["module"]!r} in map {key!r} is not a file') if 'moduleargs' in map_: if not isinstance(map_['moduleargs'], list): raise InvalidConfig(f'Invalid module args for {key!r}: not an array')