Commit c37e85723d676245ddf2fa1012549f60d998676e

Authored by Matheus de Sousa Faria
Committed by Gust
1 parent d5f5978f

Fix widget import path

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