changeset 8622:cd8d45d4c3cd

config: only assign kallitha.CONFIG once and keep it as a plain dict Mute pytype warnings and make code more readable for developers: File "kallithea/lib/hooks.py", line 318, in _hook_environment: No attribute 'global_conf' on Dict[nothing, nothing] [attribute-error] File "kallithea/lib/hooks.py", line 318, in _hook_environment: No attribute 'local_conf' on Dict[nothing, nothing] [attribute-error] File "kallithea/bin/kallithea_cli_base.py", line 82, in runtime_wrapper: No attribute 'global_conf' on Dict[nothing, nothing] [attribute-error] File "kallithea/bin/kallithea_cli_base.py", line 82, in runtime_wrapper: No attribute 'local_conf' on Dict[nothing, nothing] [attribute-error]
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 18 Aug 2020 15:10:40 +0200
parents 3070f9bc6ebe
children ae3d9b4c043e
files kallithea/bin/kallithea_cli_base.py kallithea/lib/hooks.py
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_base.py	Mon Aug 24 13:07:08 2020 +0200
+++ b/kallithea/bin/kallithea_cli_base.py	Tue Aug 18 15:10:40 2020 +0200
@@ -71,15 +71,17 @@
             @functools.wraps(annotated) # reuse meta data from the wrapped function so click can see other options
             def runtime_wrapper(config_file, *args, **kwargs):
                 path_to_ini_file = os.path.realpath(config_file)
-                kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
+                config = paste.deploy.appconfig('config:' + path_to_ini_file)
                 cp = configparser.ConfigParser(strict=False)
                 cp.read_string(read_config(path_to_ini_file, strip_section_prefix=annotated.__name__))
                 logging.config.fileConfig(cp,
                     {'__file__': path_to_ini_file, 'here': os.path.dirname(path_to_ini_file)})
                 if config_file_initialize_app:
                     if needs_config_file:  # special case for db creation: also call annotated function (with config parameter) *before* app initialization
-                        annotated(*args, config=kallithea.CONFIG, **kwargs)
-                    kallithea.config.application.make_app(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
+                        annotated(*args, config=config, **kwargs)
+                    kallithea.config.application.make_app(config.global_conf, **config.local_conf)
+                else:
+                    kallithea.CONFIG = dict(config)  # config is a dict subclass
                 return annotated(*args, **kwargs)
             return cli_command(runtime_wrapper)
         return annotator
--- a/kallithea/lib/hooks.py	Mon Aug 24 13:07:08 2020 +0200
+++ b/kallithea/lib/hooks.py	Tue Aug 18 15:10:40 2020 +0200
@@ -313,9 +313,9 @@
     extras = get_hook_environment()
 
     path_to_ini_file = extras['config']
-    kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
+    config = paste.deploy.appconfig('config:' + path_to_ini_file)
     #logging.config.fileConfig(ini_file_path) # Note: we are in a different process - don't use configured logging
-    kallithea.config.application.make_app(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
+    kallithea.config.application.make_app(config.global_conf, **config.local_conf)
 
     # fix if it's not a bare repo
     if repo_path.endswith(os.sep + '.git'):