Skip to content

Commit 0112ec2

Browse files
authored
Merge pull request #1317 from common-workflow-language/cleanups
add format test to CI & fix pydocstyle check
2 parents 71113cb + 9d2321c commit 0112ec2

23 files changed

+97
-62
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pydocstyle_report.txt: $(PYSOURCES)
8989
pydocstyle setup.py $^ > $@ 2>&1 || true
9090

9191
diff_pydocstyle_report: pydocstyle_report.txt
92-
diff-quality --compare-branch=main --violations=pycodestyle --fail-under=100 $^
92+
diff-quality --compare-branch=main --violations=pydocstyle --fail-under=100 $^
9393

9494
## format : check/fix all code indentation and formatting (runs black)
9595
format:

cwltool/builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def formatSubclassOf(
8989

9090
uriRefFmt = URIRef(fmt)
9191

92-
for s, p, o in ontology.triples((uriRefFmt, RDFS.subClassOf, None)):
92+
for _s, _p, o in ontology.triples((uriRefFmt, RDFS.subClassOf, None)):
9393
# Find parent classes of `fmt` and search upward
9494
if formatSubclassOf(o, cls, ontology, visited):
9595
return True
9696

97-
for s, p, o in ontology.triples((uriRefFmt, OWL.equivalentClass, None)):
97+
for _s, _p, o in ontology.triples((uriRefFmt, OWL.equivalentClass, None)):
9898
# Find equivalent classes of `fmt` and search horizontally
9999
if formatSubclassOf(o, cls, ontology, visited):
100100
return True
101101

102-
for s, p, o in ontology.triples((None, OWL.equivalentClass, uriRefFmt)):
102+
for s, _p, _o in ontology.triples((None, OWL.equivalentClass, uriRefFmt)):
103103
# Find equivalent classes of `fmt` and search horizontally
104104
if formatSubclassOf(s, cls, ontology, visited):
105105
return True

cwltool/command_line_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def check_valid_locations(fs_access: StdFsAccess, ob: CWLObjectType) -> None:
345345

346346
class ParameterOutputWorkflowException(WorkflowException):
347347
def __init__(self, msg: str, port: CWLObjectType, **kwargs: Any) -> None:
348+
"""Exception for when there was an error collecting output for a parameter."""
348349
super(ParameterOutputWorkflowException, self).__init__(
349350
"Error collecting output for parameter '%s':\n%s"
350351
% (shortname(cast(str, port["id"])), msg),
@@ -1145,7 +1146,7 @@ def collect_output(
11451146
)
11461147
]
11471148
)
1148-
except (OSError, IOError) as e:
1149+
except (OSError) as e:
11491150
_logger.warning(str(e))
11501151
except Exception:
11511152
_logger.error(

cwltool/cwlrdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def dot_without_parameters(g: Graph, stdout: Union[TextIO, StreamWriter]) -> Non
138138
)
139139

140140
currentwf = None # type: Optional[str]
141-
for wf, step, run, runtype in qres:
141+
for wf, step, _run, runtype in qres:
142142
if step not in dotname:
143143
dotname[step] = lastpart(step)
144144

cwltool/docker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def __init__(
100100
hints: List[CWLObjectType],
101101
name: str,
102102
) -> None:
103+
"""Initialize a command line builder using the Docker software container engine."""
103104
super(DockerCommandLineJob, self).__init__(
104105
builder, joborder, make_path_mapper, requirements, hints, name
105106
)

