Skip to content

Commit faff174

Browse files
committed
Make the requested output directory, if it doesn't exist yet
1 parent cbd64d9 commit faff174

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

cwlupgrader/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import argparse
55
import copy
66
import logging
7+
import os
8+
import os.path
79
import stat
810
import sys
911
from collections.abc import MutableSequence, Sequence
@@ -62,6 +64,8 @@ def main(args: Optional[List[str]] = None) -> int:
6264
def run(args: argparse.Namespace) -> int:
6365
"""Main function."""
6466
imports: Set[str] = set()
67+
if args.dir and not os.path.exists(args.dir):
68+
os.makedirs(args.dir)
6569
for path in args.inputs:
6670
_logger.info("Processing %s", path)
6771
document = load_cwl_document(path)

tests/test_output_dir.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Tests related to the --dir command line option."""
2+
import filecmp
3+
from pathlib import Path
4+
5+
from cwlupgrader.main import main
6+
7+
from .util import get_data
8+
9+
10+
def test_draft3_workflow(tmp_path: Path) -> None:
11+
"""Confirm that --dir works when the directory doesn't exist yet."""
12+
out_dir = tmp_path / "new"
13+
main([f"--dir={out_dir}", "--v1-only", get_data("testdata/draft-3/wf.cwl")])
14+
result = filecmp.cmp(
15+
get_data("testdata/v1.0/wf.cwl"),
16+
out_dir / "wf.cwl",
17+
shallow=False,
18+
)
19+
assert result

tests/util.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import os
22

3-
from pkg_resources import (
4-
Requirement,
5-
ResolutionError,
6-
resource_filename,
7-
)
3+
from pkg_resources import Requirement, ResolutionError, resource_filename
84

95

106
def get_data(filename: str) -> str:

0 commit comments

Comments
 (0)