Changeset - 7c2704784297
[Not reviewed]
stable
0 5 0
Mads Kiilerich (mads) - 18 months ago 2024-09-22 19:08:29
mads@kiilerich.com
Grafted from: ec090899c2b7
wsgi: Refactor to introduce make_app_raw function with the essentials of make_app

Command line commands and WSGI applications have different environments and
runtime models. They deserve different handling.

Keep make_app doing as before so WSGI scripts keep working as before.

All "app" usage from command line is changed to use make_app_raw directly.
5 files changed with 10 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_base.py
Show inline comments
 
@@ -76,11 +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:
 
                    kallithea.config.application.make_app(config.global_conf, **config.local_conf)
 
                    kallithea.config.application.make_app_raw(config.global_conf, **config.local_conf)
 
                    annotated(*args, **kwargs)
 
            return cli_command(runtime_wrapper)
 
        return annotator
 
    return cli_command
kallithea/bin/kallithea_cli_celery.py
Show inline comments
 
@@ -37,13 +37,13 @@ def celery_run(celery_args, config):
 
    if not asbool(config.get('use_celery')):
 
        raise Exception('Please set use_celery = true in .ini config '
 
                        'file before running this command')
 

	
 
    kallithea.CELERY_APP.config_from_object(celery_app.make_celery_config(config))
 

	
 
    kallithea.CELERY_APP.loader.on_worker_process_init = lambda: kallithea.config.application.make_app(config.global_conf, **config.local_conf)
 
    kallithea.CELERY_APP.loader.on_worker_process_init = lambda: kallithea.config.application.make_app_raw(config.global_conf, **config.local_conf)
 

	
 
    args = list(celery_args)
 
    # args[0] is generally ignored when prog_name is specified, but -h *needs* it to be 'worker' ... but will also suggest that users specify 'worker' explicitly
 
    if not args or args[0] != 'worker':
 
        args.insert(0, 'worker')
 

	
kallithea/bin/vcs_hooks.py
Show inline comments
 
@@ -113,13 +113,13 @@ def _git_hook_environment(repo_path):
 
    """
 
    extras = get_hook_environment()
 

	
 
    path_to_ini_file = extras['config']
 
    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(config.global_conf, **config.local_conf)
 
    kallithea.config.application.make_app_raw(config.global_conf, **config.local_conf)
 

	
 
    # fix if it's not a bare repo
 
    if repo_path.endswith(os.sep + '.git'):
 
        repo_path = repo_path[:-5]
 

	
 
    repo = db.Repository.get_by_full_path(repo_path)
kallithea/config/application.py
Show inline comments
 
@@ -45,12 +45,18 @@ def wrap_app(app):
 
        app = RequestWrapper(app, config)
 

	
 
    return app
 

	
 

	
 
def make_app(global_conf, **app_conf):
 
    """Return WSGI app with logging Mercurial stdout/stderr - to be used as
 
    Paste or mod_wsgi entry point"""
 
    return make_app_raw(global_conf, **app_conf)
 

	
 

	
 
def make_app_raw(global_conf, **app_conf):
 
    """
 
    Set up Kallithea with the settings found in the PasteDeploy configuration
 
    file used.
 

	
 
    :param global_conf: The global settings for Kallithea (those
 
        defined under the ``[DEFAULT]`` section).
kallithea/tests/scripts/manual_test_concurrency.py
Show inline comments
 
@@ -44,13 +44,13 @@ from kallithea.model.base import init_mo
 
from kallithea.model.repo import RepoModel
 
from kallithea.tests.base import HG_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
 

	
 

	
 
rel_path = dirname(dirname(dirname(dirname(os.path.abspath(__file__)))))
 
conf = appconfig('config:development.ini', relative_to=rel_path)
 
kallithea.config.application.make_app(conf.global_conf, **conf.local_conf)
 
kallithea.config.application.make_app_raw(conf.global_conf, **conf.local_conf)
 

	
 
USER = TEST_USER_ADMIN_LOGIN
 
PASS = TEST_USER_ADMIN_PASS
 
HOST = 'server.local'
 
METHOD = 'pull'
 
DEBUG = True
0 comments (0 inline, 0 general)