# HG changeset patch # User Mads Kiilerich # Date 2020-08-18 15:10:40 # Node ID cd8d45d4c3cde82ce9c53d81e64fefdd495bab76 # Parent 3070f9bc6ebe735ea3e8a1d0c4694a252c3c263d 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] diff --git a/kallithea/bin/kallithea_cli_base.py b/kallithea/bin/kallithea_cli_base.py --- a/kallithea/bin/kallithea_cli_base.py +++ b/kallithea/bin/kallithea_cli_base.py @@ -71,15 +71,17 @@ def register_command(needs_config_file=F @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 diff --git a/kallithea/lib/hooks.py b/kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py +++ b/kallithea/lib/hooks.py @@ -313,9 +313,9 @@ def _hook_environment(repo_path): 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'):