Included scripts_dir parent dir on sys.path so scripts can import members through the "scripts" package

This commit is contained in:
Fabio Manganiello 2020-04-10 00:40:46 +02:00
parent 0cd28f7499
commit 25ea0ea77c

View file

@ -3,6 +3,7 @@ import importlib
import inspect import inspect
import logging import logging
import os import os
import pathlib
import pkgutil import pkgutil
import re import re
import socket import socket
@ -81,6 +82,11 @@ class Config(object):
with open(init_py, 'w') as f: with open(init_py, 'w') as f:
f.write('# Auto-generated __init__.py - do not remove\n') f.write('# Auto-generated __init__.py - do not remove\n')
# Include scripts_dir parent in sys.path so members can be imported in scripts
# through the `scripts` package
scripts_parent_dir = str(pathlib.Path(self._config['scripts_dir']).absolute().parent)
sys.path = [scripts_parent_dir] + sys.path
self._config['db'] = self._config.get('main.db', { self._config['db'] = self._config.get('main.db', {
'engine': 'sqlite:///' + os.path.join( 'engine': 'sqlite:///' + os.path.join(
os.path.expanduser('~'), '.local', 'share', 'platypush', 'main.db') os.path.expanduser('~'), '.local', 'share', 'platypush', 'main.db')