Skip to content

Commit 36c1ee6

Browse files
committed
Fix pycodestyle complaints
Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent a652096 commit 36c1ee6

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

kernelci/cli/job.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def new(name, input_node_id, platform, # pylint: disable=too-many-arguments
5555
if runtime not in configs['runtimes']:
5656
raise click.ClickException(f"Invalid runtime {runtime}")
5757
runtime = kernelci.runtime.get_runtime(
58-
configs['runtimes'][runtime], token=secrets.api.runtime_token, custom_template_dir=config[0] if config else None)
58+
configs['runtimes'][runtime], token=secrets.api.runtime_token,
59+
custom_template_dir=config[0] if config else None)
5960
job_node = helper.create_job_node(job_config, input_node,
6061
platform=platform_config, runtime=runtime)
6162
if job_node:
@@ -107,16 +108,7 @@ def generate(node_id, # pylint: disable=too-many-arguments, too-many-locals
107108
configs['storage'][storage]
108109
if storage else None
109110
)
110-
if not runtime:
111-
raise click.ClickException("No runtime provided (--runtime)")
112-
runtimes_section = configs.get('runtimes', None)
113-
if runtimes_section is None:
114-
raise click.ClickException("No runtimes section found in the config")
115-
runtime_config = runtimes_section.get(runtime, None)
116-
if runtime_config is None:
117-
raise click.ClickException(f"Runtime {runtime} not found in the config")
118-
runtime = kernelci.runtime.get_runtime(
119-
runtime_config, token=secrets.api.runtime_token, custom_template_dir=config[0] if config else None)
111+
runtime = _get_runtime(runtime, config, secrets)
120112
params = runtime.get_params(job, api.config)
121113
if not params:
122114
raise click.ClickException("Invalid job parameters, aborting...")
@@ -136,6 +128,23 @@ def generate(node_id, # pylint: disable=too-many-arguments, too-many-locals
136128
click.echo(job_data)
137129

138130

131+
def _get_runtime(runtime, config, secrets):
132+
if not runtime:
133+
raise click.ClickException("Runtime not specified, please provide --runtime argument")
134+
configs = kernelci.config.load(config)
135+
runtime_section = configs.get('runtimes', None)
136+
if runtime_section is None:
137+
raise click.ClickException("No runtime section found in the config")
138+
runtime_config = runtime_section.get(runtime, None)
139+
if runtime_config is None:
140+
raise click.ClickException(f"Runtime {runtime} not found in the config")
141+
runtime = kernelci.runtime.get_runtime(
142+
runtime_config, token=secrets.api.runtime_token,
143+
custom_template_dir=config[0] if config else None
144+
)
145+
return runtime
146+
147+
139148
@kci_job.command(secrets=True)
140149
@click.argument('job-path')
141150
@click.option('--wait', is_flag=True)
@@ -149,7 +158,8 @@ def submit(runtime, job_path, wait, # pylint: disable=too-many-arguments
149158
configs = kernelci.config.load(config)
150159
runtime_config = configs['runtimes'][runtime]
151160
runtime = kernelci.runtime.get_runtime(
152-
runtime_config, token=secrets.api.runtime_token, custom_template_dir=config[0] if config else None
161+
runtime_config, token=secrets.api.runtime_token,
162+
custom_template_dir=config[0] if config else None
153163
)
154164
job = runtime.submit(job_path)
155165
click.echo(runtime.get_job_id(job))

kernelci/runtime/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ def __init__(self, config, user=None, token=None, custom_template_dir=None):
8888
self._templates.append(custom_template_dir)
8989
# Add relevant subdirectories
9090
for subdir in ["runtime", "runtime/base", "runtime/boot", "runtime/tests"]:
91-
sub_path = os.path.join(custom_template_dir, subdir) if not custom_template_dir.endswith(subdir) else custom_template_dir
91+
sub_path = (
92+
os.path.join(custom_template_dir, subdir)
93+
if not custom_template_dir.endswith(subdir)
94+
else custom_template_dir
95+
)
9296
if os.path.isdir(sub_path):
9397
self._templates.append(sub_path)
9498
self._user = user
@@ -231,7 +235,8 @@ def get_runtime(config, user=None, token=None, custom_template_dir=None):
231235
"""
232236
module_name = '.'.join(['kernelci', 'runtime', config.lab_type])
233237
runtime_module = importlib.import_module(module_name)
234-
return runtime_module.get_runtime(config, user=user, token=token, custom_template_dir=custom_template_dir)
238+
return runtime_module.get_runtime(config, user=user, token=token,
239+
custom_template_dir=custom_template_dir)
235240

236241

237242
def get_all_runtimes(runtime_configs, opts, custom_template_dir=None):
@@ -251,7 +256,8 @@ def get_all_runtimes(runtime_configs, opts, custom_template_dir=None):
251256
opts.get_from_section(section, opt)
252257
for opt in ('user', 'runtime_token')
253258
)
254-
runtime = get_runtime(config, user=user, token=token, custom_template_dir=custom_template_dir)
259+
runtime = get_runtime(config, user=user, token=token,
260+
custom_template_dir=custom_template_dir)
255261
yield config_name, runtime
256262

257263

0 commit comments

Comments
 (0)