John Purviance
12/13/2023, 5:49 AMShellTask
be a class that users instantiate while python tasks are functions. Python tasks are presented to users as Python functions. Shell tasks are presented as data type to be instantiated. Is there a reason why these diverge?Ketan (kumare3)
Ketan (kumare3)
Ketan (kumare3)
Ketan (kumare3)
Ketan (kumare3)
John Purviance
12/14/2023, 3:29 PMShellTask(
name="task_1",
debug=True,
script="""
set -ex
echo "Hey there! Let's run some bash scripts using Flyte's ShellTask."
echo "Showcasing Flyte's Shell Task." >> {inputs.x}
if grep "Flyte" {inputs.x}
then
echo "Found it!" >> {inputs.x}
else
echo "Not found!"
fi
""",
inputs=kwtypes(x=FlyteFile),
output_locs=[OutputLocation(var="i", var_type=FlyteFile, location="{inputs.x}")],
)
what come to mind is something like (or similar)
@shell_task(
debug = True,
)
def task_1(x: FlyteFile) -> FlyteFile:
return """
set -ex
echo "Hey there! Let's run some bash scripts using Flyte's ShellTask."
echo "Showcasing Flyte's Shell Task." >> {inputs.x}
if grep "Flyte" {inputs.x}
then
echo "Found it!" >> {inputs.x}
else
echo "Not found!"
fi
""""
John Purviance
12/14/2023, 3:30 PMKetan (kumare3)
Niels Bantilan
12/15/2023, 4:02 PM@shell_task
example I think highlights why it’s a little confusing to have functions that return templated strings… the function body of task_1
is returning a string, not a `FlyteFile`… I’ve seen other frameworks do this and always found it odd, personally.Niels Bantilan
12/15/2023, 4:05 PMAnnotated
to add output location metedata:
@shell_task(
debug = True,
)
def task_1(x: FlyteFile) -> typing.Annotated[
FlyteFile,
OutputLocation(var="i", location="{inputs.x}")
]:
"""
set -ex
echo "Hey there! Let's run some bash scripts using Flyte's ShellTask."
echo "Showcasing Flyte's Shell Task." >> {inputs.x}
if grep "Flyte" {inputs.x}
then
echo "Found it!" >> {inputs.x}
else
echo "Not found!"
fi
""""
Niels Bantilan
12/15/2023, 4:11 PMKetan (kumare3)
Niels Bantilan
12/15/2023, 4:12 PMShellTask
right?Ketan (kumare3)
Ketan (kumare3)
Niels Bantilan
12/15/2023, 4:17 PMstr
or None
, and the actual function return type. Not really sure how to assess this trade-off… feel like this is a “taste” thing
@Thomas Fan any thoughts on this? ^^Thomas Fan
12/15/2023, 5:12 PM@shell_task(debug=True)
def task_1(
x: FlyteFile,
y: FlyteDirectory,
) -> Annotated[FlyteFile, OutputLocation(var="j", location="{inputs.y}.tar.gz")]:
shell_context = current_context().shell_context
shell_context.set_script("""
set -ex
cp {inputs.x} {inputs.y}
tar -zcvf {outputs.j} {inputs.y}
""")
return shell_context.output