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 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 148 msg = "The py file {} does not exist".format(py_path)
150 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 156 settings_dir = '/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:
... ...