22import json
33import attr
44from urllib .request import urlretrieve
5- import subprocess as sp
6- import os
75from pathlib import Path
86from functools import reduce
97
108from ..utils .messenger import AuditFlag
119from ..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
2212
2313
2414class BoshTask (ShellCommandTask ):
@@ -30,11 +20,11 @@ def __init__(
3020 bosh_file = None ,
3121 audit_flags : AuditFlag = AuditFlag .NONE ,
3222 cache_dir = None ,
33- input_spec : ty .Optional [SpecInfo ] = None ,
23+ input_spec_names : ty .Optional [ty . List ] = None ,
3424 messenger_args = None ,
3525 messengers = None ,
3626 name = None ,
37- output_spec : ty .Optional [SpecInfo ] = None ,
27+ output_spec_names : ty .Optional [ty . List ] = None ,
3828 rerun = False ,
3929 strip = False ,
4030 ** kwargs ,
@@ -52,16 +42,16 @@ def __init__(
5242 Auditing configuration
5343 cache_dir : :obj:`os.pathlike`
5444 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 .
5747 messenger_args :
5848 TODO
5949 messengers :
6050 TODO
6151 name : :obj:`str`
6252 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 .
6555 strip : :obj:`bool`
6656 TODO
6757
@@ -86,18 +76,14 @@ def __init__(
8676 if tries == tries_max :
8777 raise
8878
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 )
9581 self .bindings = ["-v" , f"{ self .bosh_file .parent } :{ self .bosh_file .parent } :ro" ]
9682
9783 super (BoshTask , self ).__init__ (
9884 name = name ,
99- input_spec = input_spec ,
100- output_spec = output_spec ,
85+ input_spec = self . input_spec ,
86+ output_spec = self . output_spec ,
10187 executable = ["bosh" , "exec" , "launch" ],
10288 args = ["-s" ],
10389 audit_flags = audit_flags ,
@@ -129,13 +115,21 @@ def _download_spec(self, zenodo_id):
129115 urlretrieve (zenodo_url , zenodo_file )
130116 return zenodo_file
131117
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+ """
134122 binputs = self .bosh_spec ["inputs" ]
135123 self ._input_spec_keys = {}
136124 fields = []
137125 for input in binputs :
138126 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 )
139133 if input ["type" ] == "File" :
140134 tp = File
141135 elif input ["type" ] == "String" :
@@ -157,16 +151,25 @@ def _prepare_input_spec(self):
157151 }
158152 fields .append ((name , tp , mdata ))
159153 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" )
161156 spec = SpecInfo (name = "Inputs" , fields = fields , bases = (ShellSpec ,))
162157 return spec
163158
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+ """
166163 boutputs = self .bosh_spec ["output-files" ]
167164 fields = []
168165 for output in boutputs :
169166 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 )
170173 path_template = reduce (
171174 lambda s , r : s .replace (* r ),
172175 self ._input_spec_keys .items (),
@@ -179,6 +182,8 @@ def _prepare_output_spec(self):
179182 }
180183 fields .append ((name , attr .ib (type = File , metadata = mdata )))
181184
185+ if names_subset :
186+ raise RuntimeError (f"{ names_subset } are not in the zenodo output spec" )
182187 spec = SpecInfo (name = "Outputs" , fields = fields , bases = (ShellOutSpec ,))
183188 return spec
184189
0 commit comments