Skip to content

Commit 0bbb82c

Browse files
committed
fix flake8 check
1 parent c44da20 commit 0bbb82c

28 files changed

+116
-116
lines changed

.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
ignore = E203,W503
3+
max-line-length = 100
4+
select = B,C,E,F,W,T4
5+
exclude = cwltool/schemas
6+
extend-ignore = E501,B905
7+
# when Python 3.10 is the minimum version, re-enable check B905 for zip + strict
8+
extend-select = B9

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ codespell:
109109
codespell -w $(shell git ls-files | grep -v mypy-stubs)
110110

111111
## format : check/fix all code indentation and formatting (runs black)
112-
format: $(PYSOURCES)
113-
black $^
112+
format: $(PYSOURCES) FORCE
113+
black $(PYSOURCES)
114114

115115
format-check: $(PYSOURCES)
116116
black --diff --check $^

cwl_utils/cwl_v1_0_expression_refactor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def generate_etool_from_expr(
350350
elif self_type.type:
351351
new_type = clean_type_ids(self_type.type)
352352
else:
353-
raise WorkflowException(f"Don't know how to make type from '{self_type}'.")
353+
raise WorkflowException(f"Don't know how to make type from {self_type!r}.")
354354
inputs.append(
355355
cwl.InputParameter(
356356
id="self",
@@ -652,7 +652,8 @@ def process_workflow_reqs_and_hints(
652652
"""
653653
# TODO: consolidate the generated etools/cltools into a single "_expression_workflow_reqs" step
654654
# TODO: support resourceReq.* references to Workflow.inputs?
655-
# ^ By refactoring replace_expr_etool to allow multiple inputs, and connecting all workflow inputs to the generated step
655+
# ^ By refactoring replace_expr_etool to allow multiple inputs,
656+
# and connecting all workflow inputs to the generated step
656657
modified = False
657658
inputs = empty_inputs(workflow)
658659
generated_res_reqs: List[Tuple[str, Union[int, str]]] = []
@@ -837,7 +838,8 @@ def process_workflow_reqs_and_hints(
837838
raise_type=WorkflowException,
838839
).makeError(
839840
f"Entry {index},"
840-
+ "Invalid CWL, if 'entry' is a string, then entryName must be specified."
841+
+ "Invalid CWL, if 'entry' "
842+
"is a string, then entryName must be specified."
841843
)
842844
expr = (
843845
'${return {"class": "File", "basename": "'
@@ -979,7 +981,8 @@ def process_level_reqs(
979981
# - Replace the CWL Expression inplace with a CWL parameter reference
980982
# - Don't create a new Requirement, nor delete the existing Requirement
981983
# - the Process is passed to replace_expr_with_etool for later searching for JS expressionLibs
982-
# - in addition to adding the input to the step for the ETool/CTool result, add it to the Process.inputs as well
984+
# - in addition to adding the input to the step for the ETool/CTool result,
985+
# add it to the Process.inputs as well
983986
if not process.requirements:
984987
return False
985988
modified = False
@@ -1122,7 +1125,7 @@ def process_level_reqs(
11221125
entryname = (
11231126
entry.entryname
11241127
if entryname_expr
1125-
else f'"{entry.entryname}"'
1128+
else f'"{entry.entryname}"' # noqa: B907
11261129
)
11271130
new_expression = (
11281131
"${var result; var entryname = "
@@ -1914,15 +1917,15 @@ def workflow_step_to_InputParameters(
19141917
for p in param:
19151918
if not p.type:
19161919
raise WorkflowException(
1917-
f"Don't know how to get type id for '{p}'."
1920+
f"Don't know how to get type id for {p!r}."
19181921
)
19191922
p.id = inp_id
19201923
p.type = clean_type_ids(p.type)
19211924
params.append(p)
19221925
else:
19231926
if not param.type:
19241927
raise WorkflowException(
1925-
f"Don't know how to get type id for '{param}'."
1928+
f"Don't know how to get type id for {param!r}."
19261929
)
19271930
param.id = inp_id
19281931
param.type = clean_type_ids(param.type)

cwl_utils/cwl_v1_1_expression_refactor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def etool_to_cltool(
183183
contents += "\n" + "\n".join(expressionLib)
184184
contents += (
185185
"""
186-
var ret = function(){"""
186+
var ret = function(){"""
187187
+ escape_expression_field(etool.expression.strip()[2:-1])
188188
+ """}();
189189
process.stdout.write(JSON.stringify(ret));"""
@@ -389,7 +389,7 @@ def generate_etool_from_expr(
389389
expression += "\n var self=inputs.self;"
390390
expression += (
391391
"""
392-
return {"result": function(){"""
392+
return {"result": function(){"""
393393
+ expr[2:-2]
394394
+ """}()};
395395
}"""
@@ -652,7 +652,8 @@ def process_workflow_reqs_and_hints(
652652
"""
653653
# TODO: consolidate the generated etools/cltools into a single "_expression_workflow_reqs" step
654654
# TODO: support resourceReq.* references to Workflow.inputs?
655-
# ^ By refactoring replace_expr_etool to allow multiple inputs, and connecting all workflow inputs to the generated step
655+
# ^ By refactoring replace_expr_etool to allow multiple inputs,
656+
# and connecting all workflow inputs to the generated step
656657
modified = False
657658
inputs = empty_inputs(workflow)
658659
generated_res_reqs: List[Tuple[str, Union[int, str]]] = []
@@ -837,7 +838,8 @@ def process_workflow_reqs_and_hints(
837838
raise_type=WorkflowException,
838839
).makeError(
839840
f"Entry {index},"
840-
+ "Invalid CWL, if 'entry' is a string, then entryName must be specified."
841+
+ "Invalid CWL, if 'entry' "
842+
"is a string, then entryName must be specified."
841843
)
842844
expr = (
843845
'${return {"class": "File", "basename": "'
@@ -979,7 +981,8 @@ def process_level_reqs(
979981
# - Replace the CWL Expression inplace with a CWL parameter reference
980982
# - Don't create a new Requirement, nor delete the existing Requirement
981983
# - the Process is passed to replace_expr_with_etool for later searching for JS expressionLibs
982-
# - in addition to adding the input to the step for the ETool/CTool result, add it to the Process.inputs as well
984+
# - in addition to adding the input to the step for the ETool/CTool result,
985+
# add it to the Process.inputs as well
983986
if not process.requirements:
984987
return False
985988
modified = False
@@ -1122,7 +1125,7 @@ def process_level_reqs(
11221125
entryname = (
11231126
entry.entryname
11241127
if entryname_expr
1125-
else f'"{entry.entryname}"'
1128+
else f'"{entry.entryname}"' # noqa: B907
11261129
)
11271130
new_expression = (
11281131
"${var result; var entryname = "
@@ -1716,7 +1719,7 @@ def generate_etool_from_expr2(
17161719
expression += f"\n var self=inputs.{self_name};"
17171720
expression += (
17181721
"""
1719-
return {"result": function(){"""
1722+
return {"result": function(){"""
17201723
+ expr[2:-2]
17211724
+ """}()};
17221725
}"""

cwl_utils/cwl_v1_2_expression_refactor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def etool_to_cltool(
183183
contents += "\n" + "\n".join(expressionLib)
184184
contents += (
185185
"""
186-
var ret = function(){"""
186+
var ret = function(){"""
187187
+ escape_expression_field(etool.expression.strip()[2:-1])
188188
+ """}();
189189
process.stdout.write(JSON.stringify(ret));"""
@@ -389,7 +389,7 @@ def generate_etool_from_expr(
389389
expression += "\n var self=inputs.self;"
390390
expression += (
391391
"""
392-
return {"result": function(){"""
392+
return {"result": function(){"""
393393
+ expr[2:-2]
394394
+ """}()};
395395
}"""
@@ -747,7 +747,8 @@ def process_workflow_reqs_and_hints(
747747
"""
748748
# TODO: consolidate the generated etools/cltools into a single "_expression_workflow_reqs" step
749749
# TODO: support resourceReq.* references to Workflow.inputs?
750-
# ^ By refactoring replace_expr_etool to allow multiple inputs, and connecting all workflow inputs to the generated step
750+
# ^ By refactoring replace_expr_etool to allow multiple inputs,
751+
# and connecting all workflow inputs to the generated step
751752
modified = False
752753
inputs = empty_inputs(workflow)
753754
generated_res_reqs: List[Tuple[str, Union[int, str]]] = []
@@ -932,7 +933,8 @@ def process_workflow_reqs_and_hints(
932933
raise_type=WorkflowException,
933934
).makeError(
934935
f"Entry {index},"
935-
+ "Invalid CWL, if 'entry' is a string, then entryName must be specified."
936+
+ "Invalid CWL, if 'entry' "
937+
"is a string, then entryName must be specified."
936938
)
937939
expr = (
938940
'${return {"class": "File", "basename": "'
@@ -1074,7 +1076,8 @@ def process_level_reqs(
10741076
# - Replace the CWL Expression inplace with a CWL parameter reference
10751077
# - Don't create a new Requirement, nor delete the existing Requirement
10761078
# - the Process is passed to replace_expr_with_etool for later searching for JS expressionLibs
1077-
# - in addition to adding the input to the step for the ETool/CTool result, add it to the Process.inputs as well
1079+
# - in addition to adding the input to the step for the ETool/CTool result,
1080+
# add it to the Process.inputs as well
10781081
if not process.requirements:
10791082
return False
10801083
modified = False
@@ -1217,7 +1220,7 @@ def process_level_reqs(
12171220
entryname = (
12181221
entry.entryname
12191222
if entryname_expr
1220-
else f'"{entry.entryname}"'
1223+
else f'"{entry.entryname}"' # noqa: B907
12211224
)
12221225
new_expression = (
12231226
"${var result; var entryname = "
@@ -1811,7 +1814,7 @@ def generate_etool_from_expr2(
18111814
expression += f"\n var self=inputs.{self_name};"
18121815
expression += (
18131816
"""
1814-
return {"result": function(){"""
1817+
return {"result": function(){"""
18151818
+ expr[2:-2]
18161819
+ """}()};
18171820
}"""

cwl_utils/expression.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def dump(string: str) -> str:
206206
w = scanner(scan)
207207
while w:
208208
if convert_to_expression:
209-
parts.append(f'"{scan[0: w[0]]}" + ')
209+
parts.append(f'"{scan[0: w[0]]}" + ') # noqa: B907
210210
else:
211211
parts.append(scan[0 : w[0]])
212212

@@ -227,7 +227,8 @@ def dump(string: str) -> str:
227227
parts.append(
228228
"function(){var item ="
229229
+ scan[w[0] : w[1]][2:-1]
230-
+ '; if (typeof(item) === "string"){ return item; } else { return JSON.stringify(item); }}() + '
230+
+ '; if (typeof(item) === "string"){ return item; } '
231+
"else { return JSON.stringify(item); }}() + "
231232
)
232233
elif scan[w[0]] == "\\":
233234
if escaping_behavior == 1:
@@ -254,7 +255,7 @@ def dump(string: str) -> str:
254255
scan = scan[w[1] :]
255256
w = scanner(scan)
256257
if convert_to_expression:
257-
parts.append(f'"{scan}"')
258+
parts.append(f'"{scan}"') # noqa: B907
258259
parts.append(";}")
259260
else:
260261
parts.append(scan)

cwl_utils/expression_refactor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
from ruamel.yaml.main import YAML
2323
from ruamel.yaml.scalarstring import walk_tree
2424

25+
from cwl_utils import (
26+
cwl_v1_0_expression_refactor,
27+
cwl_v1_1_expression_refactor,
28+
cwl_v1_2_expression_refactor,
29+
)
2530
from cwl_utils.errors import WorkflowException
2631
from cwl_utils.loghandler import _logger as _cwlutilslogger
32+
from cwl_utils.parser import cwl_v1_0, cwl_v1_1, cwl_v1_2
2733

2834
if TYPE_CHECKING:
2935
from typing_extensions import Protocol
@@ -36,13 +42,6 @@
3642
_logger.setLevel(logging.INFO)
3743
_cwlutilslogger.setLevel(100)
3844

39-
from cwl_utils import (
40-
cwl_v1_0_expression_refactor,
41-
cwl_v1_1_expression_refactor,
42-
cwl_v1_2_expression_refactor,
43-
)
44-
from cwl_utils.parser import cwl_v1_0, cwl_v1_1, cwl_v1_2
45-
4645
save_type = Optional[
4746
Union[MutableMapping[str, Any], MutableSequence[Any], int, float, bool, str]
4847
]
@@ -81,7 +80,8 @@ def arg_parser() -> argparse.ArgumentParser:
8180
)
8281
parser.add_argument(
8382
"--skip-some2",
84-
help="Don't process CommandLineTool.outputEval or CommandLineTool.requirements.InitialWorkDirRequirement.",
83+
help="Don't process CommandLineTool.outputEval or "
84+
"CommandLineTool.requirements.InitialWorkDirRequirement.",
8585
action="store_true",
8686
)
8787
parser.add_argument("dir", help="Directory in which to save converted files")

cwl_utils/image_puller.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _run_command_pull(cmd_pull: List[str]) -> None:
3636
)
3737
except subprocess.CalledProcessError as err:
3838
if err.output:
39-
raise subprocess.SubprocessError(err.output)
39+
raise subprocess.SubprocessError(err.output) from err
4040
raise err
4141

4242

@@ -95,14 +95,12 @@ def get_image_name(self) -> str:
9595
suffix = ".sif"
9696
else:
9797
raise Exception(
98-
"Don't know how to handle this version of singularity: {}.".format(
99-
self.version
100-
)
98+
f"Don't know how to handle this version of singularity: {get_singularity_version()}."
10199
)
102100
return f"{image_name}{suffix}"
103101

104102
def save_docker_image(self) -> None:
105-
"""Pull down the Docker format software container image and save it in the Singularity image format."""
103+
"""Pull down the Docker container image in the Singularity image format."""
106104
_LOGGER.info(f"Pulling {self.req} with Singularity...")
107105
cmd_pull = [
108106
"singularity",

cwl_utils/normalizer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
from ruamel import yaml
1414
from schema_salad.sourceline import add_lc_filename
1515

16+
from cwl_utils import cwl_v1_2_expression_refactor
1617
from cwl_utils.loghandler import _logger as _cwlutilslogger
1718
from cwl_utils.pack import pack
19+
from cwl_utils.parser.cwl_v1_2 import load_document_by_yaml, save
1820

1921
_logger = logging.getLogger("cwl-normalizer") # pylint: disable=invalid-name
2022
defaultStreamHandler = logging.StreamHandler() # pylint: disable=invalid-name
2123
_logger.addHandler(defaultStreamHandler)
2224
_logger.setLevel(logging.INFO)
2325
_cwlutilslogger.setLevel(100)
2426

25-
from cwl_utils import cwl_v1_2_expression_refactor
26-
from cwl_utils.parser.cwl_v1_2 import load_document_by_yaml, save
27-
2827

2928
def arg_parser() -> argparse.ArgumentParser:
3029
"""Build the argument parser."""
@@ -44,7 +43,8 @@ def arg_parser() -> argparse.ArgumentParser:
4443
)
4544
parser.add_argument(
4645
"--skip-some2",
47-
help="Don't process CommandLineTool.outputEval or CommandLineTool.requirements.InitialWorkDirRequirement.",
46+
help="Don't process CommandLineTool.outputEval or "
47+
"CommandLineTool.requirements.InitialWorkDirRequirement.",
4848
action="store_true",
4949
)
5050
parser.add_argument(

cwl_utils/pack.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
From https://github.com/rabix/sbpack/blob/b8404a0859ffcbe1edae6d8f934e51847b003320/sbpack/lib.py
1414
"""
1515

16-
1716
import logging
18-
import os
1917
import sys
2018
import urllib.parse
2119
import urllib.request
@@ -216,7 +214,6 @@ def resolve_steps(
216214
if cwl.get("class") != "Workflow":
217215
return cwl
218216

219-
workflow_id = cwl.get("id", os.path.basename(base_url.path))
220217
for _, v in enumerate(cwl["steps"]):
221218
if isinstance(v, dict):
222219
sys.stderr.write(

cwl_utils/parser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
]
1717
"""Type union for a CWL v1.x LoadingOptions object."""
1818
Saveable = Union[cwl_v1_0.Saveable, cwl_v1_1.Saveable, cwl_v1_2.Saveable]
19-
"""Type union for a CWL v1.x Savable object."""
19+
"""Type union for a CWL v1.x Saveable object."""
2020
InputParameter = Union[
2121
cwl_v1_0.InputParameter, cwl_v1_1.InputParameter, cwl_v1_2.InputParameter
2222
]

0 commit comments

Comments
 (0)