Skip to content

Commit 260b425

Browse files
committed
Add more docstrings
1 parent d26b6f7 commit 260b425

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

cwl_utils/expression.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def _convert_dumper(string: str) -> str:
2121

2222

2323
def scanner(scan: str) -> Optional[tuple[int, int]]:
24+
"""Find JS relevant punctuation in a string."""
2425
DEFAULT = 0
2526
DOLLAR = 1
2627
PAREN = 2
@@ -253,9 +254,7 @@ def dump(string: str) -> str:
253254

254255

255256
def jshead(engine_config: list[str], rootvars: CWLObjectType) -> str:
256-
# make sure all the byte strings are converted
257-
# to str in `rootvars` dict.
258-
257+
"""Make sure all the byte strings are converted to str in `rootvars` dict."""
259258
return "\n".join(
260259
engine_config
261260
+ [f"var {k} = {json_dumps(v, indent=4)};" for k, v in rootvars.items()]

cwl_utils/pack.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def pack_process(
7474

7575

7676
def listify_everything(cwl: dict[str, Any]) -> dict[str, Any]:
77+
"""
78+
Convert many CWL construct from their map to the list version.
79+
80+
See https://www.commonwl.org/v1.1/Workflow.html#map
81+
"""
7782
for port in ["inputs", "outputs"]:
7883
cwl[port] = utils.normalize_to_list(
7984
cwl.get(port, []), key_field="id", value_field="type"
@@ -99,14 +104,8 @@ def listify_everything(cwl: dict[str, Any]) -> dict[str, Any]:
99104
return cwl
100105

101106

102-
def dictify_requirements(cwl: dict[str, Any]) -> dict[str, Any]:
103-
cwl["requirements"] = utils.normalize_to_map(
104-
cwl.get("requirements", {}), key_field="class"
105-
)
106-
return cwl
107-
108-
109107
def normalize_sources(cwl: dict[str, Any]) -> dict[str, Any]:
108+
"""Normalize the steps and output of a CWL Workflow."""
110109
if cwl.get("class") != "Workflow":
111110
return cwl
112111

@@ -147,6 +146,7 @@ def load_schemadefs(
147146
base_url: urllib.parse.ParseResult,
148147
parent_user_defined_types: Optional[dict[str, Any]] = None,
149148
) -> tuple[dict[str, Any], dict[str, Any]]:
149+
"""Internalize any SchemaDefRequirement, and remove it."""
150150
user_defined_types = schemadef.build_user_defined_type_dict(cwl, base_url)
151151
if parent_user_defined_types is not None:
152152
user_defined_types.update(parent_user_defined_types)
@@ -198,6 +198,7 @@ def resolve_steps(
198198
cwl_version: str,
199199
parent_user_defined_types: Optional[dict[str, Any]] = None,
200200
) -> dict[str, Any]:
201+
"""Load and pack all "run" sections of the workflow steps."""
201202
if isinstance(cwl, str):
202203
raise RuntimeError(f"{base_url.geturl()}: Expecting a process, found a string")
203204

@@ -243,6 +244,7 @@ def resolve_steps(
243244

244245

245246
def add_missing_requirements(cwl: dict[str, Any]) -> dict[str, Any]:
247+
"""Due to packing, we may need to add a "SubworkflowFeatureRequirement"."""
246248
requirements = cwl.get("requirements", [])
247249
present = {req["class"] for req in requirements}
248250

@@ -263,6 +265,7 @@ def _add_req(_req_name: str) -> None:
263265

264266

265267
def pack(cwl_path: str) -> dict[str, Any]:
268+
"""Pack a CWL document at the given path."""
266269
sys.stderr.write(f"Packing {cwl_path}\n")
267270
file_path_url = urllib.parse.urlparse(cwl_path)
268271

cwl_utils/sandboxjs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,13 @@ def check_js_threshold_version(*args: Any, **kwargs: Any) -> bool:
609609

610610

611611
def exec_js_process(*args: Any, **kwargs: Any) -> tuple[int, str, str]:
612+
"""
613+
Run a javascript text.
614+
615+
:param timeout: Max number of seconds to wait.
616+
:returns: A tuple of the return code, stdout, and stderr of the javascript
617+
engine invocation.
618+
"""
612619
_exec_js_process = getattr(get_js_engine(), "exec_js_process", None)
613620
if callable(_exec_js_process):
614621
return cast(tuple[int, str, str], _exec_js_process(*args, **kwargs))

0 commit comments

Comments
 (0)