From eebbc859fc6ccec0583c2e5ff0f9ea68cf2e2c0f Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" Date: Thu, 7 Nov 2019 16:06:26 +0100 Subject: [PATCH] lister.cli: Clarify configuration loading step --- swh/lister/cli.py | 10 ++++------ swh/lister/tests/test_cli.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/swh/lister/cli.py b/swh/lister/cli.py index a5ed46c..83c5c88 100644 --- a/swh/lister/cli.py +++ b/swh/lister/cli.py @@ -54,17 +54,15 @@ def lister(ctx, config_file, db_url): from swh.core import config ctx.ensure_object(dict) - override_conf = {} + if not config_file: + config_file = os.environ.get('SWH_CONFIG_FILENAME') + conf = config.read(config_file) if db_url: - override_conf['lister'] = { + conf['lister'] = { 'cls': 'local', 'args': {'db': db_url} } - if not config_file: - config_file = os.environ.get('SWH_CONFIG_FILENAME') - conf = config.read(config_file, override_conf) ctx.obj['config'] = conf - ctx.obj['override_conf'] = override_conf @lister.command(name='db-init', context_settings=CONTEXT_SETTINGS) diff --git a/swh/lister/tests/test_cli.py b/swh/lister/tests/test_cli.py index 6039ea4..2e9f9a1 100644 --- a/swh/lister/tests/test_cli.py +++ b/swh/lister/tests/test_cli.py @@ -98,21 +98,22 @@ def test_get_lister_override(): def test_task_types(swh_scheduler_config, tmp_path): - db_url = init_db().url() - configfile = tmp_path / 'config.yml' - configfile.write_text(yaml.dump({'scheduler': { - 'cls': 'local', - 'args': swh_scheduler_config}})) + config = { + 'scheduler': { + 'cls': 'local', + 'args': swh_scheduler_config + } + } + configfile.write_text(yaml.dump(config)) runner = CliRunner() result = runner.invoke(cli, [ - '--db-url', db_url, '--config-file', configfile.as_posix(), 'register-task-types']) assert result.exit_code == 0, traceback.print_exception(*result.exc_info) - scheduler = get_scheduler(cls='local', args=swh_scheduler_config) + scheduler = get_scheduler(**config['scheduler']) all_tasks = [ 'list-bitbucket-full', 'list-bitbucket-incremental', 'list-cran', @@ -125,7 +126,7 @@ def test_task_types(swh_scheduler_config, tmp_path): 'list-phabricator-full', 'list-packagist', 'list-pypi', - ] + ] for task in all_tasks: task_type_desc = scheduler.get_task_type(task) assert task_type_desc