# HG changeset patch # User Mads Kiilerich # Date 2020-12-26 17:23:43 # Node ID e9521559d013b7e4a97aa86643997427839a39d0 # Parent 04c8edacc3a1a8146400c990c52ba886756b60ac cli: only config_file_initialize_app should set global CONFIG; needs_config_file will be passed the config object diff --git a/kallithea/__init__.py b/kallithea/__init__.py --- a/kallithea/__init__.py +++ b/kallithea/__init__.py @@ -42,7 +42,7 @@ BACKENDS = { CELERY_APP = None # set to Celery app instance if using Celery -CONFIG = {} +CONFIG = {} # set to tg.config when TG app is initialized and calls app_cfg # URL prefix for non repository related links - must start with `/` ADMIN_PREFIX = '/_admin' 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 @@ -76,13 +76,11 @@ def register_command(needs_config_file=F 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 needs_config_file: + annotated(*args, config=config, **kwargs) 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=config, **kwargs) kallithea.config.application.make_app(config.global_conf, **config.local_conf) - else: - kallithea.CONFIG = dict(config) # config is a dict subclass - annotated(*args, **kwargs) + annotated(*args, **kwargs) return cli_command(runtime_wrapper) return annotator return cli_command diff --git a/kallithea/bin/kallithea_cli_extensions.py b/kallithea/bin/kallithea_cli_extensions.py --- a/kallithea/bin/kallithea_cli_extensions.py +++ b/kallithea/bin/kallithea_cli_extensions.py @@ -24,20 +24,19 @@ import os import click import pkg_resources -import kallithea import kallithea.bin.kallithea_cli_base as cli_base from kallithea.lib.utils2 import ask_ok @cli_base.register_command(needs_config_file=True) -def extensions_create(): +def extensions_create(config): """Write template file for extending Kallithea in Python. Create a template `extensions.py` file next to the ini file. Local customizations in that file will survive upgrades. The file contains instructions on how it can be customized. """ - here = kallithea.CONFIG['here'] + here = config['here'] content = pkg_resources.resource_string( 'kallithea', os.path.join('templates', 'py', 'extensions.py') ) diff --git a/kallithea/bin/kallithea_cli_iis.py b/kallithea/bin/kallithea_cli_iis.py --- a/kallithea/bin/kallithea_cli_iis.py +++ b/kallithea/bin/kallithea_cli_iis.py @@ -16,7 +16,6 @@ import sys import click -import kallithea import kallithea.bin.kallithea_cli_base as cli_base @@ -60,10 +59,10 @@ if __name__=='__main__': @cli_base.register_command(needs_config_file=True) @click.option('--virtualdir', default='/', help='The virtual folder to install into on IIS.') -def iis_install(virtualdir): +def iis_install(virtualdir, config): """Install into IIS using isapi-wsgi.""" - config_file_abs = kallithea.CONFIG['__file__'] + config_file_abs = config['__file__'] try: import isapi_wsgi