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

[batch] Omit empty command strings when constructing shell scripts #14700

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions hail/python/hailtop/batch/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ def command(self, command: str) -> 'BashJob':
Same job object with command appended.
"""

if command.strip() == '':
job_name = f'job {self.name!r}' if self.name else 'unnamed job'
warnings.warn(f'Ignoring empty command specified for {job_name}.')
return self

command = self._interpolate_command(command)
self._command.append(command)
return self
Expand Down
14 changes: 14 additions & 0 deletions hail/python/test/hailtop/batch/test_batch_local_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import subprocess as sp
import tempfile
from random import choice, randint
from string import whitespace
from typing import AsyncIterator

import pytest
Expand Down Expand Up @@ -179,6 +181,18 @@
b.run()


@pytest.fixture
def randwhitespace():
return ''.join(choice(whitespace) for _ in range(randint(0, 9)))

Check warning on line 186 in hail/python/test/hailtop/batch/test_batch_local_backend.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hail/python/test/hailtop/batch/test_batch_local_backend.py#L186

Standard pseudo-random generators are not suitable for security/cryptographic purposes.


@pytest.mark.parametrize('randwhitespace', range(20), indirect=True)
def test_single_job_empty_command(batch, randwhitespace):
j = batch.new_job()
with pytest.warns(match='Ignoring empty command'):
j.command(randwhitespace)


def test_declare_resource_group(batch):
with tempfile.NamedTemporaryFile('w') as output_file:
msg = 'hello world'
Expand Down