Browse Source

Evaluate module paths relative to the config file or the code path

master
JustAnotherArchivist 4 years ago
parent
commit
f1275fc7ca
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      http2irc.py

+ 8
- 2
http2irc.py View File

@@ -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')


Loading…
Cancel
Save