2
2
import json
3
3
import attr
4
4
from urllib .request import urlretrieve
5
- import subprocess as sp
6
- import os
7
5
from pathlib import Path
8
6
from functools import reduce
9
7
10
8
from ..utils .messenger import AuditFlag
11
9
from ..engine import ShellCommandTask
12
- from ..engine .specs import (
13
- SpecInfo ,
14
- ShellSpec ,
15
- ShellOutSpec ,
16
- File ,
17
- Directory ,
18
- attr_fields ,
19
- )
20
- from .helpers import ensure_list , execute
21
- from .helpers_file import template_update , is_local_file
10
+ from ..engine .specs import SpecInfo , ShellSpec , ShellOutSpec , File , attr_fields
11
+ from .helpers_file import is_local_file
22
12
23
13
24
14
class BoshTask (ShellCommandTask ):
@@ -30,11 +20,11 @@ def __init__(
30
20
bosh_file = None ,
31
21
audit_flags : AuditFlag = AuditFlag .NONE ,
32
22
cache_dir = None ,
33
- input_spec : ty .Optional [SpecInfo ] = None ,
23
+ input_spec_names : ty .Optional [ty . List ] = None ,
34
24
messenger_args = None ,
35
25
messengers = None ,
36
26
name = None ,
37
- output_spec : ty .Optional [SpecInfo ] = None ,
27
+ output_spec_names : ty .Optional [ty . List ] = None ,
38
28
rerun = False ,
39
29
strip = False ,
40
30
** kwargs ,
@@ -52,16 +42,16 @@ def __init__(
52
42
Auditing configuration
53
43
cache_dir : :obj:`os.pathlike`
54
44
Cache directory
55
- input_spec : :obj:`pydra.engine.specs.SpecInfo`
56
- Specification of inputs .
45
+ input_spec_names : :obj: list
46
+ Input names for input_spec .
57
47
messenger_args :
58
48
TODO
59
49
messengers :
60
50
TODO
61
51
name : :obj:`str`
62
52
Name of this task.
63
- output_spec : :obj:`pydra.engine.specs.BaseSpec`
64
- Specification of inputs .
53
+ output_spec_names : :obj: list
54
+ Output names for output_spec .
65
55
strip : :obj:`bool`
66
56
TODO
67
57
@@ -86,18 +76,14 @@ def __init__(
86
76
if tries == tries_max :
87
77
raise
88
78
89
- if input_spec is None :
90
- input_spec = self ._prepare_input_spec ()
91
- self .input_spec = input_spec
92
- if output_spec is None :
93
- output_spec = self ._prepare_output_spec ()
94
- self .output_spec = output_spec
79
+ self .input_spec = self ._prepare_input_spec (names_subset = input_spec_names )
80
+ self .output_spec = self ._prepare_output_spec (names_subset = output_spec_names )
95
81
self .bindings = ["-v" , f"{ self .bosh_file .parent } :{ self .bosh_file .parent } :ro" ]
96
82
97
83
super (BoshTask , self ).__init__ (
98
84
name = name ,
99
- input_spec = input_spec ,
100
- output_spec = output_spec ,
85
+ input_spec = self . input_spec ,
86
+ output_spec = self . output_spec ,
101
87
executable = ["bosh" , "exec" , "launch" ],
102
88
args = ["-s" ],
103
89
audit_flags = audit_flags ,
@@ -129,13 +115,21 @@ def _download_spec(self, zenodo_id):
129
115
urlretrieve (zenodo_url , zenodo_file )
130
116
return zenodo_file
131
117
132
- def _prepare_input_spec (self ):
133
- """ creating input spec from the zenodo file"""
118
+ def _prepare_input_spec (self , names_subset = None ):
119
+ """ creating input spec from the zenodo file
120
+ if name_subset provided, only names from the subset will be used in the spec
121
+ """
134
122
binputs = self .bosh_spec ["inputs" ]
135
123
self ._input_spec_keys = {}
136
124
fields = []
137
125
for input in binputs :
138
126
name = input ["id" ]
127
+ if names_subset is None :
128
+ pass
129
+ elif name not in names_subset :
130
+ continue
131
+ else :
132
+ names_subset .remove (name )
139
133
if input ["type" ] == "File" :
140
134
tp = File
141
135
elif input ["type" ] == "String" :
@@ -157,16 +151,25 @@ def _prepare_input_spec(self):
157
151
}
158
152
fields .append ((name , tp , mdata ))
159
153
self ._input_spec_keys [input ["value-key" ]] = "{" + f"{ name } " + "}"
160
-
154
+ if names_subset :
155
+ raise RuntimeError (f"{ names_subset } are not in the zenodo input spec" )
161
156
spec = SpecInfo (name = "Inputs" , fields = fields , bases = (ShellSpec ,))
162
157
return spec
163
158
164
- def _prepare_output_spec (self ):
165
- """ creating output spec from the zenodo file"""
159
+ def _prepare_output_spec (self , names_subset = None ):
160
+ """ creating output spec from the zenodo file
161
+ if name_subset provided, only names from the subset will be used in the spec
162
+ """
166
163
boutputs = self .bosh_spec ["output-files" ]
167
164
fields = []
168
165
for output in boutputs :
169
166
name = output ["id" ]
167
+ if names_subset is None :
168
+ pass
169
+ elif name not in names_subset :
170
+ continue
171
+ else :
172
+ names_subset .remove (name )
170
173
path_template = reduce (
171
174
lambda s , r : s .replace (* r ),
172
175
self ._input_spec_keys .items (),
@@ -179,6 +182,8 @@ def _prepare_output_spec(self):
179
182
}
180
183
fields .append ((name , attr .ib (type = File , metadata = mdata )))
181
184
185
+ if names_subset :
186
+ raise RuntimeError (f"{ names_subset } are not in the zenodo output spec" )
182
187
spec = SpecInfo (name = "Outputs" , fields = fields , bases = (ShellOutSpec ,))
183
188
return spec
184
189
0 commit comments