changeset 8654:2228102b99ab

extensions: preparatory refactoring Small refactoring: - use 'try..except' rather than 'if-then', which removes the need for a separate 'path' variable and is more 'pythonic'. - promote log from 'debug' to 'info' and execute it immediately after loading before anything else. - clarify comments related to INDEX_EXTENSIONS
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Fri, 09 Oct 2020 13:59:52 +0200
parents ec73bce93d6a
children e3d8f4bc3ce7
files kallithea/lib/utils.py
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/utils.py	Fri Oct 09 13:39:08 2020 +0200
+++ b/kallithea/lib/utils.py	Fri Oct 09 13:59:52 2020 +0200
@@ -521,24 +521,25 @@
 
 
 def load_extensions(root_path):
-    path = os.path.join(root_path, 'rcextensions', '__init__.py')
-    if os.path.isfile(path):
-        ext = create_module('rc', path)
-        kallithea.EXTENSIONS = ext
-        log.debug('Found rcextensions now loading %s...', ext)
+    try:
+        ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py'))
+    except FileNotFoundError:
+        return
 
-        # Additional mappings that are not present in the pygments lexers
-        kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(ext, 'EXTRA_MAPPINGS', {}))
+    log.info('Loaded rcextensions from %s', ext)
+    kallithea.EXTENSIONS = ext
 
-        # OVERRIDE OUR EXTENSIONS FROM RC-EXTENSIONS (if present)
+    # Additional mappings that are not present in the pygments lexers
+    kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(ext, 'EXTRA_MAPPINGS', {}))
 
-        if getattr(ext, 'INDEX_EXTENSIONS', []):
-            log.debug('settings custom INDEX_EXTENSIONS')
-            kallithea.config.conf.INDEX_EXTENSIONS = getattr(ext, 'INDEX_EXTENSIONS', [])
+    # Override any INDEX_EXTENSIONS
+    if getattr(ext, 'INDEX_EXTENSIONS', []):
+        log.debug('settings custom INDEX_EXTENSIONS')
+        kallithea.config.conf.INDEX_EXTENSIONS = getattr(ext, 'INDEX_EXTENSIONS', [])
 
-        # ADDITIONAL MAPPINGS
-        log.debug('adding extra into INDEX_EXTENSIONS')
-        kallithea.config.conf.INDEX_EXTENSIONS.extend(getattr(ext, 'EXTRA_INDEX_EXTENSIONS', []))
+    # Additional INDEX_EXTENSIONS
+    log.debug('adding extra into INDEX_EXTENSIONS')
+    kallithea.config.conf.INDEX_EXTENSIONS.extend(getattr(ext, 'EXTRA_INDEX_EXTENSIONS', []))
 
 
 #==============================================================================