cwltool/executors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
""" Single and multi-threaded executors."""
2+
"""Single and multi-threaded executors."""
33
import datetime
44
import logging
55
import os
@@ -443,7 +443,7 @@ def run_jobs(
443443

444444

445445
class NoopJobExecutor(JobExecutor):
446-
""" Do nothing executor, for testing purposes only. """
446+
"""Do nothing executor, for testing purposes only."""
447447

448448
def run_jobs(
449449
self,

cwltool/job.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ def _execute(
292292
# execution.
293293
if self.mpi_procs:
294294
menv = runtimeContext.mpi_config
295-
mpi_runtime = [menv.runner, menv.nproc_flag, str(self.mpi_procs)] + menv.extra_flags
295+
mpi_runtime = [
296+
menv.runner,
297+
menv.nproc_flag,
298+
str(self.mpi_procs),
299+
] + menv.extra_flags
296300
runtime = mpi_runtime + runtime
297301
menv.pass_through_env_vars(env)
298302
menv.set_env_vars(env)
@@ -863,7 +867,7 @@ def docker_monitor(
863867
try:
864868
with open(cidfile) as cidhandle:
865869
cid = cidhandle.readline().strip()
866-
except (OSError, IOError):
870+
except (OSError):
867871
cid = None
868872
max_mem = psutil.virtual_memory().total
869873
tmp_dir, tmp_prefix = os.path.split(tmpdir_prefix)
@@ -927,11 +931,15 @@ def _job_popen(
927931
if stdin_path is not None:
928932
stdin = open(stdin_path, "rb")
929933

930-
stdout = default_stdout if default_stdout is not None else sys.stderr # type: Union[IO[bytes], TextIO]
934+
stdout = (
935+
default_stdout if default_stdout is not None else sys.stderr
936+
) # type: Union[IO[bytes], TextIO]
931937
if stdout_path is not None:
932938
stdout = open(stdout_path, "wb")
933939

934-
stderr = default_stderr if default_stderr is not None else sys.stderr # type: Union[IO[bytes], TextIO]
940+
stderr = (
941+
default_stderr if default_stderr is not None else sys.stderr
942+
) # type: Union[IO[bytes], TextIO]
935943
if stderr_path is not None:
936944
stderr = open(stderr_path, "wb")
937945

@@ -976,13 +984,13 @@ def terminate(): # type: () -> None
976984
if tm is not None:
977985
tm.cancel()
978986

979-
if isinstance(stdin, IOBase) and hasattr(stdin, 'close'):
987+
if isinstance(stdin, IOBase) and hasattr(stdin, "close"):
980988
stdin.close()
981989

982-
if stdout is not sys.stderr and hasattr(stdout, 'close'):
990+
if stdout is not sys.stderr and hasattr(stdout, "close"):
983991
stdout.close()
984992

985-
if stderr is not sys.stderr and hasattr(stderr, 'close'):
993+
if stderr is not sys.stderr and hasattr(stderr, "close"):
986994
stderr.close()
987995

988996
return rcode

cwltool/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
from .workflow import Workflow
102102
from .mpi import MpiConfig
103103

104+
104105
def _terminate_processes() -> None:
105106
"""Kill all spawned processes.
106107
@@ -653,6 +654,7 @@ class ProvLogFormatter(logging.Formatter):
653654
"""Enforce ISO8601 with both T and Z."""
654655

655656
def __init__(self) -> None:
657+
"""Use the default formatter with our custom formatstring."""
656658
super(ProvLogFormatter, self).__init__("[%(asctime)sZ] %(message)s")
657659

658660
def formatTime(
@@ -874,7 +876,7 @@ def main(
874876

875877
if not args.workflow:
876878
if os.path.isfile("CWLFile"):
877-
setattr(args, "workflow", "CWLFile")
879+
args.workflow = "CWLFile"
878880
else:
879881
_logger.error("CWL document required, no input file was provided")
880882
arg_parser().print_help()

cwltool/mpi.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import os
22
import re
33
import inspect
4-
from typing import List, Type, TypeVar, MutableMapping, Mapping, Union
4+
from typing import List, Type, TypeVar, Optional, MutableMapping, Mapping, Union
55
from ruamel import yaml
66

77

88
MpiConfigT = TypeVar("MpiConfigT", bound="MpiConfig")
99

1010
MPIRequirementName = "http://commonwl.org/cwltool#MPIRequirement"
1111

12+
1213
class MpiConfig:
1314
def __init__(
1415
self,
1516
runner: str = "mpirun",
1617
nproc_flag: str = "-n",
1718
default_nproc: Union[int, str] = 1,
18-
extra_flags: List[str] = [],
19-
env_pass: List[str] = [],
20-
env_pass_regex: List[str] = [],
21-
env_set: Mapping[str, str] = {},
19+
extra_flags: Optional[List[str]] = None,
20+
env_pass: Optional[List[str]] = None,
21+
env_pass_regex: Optional[List[str]] = None,
22+
env_set: Optional[Mapping[str, str]] = None,
2223
) -> None:
23-
"""Initialize from the argument mapping with the following defaults:
24+
"""
25+
Initialize from the argument mapping.
2426
27+
Defaults are:
2528
runner: "mpirun"
2629
nproc_flag: "-n"
2730
default_nproc: 1
@@ -30,14 +33,15 @@ def __init__(
3033
env_pass_regex: []
3134
env_set: {}
3235
33-
Any unknown keys will result in an exception."""
36+
Any unknown keys will result in an exception.
37+
"""
3438
self.runner = runner
3539
self.nproc_flag = nproc_flag
3640
self.default_nproc = int(default_nproc)
37-
self.extra_flags = extra_flags
38-
self.env_pass = env_pass
39-
self.env_pass_regex = env_pass_regex
40-
self.env_set = env_set
41+
self.extra_flags = extra_flags or []
42+
self.env_pass = env_pass or []
43+
self.env_pass_regex = env_pass_regex or []
44+
self.env_set = env_set or {}
4145

4246
@classmethod
4347
def load(cls: Type[MpiConfigT], config_file_name: str) -> MpiConfigT:
@@ -56,9 +60,7 @@ def load(cls: Type[MpiConfigT], config_file_name: str) -> MpiConfigT:
5660
raise ValueError("Unknown key(s) in MPI configuration: {}".format(unknown))
5761

5862
def pass_through_env_vars(self, env: MutableMapping[str, str]) -> None:
59-
"""Here we take the configured list of environment variables and
60-
simply pass them through to the executed process.
61-
"""
63+
"""Take the configured list of environment variables and pass them to the executed process."""
6264
for var in self.env_pass:
6365
if var in os.environ:
6466
env[var] = os.environ[var]
@@ -70,6 +72,5 @@ def pass_through_env_vars(self, env: MutableMapping[str, str]) -> None:
7072
env[k] = os.environ[k]
7173

7274
def set_env_vars(self, env: MutableMapping[str, str]) -> None:
73-
"""Here we set some variables to the value configured.
74-
"""
75+
"""Set some variables to the value configured."""
7576
env.update(self.env_set)

cwltool/pathmapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,5 @@ def __contains__(self, key: str) -> bool:
229229
return key in self._pathmap
230230

231231
def __iter__(self) -> Iterator[MapperEnt]:
232+
"""Get iterator for the maps."""
232233
return self._pathmap.values().__iter__()

0 commit comments

Comments
 (0)