1111
1212from ._render import _DICT_SEP , _render_command
1313from ._types import (
14+ _SCALAR_TYPES ,
1415 FlagSpec ,
1516 Glob ,
1617 Stderr ,
1718 Stdout ,
18- _ProcessResult ,
19- _SCALAR_TYPES ,
2019 _classify_input ,
2120 _is_dict_str_str ,
2221 _is_optional ,
22+ _ProcessResult ,
2323 _validate_outputs ,
2424 listMode ,
2525)
@@ -51,8 +51,8 @@ class _Shell:
5151 _env : Optional ["flyte.TaskEnvironment" ] = field (default = None , repr = False , compare = False )
5252 _resolved_image_uri : Optional [str ] = field (default = None , repr = False , compare = False )
5353
54- def _container_inputs (self ) -> dict [str , Type ]:
55- wired : dict [str , Type ] = {}
54+ def _container_inputs (self ) -> dict [str , Any ]:
55+ wired : dict [str , Any ] = {}
5656 for name , tp in self .inputs .items ():
5757 is_opt , inner = _is_optional (tp )
5858 if _is_dict_str_str (inner ):
@@ -81,10 +81,7 @@ def _build_command(self) -> list[str]:
8181 script = self .script ,
8282 inputs = self .inputs ,
8383 outputs = self .outputs ,
84- flag_specs = {
85- name : FlagSpec .coerce (name , self .flag_aliases .get (name ))
86- for name in self .inputs
87- },
84+ flag_specs = {name : FlagSpec .coerce (name , self .flag_aliases .get (name )) for name in self .inputs },
8885 input_data_dir = self .input_data_dir ,
8986 output_data_dir = self .output_data_dir ,
9087 )
@@ -100,17 +97,13 @@ def _build_command(self) -> list[str]:
10097 mkdirs = [
10198 f"mkdir -p { shlex .quote (str (self .output_data_dir / name ))} "
10299 for name , spec in self .outputs .items ()
103- if isinstance (spec , Glob )
104- or (isinstance (spec , type ) and issubclass (spec , Dir ))
100+ if isinstance (spec , Glob ) or (isinstance (spec , type ) and issubclass (spec , Dir ))
105101 ]
106102 mkdir_preamble = "; " .join (mkdirs ) + ";" if mkdirs else ""
107103
108104 debug_preamble = ""
109105 if self .debug :
110- debug_preamble = (
111- 'echo "--- shell task: rendered script ---" >&2; '
112- f"cat <<'_EOF_' >&2\n { body } \n _EOF_\n "
113- )
106+ debug_preamble = f"echo \" --- shell task: rendered script ---\" >&2; cat <<'_EOF_' >&2\n { body } \n _EOF_\n "
114107
115108 wrapped = (
116109 f"{ mkdir_preamble } "
@@ -187,9 +180,7 @@ async def _unpack_outputs(self, raw: Any) -> Any:
187180 if isinstance (spec , Glob ) and isinstance (value , Dir ):
188181 local = await value .download () if hasattr (value , "download" ) else value .path
189182 matched = sorted (pathlib .Path (str (local )).glob (spec .pattern ))
190- unpacked .append (
191- [await File .from_local (str (p )) for p in matched if p .is_file ()]
192- )
183+ unpacked .append ([await File .from_local (str (p )) for p in matched if p .is_file ()])
193184 else :
194185 unpacked .append (value )
195186 return unpacked [0 ] if single else tuple (unpacked )
@@ -223,20 +214,15 @@ async def _prepare_kwargs(self, kwargs: dict[str, Any]) -> dict[str, Any]:
223214 for k , v in value .items ():
224215 if _DICT_SEP in k or _DICT_SEP in v :
225216 raise ValueError (
226- f"dict input { name !r} : keys/values cannot contain the "
227- f"record-separator byte (\\ x1e)."
217+ f"dict input { name !r} : keys/values cannot contain the record-separator byte (\\ x1e)."
228218 )
229219 parts .append (k )
230220 parts .append (v )
231221 out [name ] = _DICT_SEP .join (parts )
232222 continue
233223
234224 if is_opt and kind in ("scalar" , "bool" ):
235- out [name ] = (
236- "true"
237- if (kind == "bool" and value )
238- else "false" if kind == "bool" else str (value )
239- )
225+ out [name ] = "true" if (kind == "bool" and value ) else "false" if kind == "bool" else str (value )
240226 continue
241227
242228 out [name ] = value
@@ -310,9 +296,7 @@ def create(
310296 inputs : Optional [dict [str , Type ]] = None ,
311297 outputs : Optional [dict [str , Any ]] = None ,
312298 script : str ,
313- flag_aliases : Optional [
314- dict [str , Union [str , Tuple [str , listMode ], FlagSpec ]]
315- ] = None ,
299+ flag_aliases : Optional [dict [str , Union [str , Tuple [str , listMode ], FlagSpec ]]] = None ,
316300 shell : str = "/bin/bash" ,
317301 debug : bool = False ,
318302 resources : Optional [flyte .Resources ] = None ,
@@ -484,16 +468,11 @@ async def pipeline(a: File, b: list[File]) -> list[File]:
484468 coerced_aliases : dict [str , FlagSpec ] = {}
485469 for n , alias in (flag_aliases or {}).items ():
486470 if n not in inputs :
487- raise KeyError (
488- f"flag_aliases references { n !r} which is not declared in inputs."
489- )
471+ raise KeyError (f"flag_aliases references { n !r} which is not declared in inputs." )
490472 coerced_aliases [n ] = FlagSpec .coerce (n , alias )
491473
492474 if not isinstance (image , (str , flyte .Image )):
493- raise TypeError (
494- f"image must be a URI string or a flyte.Image, got "
495- f"{ type (image ).__name__ } ."
496- )
475+ raise TypeError (f"image must be a URI string or a flyte.Image, got { type (image ).__name__ } ." )
497476
498477 return _Shell (
499478 name = name ,
0 commit comments