Skip to content

Commit

Permalink
Made outfile ephemeral
Browse files Browse the repository at this point in the history
Signed-off-by: pryce-turner <pryce.turner@gmail.com>
  • Loading branch information
pryce-turner committed May 9, 2024
1 parent 4dd4d22 commit 9132cf3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flytekit/extras/tasks/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def subproc_execute(command: typing.Union[List[str], str], **kwargs) -> ProcessR
# Execute the command and capture stdout and stderr
result = subprocess.run(command, **kwargs)

assert result.stderr == ""

Check warning on line 83 in flytekit/extras/tasks/shell.py

View check run for this annotation

Codecov / codecov/patch

flytekit/extras/tasks/shell.py#L83

Added line #L83 was not covered by tests

# Access the stdout and stderr output
return ProcessResult(result.returncode, result.stdout, result.stderr)

Expand All @@ -93,6 +95,9 @@ def subproc_execute(command: typing.Union[List[str], str], **kwargs) -> ProcessR
custom dependencies?\n{e}"""
)

except AssertionError:
raise Exception(f"Command: {command}\nexperienced a silent failure, likely due to shell=True:\n{result.stderr}")

Check warning on line 99 in flytekit/extras/tasks/shell.py

View check run for this annotation

Codecov / codecov/patch

flytekit/extras/tasks/shell.py#L98-L99

Added lines #L98 - L99 were not covered by tests


def _dummy_task_func():
"""
Expand Down
24 changes: 24 additions & 0 deletions tests/flytekit/unit/extras/tasks/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,27 @@ def test_subproc_execute_with_shell():
subproc_execute(cmd, shell=True)
cont = open(opth).read()
assert "hello" in cont


def test_subproc_execute_missing_dep():
cmd = ["non-existent", "blah"]
with pytest.raises(Exception) as e:
subproc_execute(cmd)
assert "executable could not be found" in str(e.value)


def test_subproc_execute_error():
cmd = ["ls", "--banana"]
with pytest.raises(Exception) as e:
subproc_execute(cmd)
assert "Failed with return code" in str(e.value)


def test_subproc_execute_shell_error(tmp_path):
# This is a corner case I ran into that really shouldn't
# ever happen. The assert catches anything in stderr despite
# a 0 exit.
cmd = " ".join(["bcftools", "isec", "|", "gzip", "-c", ">", f"{tmp_path.joinpath('out')}"])
with pytest.raises(Exception) as e:
subproc_execute(cmd, shell=True)
assert "silent failure" in str(e.value)

0 comments on commit 9132cf3

Please sign in to comment.