Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing empty stdout/stderr to Python function tasks #692

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
(e.g. if hostname is "cn690.karolina.it4i.cz", only "cn690" is written into node list)
You can read ``HQ_HOST_FILE`` if you need to get full hostnames without stripping.

## Fixes

* Enable passing of empty `stdout`/`stderr` to Python function tasks in the Python
API (https://github.com/It4innovations/hyperqueue/issues/691).

# v0.18.0

Expand Down
4 changes: 4 additions & 0 deletions crates/pyhq/python/hyperqueue/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

@dataclasses.dataclass
class StdioDef:
"""
If `path` is `None`, then the default HQ path will be used.
"""

path: Optional[GenericPath]
on_close: FileOnCloseBehavior

Expand Down
6 changes: 4 additions & 2 deletions crates/pyhq/python/hyperqueue/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ def _build(self, client):
raise NotImplementedError


def build_stdio(stdio: Stdio, stream: str) -> StdioDef:
def build_stdio(stdio: Optional[Stdio], stream: str) -> Optional[StdioDef]:
if isinstance(stdio, (str, Path)):
return StdioDef.from_path(stdio)
elif isinstance(stdio, StdioDef):
return stdio
elif stdio is None:
return None
else:
raise ValidationException(
f"Invalid value provided for `{stream}`: {type(stdio)}. Expected str, Path or `StdioDef`."
f"Invalid value provided for `{stream}`: {type(stdio)}. Expected str, Path or `StdioDef` or `None`."
)
20 changes: 20 additions & 0 deletions tests/pyapi/test_job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import os.path
import random
import sys
import time
from pathlib import Path

Expand Down Expand Up @@ -76,6 +78,24 @@ def test_submit_stdio(hq_env: HqEnv):
check_file_contents("err", "Test2\n")


def test_empty_stdio(hq_env: HqEnv):
(job, client) = prepare_job_client(hq_env)

def foo():
print("Hello")
print("Hello", file=sys.stderr)

job.function(
foo,
stdout=None,
stderr=None,
)
submitted_job = client.submit(job)
wait_for_job_state(hq_env, submitted_job.id, "FINISHED")
assert not os.path.isfile("0.stdout")
assert not os.path.isfile("0.stderr")


def test_stdio_rm_if_finished(hq_env: HqEnv):
(job, client) = prepare_job_client(hq_env)
job.program(
Expand Down
Loading