From 72fb5e4f0744fa0ab4fd2342e3d94396d674d12a Mon Sep 17 00:00:00 2001 From: Shicong Huang Date: Thu, 20 Feb 2025 19:10:17 -0800 Subject: [PATCH] Handle args for customized entrypoint Summary: When customized entrypoint is provided, the args need to be persevered in the original format. Differential Revision: D69964149 --- torchx/components/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/torchx/components/utils.py b/torchx/components/utils.py index e64069a14..7709f1553 100644 --- a/torchx/components/utils.py +++ b/torchx/components/utils.py @@ -104,19 +104,26 @@ def sh( entrypoint: the entrypoint to use for the command (defaults to sh) """ - escaped_args = " ".join(shlex.quote(arg) for arg in args) + escaped_args = [shlex.quote(arg) for arg in args] if env is None: env = {} env.setdefault("LOGLEVEL", os.getenv("LOGLEVEL", "WARNING")) + if entrypoint is not None: + resolved_entrypoint = entrypoint + resolved_args = escaped_args + else: + resolved_entrypoint = "sh" + resolved_args = ["-c", " ".join(escaped_args)] + return specs.AppDef( name="sh", roles=[ specs.Role( name="sh", image=image, - entrypoint=entrypoint or "sh", - args=["-c", escaped_args], + entrypoint=resolved_entrypoint, + args=resolved_args, num_replicas=num_replicas, resource=specs.resource(cpu=cpu, gpu=gpu, memMB=memMB, h=h), env=env,