Skip to content

Commit a53732d

Browse files
Kiuk Chungfacebook-github-bot
authored andcommitted
(torchx/cli)(bugfix) gracefully handle leading -- in torchx run, when no component args are present
Summary: If user specifies BOTH: 1. the default component name 2. ALL default component args In `.torchxconfig`, then ``` $ torchx run $ torchx run -- ``` should both work, but the second case is not handled properly due to a missing length check after removing the leading "--". Reviewed By: d4l3k Differential Revision: D33641288 fbshipit-source-id: a4089704dd67206f8f5b3a959e0e56f2f39d506c
1 parent c37cfd7 commit a53732d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

torchx/cli/cmd_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _parse_component_name_and_args(
102102
if args[0] == "--":
103103
args = args[1:]
104104

105+
if len(args) > 0: # check len again in case we removed the leading "--" above
105106
if args[0].startswith("-"):
106107
component_args = args
107108
else: # first element is NOT an option; then it must be a component name

torchx/cli/test/cmd_run_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ def test_parse_component_name_and_args_no_default(self) -> None:
219219
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp),
220220
)
221221

222+
with self.assertRaises(SystemExit):
223+
_parse_component_name_and_args(["--"], sp)
224+
222225
with self.assertRaises(SystemExit):
223226
_parse_component_name_and_args(["--msg", "hello"], sp)
224227

@@ -248,6 +251,10 @@ def test_parse_component_name_and_args_with_default(self) -> None:
248251
("custom.echo", []),
249252
_parse_component_name_and_args([], sp, dirs),
250253
)
254+
self.assertEqual(
255+
("custom.echo", []),
256+
_parse_component_name_and_args(["--"], sp, dirs),
257+
)
251258
self.assertEqual(
252259
("custom.echo", ["--msg", "hello"]),
253260
_parse_component_name_and_args(["--", "--msg", "hello"], sp, dirs),

0 commit comments

Comments
 (0)