Skip to content

Commit 7e26b92

Browse files
committed
support always writing a new file, even if no changes
1 parent 4dd6b5e commit 7e26b92

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DEVPKGS=diff_cover black pylint pep257 pydocstyle flake8 tox tox-pyenv \
3232
-rtest-requirements.txt -rmypy-requirements.txt
3333
DEBDEVPKGS=pylint python3-coverage sloccount \
3434
python3-flake8 shellcheck
35-
VERSION=1.2.3 # please also update setup.py
35+
VERSION=1.2.4 # please also update setup.py
3636

3737
## all : default task (install cwl-upgrader in dev mode)
3838
all: dev

Diff for: cwlupgrader/main.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
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+
1517
import ruamel.yaml
1618
from ruamel.yaml.comments import CommentedMap # for consistent sort order
17-
from schema_salad.sourceline import SourceLine, add_lc_filename, cmap
1819

1920
_logger = logging.getLogger("cwl-upgrader") # pylint: disable=invalid-name
2021
defaultStreamHandler = logging.StreamHandler() # pylint: disable=invalid-name
@@ -46,6 +47,11 @@ def parse_args(args: List[str]) -> argparse.Namespace:
4647
parser.add_argument(
4748
"--dir", help="Directory in which to save converted files", default=Path.cwd()
4849
)
50+
parser.add_argument(
51+
"--always-write",
52+
help="Always write a file, even if no changes were made.",
53+
action="store_true",
54+
)
4955
parser.add_argument(
5056
"inputs",
5157
nargs="+",
@@ -93,7 +99,7 @@ def run(args: argparse.Namespace) -> int:
9399
target_version=target_version,
94100
imports=imports,
95101
)
96-
if upgraded_document is not None:
102+
if upgraded_document is not document or not args.always_write:
97103
write_cwl_document(upgraded_document, Path(path).name, args.dir)
98104
return 0
99105

@@ -154,9 +160,9 @@ def upgrade_document(
154160
elif version == "v1.2":
155161
if target_version == "v1.2":
156162
_logger.info("Not upgrading v1.2 document as requested.")
157-
return
163+
return document
158164
elif target_version == "latest":
159-
return
165+
return document
160166
else:
161167
_logger.error(f"Unknown cwlVersion in source document: {version}")
162168
return

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name="cwl-upgrader",
16-
version="1.2.3",
16+
version="1.2.4",
1717
description="Common Workflow Language standalone document upgrader",
1818
long_description=open(README).read(),
1919
author="Common Workflow Language contributors",

Diff for: tests/test_complete.py

+16
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def test_v1_1_to_v1_2(tmp_path: Path) -> None:
7373
assert upgraded == expected
7474

7575

76+
def test_v1_2_to_v1_2(tmp_path: Path) -> None:
77+
"""CWL v1.2 to CWL v1.2 no change test."""
78+
doc = load_cwl_document(get_data("testdata/v1.2/networkaccess.cwl"))
79+
upgraded = upgrade_document(doc, str(tmp_path), "v1.2")
80+
expected = load_cwl_document(get_data("testdata/v1.2/networkaccess.cwl"))
81+
assert upgraded == expected
82+
83+
84+
def test_v1_2_to_latest(tmp_path: Path) -> None:
85+
"""CWL v1.2 to latest no change test."""
86+
doc = load_cwl_document(get_data("testdata/v1.2/networkaccess.cwl"))
87+
upgraded = upgrade_document(doc, str(tmp_path), "latest")
88+
expected = load_cwl_document(get_data("testdata/v1.2/networkaccess.cwl"))
89+
assert upgraded == expected
90+
91+
7692
def test_packed_graph(tmp_path: Path) -> None:
7793
"""Test packed document with $graph."""
7894
main(

0 commit comments

Comments
 (0)