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 | 142 | '/etc/colab/widgets_settings.py') |
143 | 143 | settings_module = settings_file.split('.')[-2].split('/')[-1] |
144 | 144 | py_path = "/".join(settings_file.split('/')[:-1]) |
145 | - | |
146 | 145 | logger.info('Widgets Settings file: %s', settings_file) |
147 | 146 | |
148 | 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 | 157 | logger.info('Widgets Settings directory: %s', settings_dir) |
158 | + sys.path = original_path | |
157 | 159 | |
158 | 160 | if not os.path.exists(settings_dir): |
159 | - return py_settings | |
161 | + return | |
160 | 162 | |
161 | 163 | for file_name in os.listdir(settings_dir): |
162 | 164 | if not file_name.endswith('.py'): |
163 | 165 | continue |
164 | 166 | |
167 | + original_path = sys.path | |
168 | + sys.path.append(settings_dir) | |
169 | + | |
165 | 170 | file_module = file_name.split('.')[0] |
166 | - _load_py_file(file_module, settings_dir) | |
171 | + importlib.import_module(file_module) | |
167 | 172 | logger.info('Loaded %s/%s', settings_dir, file_name) |
168 | 173 | |
174 | + sys.path = original_path | |
175 | + | |
176 | + | |
169 | 177 | def validate_database(database_dict, default_db, debug): |
170 | 178 | db_name = database_dict.get('default', {}).get('NAME') |
171 | 179 | if not debug and db_name == default_db: | ... | ... |