From 25ea0ea77c081f1a1f12081e42957549c91359d3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 10 Apr 2020 00:40:46 +0200 Subject: [PATCH] Included scripts_dir parent dir on sys.path so scripts can import members through the "scripts" package --- platypush/config/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platypush/config/__init__.py b/platypush/config/__init__.py index d1eb7447..8f4673ba 100644 --- a/platypush/config/__init__.py +++ b/platypush/config/__init__.py @@ -3,6 +3,7 @@ import importlib import inspect import logging import os +import pathlib import pkgutil import re import socket @@ -81,6 +82,11 @@ class Config(object): with open(init_py, 'w') as f: 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', { 'engine': 'sqlite:///' + os.path.join( os.path.expanduser('~'), '.local', 'share', 'platypush', 'main.db')