Skip to content

Commit c7867ab

Browse files
committed
Rewrite generate() to make pylint happy (less branches)
Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent 67601b4 commit c7867ab

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

kernelci/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def call(*args, **kwargs):
9292
except KeyError as ex:
9393
traceback.print_exc()
9494
raise click.ClickException(
95-
f"KernelCI Error: Value not found for {str(ex)}") from ex
95+
f"Key Error: Value not found for {str(ex)}") from ex
9696
return call
9797

9898

kernelci/cli/job.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,7 @@ def generate(node_id, # pylint: disable=too-many-arguments, too-many-locals
108108
configs['storage'][storage]
109109
if storage else None
110110
)
111-
if not runtime:
112-
raise click.ClickException("No runtime provided (--runtime)")
113-
runtimes_section = configs.get('runtimes', None)
114-
if runtimes_section is None:
115-
raise click.ClickException("No runtimes section found in the config")
116-
runtime_config = runtimes_section.get(runtime, None)
117-
if runtime_config is None:
118-
raise click.ClickException(f"Runtime {runtime} not found in the config")
119-
runtime = kernelci.runtime.get_runtime(
120-
runtime_config, token=secrets.api.runtime_token,
121-
custom_template_dir=config[0] if config else None)
111+
runtime = _get_runtime(runtime, config, secrets)
122112
params = runtime.get_params(job, api.config)
123113
if not params:
124114
raise click.ClickException("Invalid job parameters, aborting...")
@@ -138,6 +128,16 @@ def generate(node_id, # pylint: disable=too-many-arguments, too-many-locals
138128
click.echo(job_data)
139129

140130

131+
def _get_runtime(runtime, config, secrets):
132+
configs = kernelci.config.load(config)
133+
runtime_config = configs['runtimes'][runtime]
134+
runtime = kernelci.runtime.get_runtime(
135+
runtime_config, token=secrets.api.runtime_token,
136+
custom_template_dir=config[0] if config else None
137+
)
138+
return runtime
139+
140+
141141
@kci_job.command(secrets=True)
142142
@click.argument('job-path')
143143
@click.option('--wait', is_flag=True)

kernelci/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_config_paths(config_paths):
3838
for config_path in ['config/core', '/etc/kernelci/core']:
3939
if os.path.isdir(config_path):
4040
config_paths.append(config_path)
41+
break
4142
elif isinstance(config_paths, str):
4243
config_paths = [config_paths]
4344
return config_paths

0 commit comments

Comments
 (0)