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

[hailctl] allow passing arguments to hailctl batch submit scripts #12525

Merged
merged 3 commits into from
Dec 3, 2022
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
51 changes: 51 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,57 @@ steps:
else
exit 1;
fi

cat >hail_with_args.py <<EOF
import hail as hl
import sys

with open('foo/baz.txt') as f:
print(f.read())

hl.init(app_name='test-hailctl-batch-submit-query')
assert hl.utils.range_table(int(sys.argv[1]))._force_count() == 100
EOF

BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json hail_with_args.py 100 | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID | jq -jr '.state')
if [ "$STATUS" == "success" ]; then
exit 0;
else
exit 1;
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have added such a test initially, but can you also test this with a bash script not just a python script?


cat >file.sh <<EOF
set -ex

cat foo
echo "Hello World!"
EOF

BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json file.sh | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID | jq -jr '.state')
if [ "$STATUS" == "success" ]; then
exit 0;
else
exit 1;
fi

cat >file-with-args.sh <<EOF
set -ex

[[ $# -eq 2 ]]

cat foo
echo "Hello World! $1 $2"
EOF

BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json file-with-args.sh abc 123 | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID | jq -jr '.state')
if [ "$STATUS" == "success" ]; then
exit 0;
else
exit 1;
fi
secrets:
- name: worker-deploy-config
namespace:
Expand Down
7 changes: 5 additions & 2 deletions hail/python/hailtop/hailctl/batch/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import orjson
import os
import sys
from shlex import quote as shq

import hailtop.batch as hb
import hailtop.batch_client.client as bc
Expand All @@ -14,13 +15,14 @@


def init_parser(parser):
parser.add_argument('script', type=str, help='Path to script')
parser.add_argument('--name', type=str, default='', help='Batch name')
parser.add_argument('--image-name', type=str, required=False,
help='Name for Docker image. Defaults to hailgenetics/hail')
parser.add_argument('--files', nargs='+', action='append', default=[],
help='Comma-separated list of files or directories to add to the working directory of job')
parser.add_argument('-o', type=str, default='text', choices=['text', 'json'])
parser.add_argument('script', type=str, help='Path to script')
parser.add_argument('arguments', nargs='*', help='Arguments to script')


async def async_main(args):
Expand Down Expand Up @@ -59,7 +61,8 @@ def cloud_prefix(path):
j.env('HAIL_QUERY_BACKEND', 'batch')

command = 'python3' if script.endswith('.py') else 'bash'
j.command(f'{command} {script_file}')
script_arguments = " ".join(shq(x) for x in args.arguments)
j.command(f'{command} {script_file} {script_arguments}')
batch_handle: bc.Batch = b.run(wait=False, disable_progress_bar=quiet) # type: ignore

if args.o == 'text':
Expand Down