1
+ """Command line argument parsing for cwltool."""
1
2
from __future__ import absolute_import , print_function
2
3
3
4
import argparse
4
5
import os
5
- from typing import (Any , AnyStr , Dict , List , # pylint: disable=unused-import
6
- Optional , Sequence , Text , Union , cast )
6
+ from typing import (Any , AnyStr , Dict , List , MutableMapping , MutableSequence ,
7
+ Optional , Sequence , Union , cast )
7
8
8
9
from schema_salad .ref_resolver import file_uri
10
+ from typing_extensions import Text # pylint: disable=unused-import
11
+ # move to a regular typing import when Python 3.3-3.6 is no longer supported
9
12
10
13
from .loghandler import _logger
11
14
from .process import Process , shortname # pylint: disable=unused-import
@@ -25,44 +28,43 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
25
28
help = "[experimental] Run jobs in parallel. " )
26
29
envgroup = parser .add_mutually_exclusive_group ()
27
30
envgroup .add_argument ("--preserve-environment" , type = Text , action = "append" ,
28
- help = "Preserve specific environment variable when "
29
- "running CommandLineTools. May be provided multiple "
30
- "times." , metavar = "ENVVAR" , default = ["PATH" ],
31
- dest = "preserve_environment" )
31
+ help = "Preserve specific environment variable when "
32
+ "running CommandLineTools. May be provided multiple "
33
+ "times." , metavar = "ENVVAR" , default = ["PATH" ],
34
+ dest = "preserve_environment" )
32
35
envgroup .add_argument ("--preserve-entire-environment" , action = "store_true" ,
33
- help = "Preserve all environment variable when running "
34
- "CommandLineTools." , default = False ,
35
- dest = "preserve_entire_environment" )
36
+ help = "Preserve all environment variable when running "
37
+ "CommandLineTools." , default = False ,
38
+ dest = "preserve_entire_environment" )
36
39
37
40
exgroup = parser .add_mutually_exclusive_group ()
38
41
exgroup .add_argument ("--rm-container" , action = "store_true" , default = True ,
39
42
help = "Delete Docker container used by jobs after they exit (default)" ,
40
43
dest = "rm_container" )
41
44
42
- exgroup .add_argument ("--leave-container" , action = "store_false" ,
43
- default = True , help = "Do not delete Docker container used by jobs after they exit" ,
44
- dest = "rm_container" )
45
+ exgroup .add_argument (
46
+ "--leave-container" , action = "store_false" , default = True ,
47
+ help = "Do not delete Docker container used by jobs after they exit" ,
48
+ dest = "rm_container" )
45
49
46
- cidgroup = parser .add_argument_group ("Options for recording the Docker "
47
- "container identifier into a file" )
50
+ cidgroup = parser .add_argument_group (
51
+ "Options for recording the Docker container identifier into a file" )
48
52
cidgroup .add_argument ("--record-container-id" , action = "store_true" ,
49
53
default = False ,
50
54
help = "If enabled, store the Docker container ID into a file. "
51
55
"See --cidfile-dir to specify the directory." ,
52
56
dest = "record_container_id" )
53
57
54
- cidgroup .add_argument ("--cidfile-dir" , type = Text ,
55
- help = "Directory for storing the Docker container ID file. "
56
- "The default is the current directory" ,
57
- default = "" ,
58
- dest = "cidfile_dir" )
58
+ cidgroup .add_argument (
59
+ "--cidfile-dir" , type = Text , help = "Directory for storing the Docker "
60
+ "container ID file. The default is the current directory" ,
61
+ default = "" , dest = "cidfile_dir" )
59
62
60
- cidgroup .add_argument ("--cidfile-prefix" , type = Text ,
61
- help = "Specify a prefix to the container ID filename. "
62
- "Final file name will be followed by a timestamp. "
63
- "The default is no prefix." ,
64
- default = "" ,
65
- dest = "cidfile_prefix" )
63
+ cidgroup .add_argument (
64
+ "--cidfile-prefix" , type = Text ,
65
+ help = "Specify a prefix to the container ID filename. "
66
+ "Final file name will be followed by a timestamp. The default is no prefix." ,
67
+ default = "" , dest = "cidfile_prefix" )
66
68
67
69
parser .add_argument ("--tmpdir-prefix" , type = Text ,
68
70
help = "Path prefix for temporary directories" ,
@@ -73,8 +75,9 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
73
75
help = "Path prefix for intermediate output directories" ,
74
76
default = DEFAULT_TMP_PREFIX )
75
77
76
- exgroup .add_argument ("--cachedir" , type = Text , default = "" ,
77
- help = "Directory to cache intermediate workflow outputs to avoid recomputing steps." )
78
+ exgroup .add_argument (
79
+ "--cachedir" , type = Text , default = "" ,
80
+ help = "Directory to cache intermediate workflow outputs to avoid recomputing steps." )
78
81
79
82
exgroup = parser .add_mutually_exclusive_group ()
80
83
exgroup .add_argument ("--rm-tmpdir" , action = "store_true" , default = True ,
@@ -86,9 +89,10 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
86
89
dest = "rm_tmpdir" )
87
90
88
91
exgroup = parser .add_mutually_exclusive_group ()
89
- exgroup .add_argument ("--move-outputs" , action = "store_const" , const = "move" , default = "move" ,
90
- help = "Move output files to the workflow output directory and delete intermediate output directories (default)." ,
91
- dest = "move_outputs" )
92
+ exgroup .add_argument (
93
+ "--move-outputs" , action = "store_const" , const = "move" , default = "move" ,
94
+ help = "Move output files to the workflow output directory and delete "
95
+ "intermediate output directories (default)." , dest = "move_outputs" )
92
96
93
97
exgroup .add_argument ("--leave-outputs" , action = "store_const" , const = "leave" , default = "move" ,
94
98
help = "Leave output files in intermediate output directories." ,
@@ -378,7 +382,7 @@ def add_argument(toolparser, name, inptype, records, description="",
378
382
flag = "--"
379
383
380
384
required = True
381
- if isinstance (inptype , list ):
385
+ if isinstance (inptype , MutableSequence ):
382
386
if inptype [0 ] == "null" :
383
387
required = False
384
388
if len (inptype ) == 2 :
@@ -395,16 +399,16 @@ def add_argument(toolparser, name, inptype, records, description="",
395
399
action = cast (argparse .Action , FileAction )
396
400
elif inptype == "Directory" :
397
401
action = cast (argparse .Action , DirectoryAction )
398
- elif isinstance (inptype , dict ) and inptype ["type" ] == "array" :
402
+ elif isinstance (inptype , MutableMapping ) and inptype ["type" ] == "array" :
399
403
if inptype ["items" ] == "File" :
400
404
action = cast (argparse .Action , FileAppendAction )
401
405
elif inptype ["items" ] == "Directory" :
402
406
action = cast (argparse .Action , DirectoryAppendAction )
403
407
else :
404
408
action = "append"
405
- elif isinstance (inptype , dict ) and inptype ["type" ] == "enum" :
409
+ elif isinstance (inptype , MutableMapping ) and inptype ["type" ] == "enum" :
406
410
atype = Text
407
- elif isinstance (inptype , dict ) and inptype ["type" ] == "record" :
411
+ elif isinstance (inptype , MutableMapping ) and inptype ["type" ] == "record" :
408
412
records .append (name )
409
413
for field in inptype ['fields' ]:
410
414
fieldname = name + "." + shortname (field ['name' ])
0 commit comments