Commit e0b7a339f48ba160af8a5f076f149e5d7aef4474
1 parent
54ff2674
Exists in
profile_integration
Fix widget import path
Showing
1 changed file
with
16 additions
and
8 deletions
Show diff stats
colab/utils/conf.py
@@ -142,30 +142,38 @@ def load_widgets_settings(): | @@ -142,30 +142,38 @@ def load_widgets_settings(): | ||
142 | '/etc/colab/widgets_settings.py') | 142 | '/etc/colab/widgets_settings.py') |
143 | settings_module = settings_file.split('.')[-2].split('/')[-1] | 143 | settings_module = settings_file.split('.')[-2].split('/')[-1] |
144 | py_path = "/".join(settings_file.split('/')[:-1]) | 144 | py_path = "/".join(settings_file.split('/')[:-1]) |
145 | - | ||
146 | logger.info('Widgets Settings file: %s', settings_file) | 145 | logger.info('Widgets Settings file: %s', settings_file) |
147 | 146 | ||
148 | if not os.path.exists(py_path): | 147 | if not os.path.exists(py_path): |
149 | - msg = "The py file {} does not exist".format(py_path) | ||
150 | - raise InaccessibleSettings(msg) | 148 | + return |
151 | 149 | ||
152 | - py_settings = _load_py_file(settings_module, py_path) | 150 | + original_path = sys.path |
151 | + sys.path.append(py_path) | ||
152 | + importlib.import_module(settings_module) | ||
153 | 153 | ||
154 | - # Read settings from settings.d | ||
155 | - settings_dir = '/etc/colab/widgets.d' | 154 | + # Read settings from widgets.d |
155 | + settings_dir = os.getenv('COLAB_WIDGETS', | ||
156 | + '/etc/colab/widgets.d') | ||
156 | logger.info('Widgets Settings directory: %s', settings_dir) | 157 | logger.info('Widgets Settings directory: %s', settings_dir) |
158 | + sys.path = original_path | ||
157 | 159 | ||
158 | if not os.path.exists(settings_dir): | 160 | if not os.path.exists(settings_dir): |
159 | - return py_settings | 161 | + return |
160 | 162 | ||
161 | for file_name in os.listdir(settings_dir): | 163 | for file_name in os.listdir(settings_dir): |
162 | if not file_name.endswith('.py'): | 164 | if not file_name.endswith('.py'): |
163 | continue | 165 | continue |
164 | 166 | ||
167 | + original_path = sys.path | ||
168 | + sys.path.append(settings_dir) | ||
169 | + | ||
165 | file_module = file_name.split('.')[0] | 170 | file_module = file_name.split('.')[0] |
166 | - _load_py_file(file_module, settings_dir) | 171 | + importlib.import_module(file_module) |
167 | logger.info('Loaded %s/%s', settings_dir, file_name) | 172 | logger.info('Loaded %s/%s', settings_dir, file_name) |
168 | 173 | ||
174 | + sys.path = original_path | ||
175 | + | ||
176 | + | ||
169 | def validate_database(database_dict, default_db, debug): | 177 | def validate_database(database_dict, default_db, debug): |
170 | db_name = database_dict.get('default', {}).get('NAME') | 178 | db_name = database_dict.get('default', {}).get('NAME') |
171 | if not debug and db_name == default_db: | 179 | if not debug and db_name == default_db: |