Commit 33a900ea0fddd57168adcc732fffb6c05e3dfc79

Authored by Matheus de Sousa Faria
1 parent 4e9516b0

Fix widget import path

Showing 1 changed file with 13 additions and 5 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) 148 msg = "The py file {} does not exist".format(py_path)
150 raise InaccessibleSettings(msg) 149 raise InaccessibleSettings(msg)
151 150
152 - py_settings = _load_py_file(settings_module, py_path) 151 + original_path = sys.path
  152 + sys.path.append(py_path)
  153 + importlib.import_module(settings_module)
153 154
154 - # Read settings from settings.d 155 + # Read settings from widgets.d
155 settings_dir = '/etc/colab/widgets.d' 156 settings_dir = '/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: