Skip to content

Commit cf3b540

Browse files
committed
fixes
1 parent 4d3e296 commit cf3b540

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

cwlupgrader/main.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
from pathlib import Path
1313
from typing import Any, Callable, Dict, List, MutableMapping, Optional, Set, Union
1414

15-
from schema_salad.sourceline import SourceLine, add_lc_filename, cmap
16-
1715
import ruamel.yaml
1816
from ruamel.yaml.comments import CommentedMap # for consistent sort order
17+
from schema_salad.sourceline import SourceLine, add_lc_filename, cmap
1918

2019
_logger = logging.getLogger("cwl-upgrader") # pylint: disable=invalid-name
2120
defaultStreamHandler = logging.StreamHandler() # pylint: disable=invalid-name
@@ -203,7 +202,7 @@ def load_cwl_document(path: Union[str, Path]) -> Any:
203202

204203

205204
def write_cwl_document(document: Any, path: Path) -> None:
206-
"""
205+
r"""
207206
Serialize the document using the Ruamel YAML round trip dumper.
208207
209208
Will also prepend "#!/usr/bin/env cwl-runner\n" and
@@ -294,7 +293,7 @@ def v1_1_to_v1_2(document: CommentedMap, out_dir: Path, root_dir: Path) -> Comme
294293
def draft3_to_v1_0(
295294
document: CommentedMap, out_dir: Path, root_dir: Path
296295
) -> CommentedMap:
297-
"""Transformation loop."""
296+
"""Transform loop for draft-3 to v1.0."""
298297
_draft3_to_v1_0(document, out_dir, root_dir)
299298
if isinstance(document, MutableMapping):
300299
for key, value in document.items():
@@ -312,14 +311,14 @@ def draft3_to_v1_0(
312311
def draft3_to_v1_1(
313312
document: CommentedMap, out_dir: Path, root_dir: Path
314313
) -> CommentedMap:
315-
"""transformation loop."""
314+
"""Transform loop for draft-3 to v1.1."""
316315
return v1_0_to_v1_1(draft3_to_v1_0(document, out_dir, root_dir), out_dir, root_dir)
317316

318317

319318
def draft3_to_v1_2(
320319
document: CommentedMap, out_dir: Path, root_dir: Path
321320
) -> CommentedMap:
322-
"""transformation loop."""
321+
"""Transform loop for draft-3 to v1.2."""
323322
return v1_1_to_v1_2(
324323
v1_0_to_v1_1(draft3_to_v1_0(document, out_dir, root_dir), out_dir, root_dir),
325324
out_dir,
@@ -405,7 +404,7 @@ def _v1_0_to_v1_1(
405404
process = v1_0_to_v1_1(
406405
load_cwl_document(str(path)), out_dir, root_dir
407406
)
408-
write_cwl_document(process, path.name, out_dir)
407+
write_cwl_document(process, out_dir / path.name)
409408
elif isinstance(steps, MutableMapping):
410409
for step_name in steps:
411410
with SourceLine(steps, step_name, Exception):
@@ -491,7 +490,7 @@ def _v1_1_to_v1_2(
491490
with SourceLine(steps, index, Exception):
492491
if "run" in entry and isinstance(entry["run"], CommentedMap):
493492
process = entry["run"]
494-
_v1_1_to_v1_2(process, out_dir)
493+
_v1_1_to_v1_2(process, out_dir, root_dir)
495494
if "cwlVersion" in process:
496495
del process["cwlVersion"]
497496

@@ -504,7 +503,7 @@ def _v1_1_to_v1_2(
504503
process = v1_1_to_v1_2(
505504
load_cwl_document(str(path)), out_dir, root_dir
506505
)
507-
write_cwl_document(process, path.name, out_dir, root_dir)
506+
write_cwl_document(process, out_dir / path.name)
508507
elif isinstance(steps, MutableMapping):
509508
for step_name in steps:
510509
with SourceLine(steps, step_name, Exception):

tests/test_import.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
import filecmp
2+
import logging
3+
import re
24
from pathlib import Path
35

4-
from cwlupgrader.main import load_cwl_document, main, upgrade_document
56
import pytest
6-
import logging
7+
8+
from cwlupgrader.main import load_cwl_document, main, upgrade_document
9+
710
from .util import get_data
8-
import re
911

10-
def test_import_parent_directory(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
12+
13+
def test_import_parent_directory(
14+
tmp_path: Path, caplog: pytest.LogCaptureFixture
15+
) -> None:
1116
"""Confirm that $import to a superior directory still preserves the directory structure."""
1217
caplog.set_level(logging.WARN)
13-
out_dir = tmp_path/"out"
18+
out_dir = tmp_path / "out"
1419
out_dir.mkdir()
1520
doc = load_cwl_document(get_data("testdata/v1.0/subdir/params.cwl"))
1621
upgraded = upgrade_document(doc, out_dir, out_dir, "v1.1")
1722
expected = load_cwl_document(get_data("testdata/v1.1/subdir/params.cwl"))
1823
assert upgraded == expected
1924
assert len(caplog.records) == 1
20-
assert re.search(re.escape(f"Writing file, '{tmp_path}/params_inc.yml', outside of the output directory, '{out_dir}'."), caplog.records[0].getMessage())
25+
assert re.search(
26+
re.escape(
27+
f"Writing file, '{tmp_path}/params_inc.yml', outside of the output directory, '{out_dir}'."
28+
),
29+
caplog.records[0].getMessage(),
30+
)
31+
2132

22-
def test_import_parent_directory_safe(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
33+
def test_import_parent_directory_safe(
34+
tmp_path: Path, caplog: pytest.LogCaptureFixture
35+
) -> None:
2336
"""Confirm no warning when $import to a superior directory (but still in the current working directory) still preserves the directory structure."""
2437
caplog.set_level(logging.WARN)
25-
out_dir = tmp_path/"out"
38+
out_dir = tmp_path / "out"
2639
out_dir.mkdir()
2740
doc = load_cwl_document(get_data("testdata/v1.0/subdir/params.cwl"))
2841
upgraded = upgrade_document(doc, out_dir, tmp_path, "v1.1")

0 commit comments

Comments
 (0)