From 0fe13b03c32cd1cdb0312b1add1b9cece93c7e5f Mon Sep 17 00:00:00 2001 From: Giannis Doukas Date: Tue, 9 Jun 2020 18:00:52 +0100 Subject: [PATCH] cleanup --- cwlkernel/CWLBuilder.py | 2 +- cwlkernel/CWLExecuteConfigurator.py | 8 ++++---- cwlkernel/CWLKernel.py | 2 +- cwlkernel/CoreExecutor.py | 8 ++++---- cwlkernel/cwlrepository/CWLComponent.py | 7 +------ cwlkernel/cwlrepository/cwlrepository.py | 6 +++--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/cwlkernel/CWLBuilder.py b/cwlkernel/CWLBuilder.py index 348c047..2232d56 100644 --- a/cwlkernel/CWLBuilder.py +++ b/cwlkernel/CWLBuilder.py @@ -32,7 +32,7 @@ def get_current_code(self) -> str: return self._code def build(self) -> WorkflowComponent: - code = yaml.load(StringIO(self._code), yaml.Loader) + code = yaml.safe_load(StringIO(self._code)) if 'id' not in code: raise ValueError("the workflow must contain an id") if code['class'] == 'CommandLineTool': diff --git a/cwlkernel/CWLExecuteConfigurator.py b/cwlkernel/CWLExecuteConfigurator.py index 82fb313..3a137bb 100644 --- a/cwlkernel/CWLExecuteConfigurator.py +++ b/cwlkernel/CWLExecuteConfigurator.py @@ -16,11 +16,11 @@ class CWLExecuteConfigurator: def __init__(self): """Kernel configurations.""" - for property, (default_value, validator) in self.properties.items(): - value = os.environ.get(property, default_value) + for property_name, (default_value, validator) in self.properties.items(): + value = os.environ.get(property_name, default_value) if not validator(value): - raise RuntimeError("Value {0} is not allowed for property {1}".format(value, property)) + raise RuntimeError("Value {0} is not allowed for property {1}".format(value, property_name)) self.__setattr__( - property, + property_name, value ) diff --git a/cwlkernel/CWLKernel.py b/cwlkernel/CWLKernel.py index 6e69e9c..a5452fb 100644 --- a/cwlkernel/CWLKernel.py +++ b/cwlkernel/CWLKernel.py @@ -167,7 +167,7 @@ def _execute_workflow(self, code_path: Path) -> Optional[Exception]: output_directory_for_that_run = str(run_id) for output in results: if isinstance(results[output], list): - for i, output_i in enumerate(results[output]): + for i, _ in enumerate(results[output]): results[output][i]['id'] = f'{output}_{i + 1}' results[output][i]['result_counter'] = self._results_manager.files_counter self._results_manager.append_files( diff --git a/cwlkernel/CoreExecutor.py b/cwlkernel/CoreExecutor.py index 7f285de..170dd8d 100644 --- a/cwlkernel/CoreExecutor.py +++ b/cwlkernel/CoreExecutor.py @@ -1,8 +1,8 @@ import os -import subprocess import sys import traceback from pathlib import Path +from subprocess import DEVNULL from typing import ( Dict, List, @@ -46,9 +46,9 @@ def execute(self) -> Tuple[UUID, Dict, Optional[Exception]]: runtime_context = RuntimeContext() runtime_context.outdir = self.file_manager.ROOT_DIRECTORY runtime_context.basedir = self.file_manager.ROOT_DIRECTORY - runtime_context.default_stdin = subprocess.DEVNULL - runtime_context.default_stdout = subprocess.DEVNULL - runtime_context.default_stderr = subprocess.DEVNULL + runtime_context.default_stdin = DEVNULL + runtime_context.default_stdout = DEVNULL + runtime_context.default_stderr = DEVNULL os.chdir(self.file_manager.ROOT_DIRECTORY) factory = Factory(runtime_context=runtime_context) executable = factory.make(self._workflow_path) diff --git a/cwlkernel/cwlrepository/CWLComponent.py b/cwlkernel/cwlrepository/CWLComponent.py index d7db710..f4ea65d 100644 --- a/cwlkernel/cwlrepository/CWLComponent.py +++ b/cwlkernel/cwlrepository/CWLComponent.py @@ -118,11 +118,6 @@ def steps(self): steps[step]['run'] = f"{steps[step]['run']._id}.cwl" return deepcopy(steps) - """ - A composite object can add or remove other components (both simple or - complex) to or from its child list. - """ - def add(self, component: WorkflowComponent, step_name: str) -> None: self._steps[step_name] = { 'run': component, @@ -188,7 +183,7 @@ def compose_requirements(self) -> Dict: class WorkflowComponentFactory: def get_workflow_component(self, yaml_string: str) -> WorkflowComponent: - component = yaml.load(StringIO(yaml_string), yaml.SafeLoader) + component = yaml.safe_load(StringIO(yaml_string)) if 'id' not in component: component['id'] = str(uuid.uuid4()) if component['class'] == 'CommandLineTool': diff --git a/cwlkernel/cwlrepository/cwlrepository.py b/cwlkernel/cwlrepository/cwlrepository.py index e91b2d1..7d66a5a 100644 --- a/cwlkernel/cwlrepository/cwlrepository.py +++ b/cwlkernel/cwlrepository/cwlrepository.py @@ -28,9 +28,9 @@ def validate(self, tool: WorkflowComponent): raise TypeError(f'WorkflowComponent expected but type of {type(tool)} given') if not isinstance(tool.id, str): raise MissingIdError('Missing WorkflowComponent\'s id') - for input in tool.inputs: - if 'id' not in input: - raise MissingIdError(f'Missing id for input: {input}') + for tool_input in tool.inputs: + if 'id' not in tool_input: + raise MissingIdError(f'Missing id for input: {tool_input}') for output in tool.outputs: if 'id' not in output: raise MissingIdError(f'Missing id for outputs: {output}')