Skip to content

Commit 1501839

Browse files
committed
Trying to fix failing tests
Signed-off-by: Marc Romeyn <[email protected]>
1 parent 05ca33d commit 1501839

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

nemo_run/cli/api.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,28 @@ def parse_fn(self, fn: T, args: List[str], **default_kwargs) -> Partial[T]:
12321232
Returns:
12331233
Partial[T]: A Partial object representing the parsed function and arguments.
12341234
"""
1235-
output = LazyEntrypoint(fn, factory=self.factory, yaml=self.yaml, overwrites=args)
1235+
lazy = LazyEntrypoint(
1236+
fn,
1237+
factory=self.factory,
1238+
yaml=self.yaml,
1239+
overwrites=args,
1240+
)
1241+
1242+
# Resolve exactly once and always pass the current RunContext
1243+
# NOTE: `LazyEntrypoint.resolve` calls `parse_factory` if
1244+
# `lazy._factory_` is a string. `parse_cli_args` that follows inside
1245+
# `resolve` used to see the **same** string and call `parse_factory`
1246+
# a second time. We temporarily clear `_factory_` right after the
1247+
# first resolution so that it cannot be triggered again.
1248+
1249+
_orig_factory = lazy._factory_
1250+
try:
1251+
result = lazy.resolve(ctx=self)
1252+
finally:
1253+
# Restore for potential further use
1254+
lazy._factory_ = _orig_factory
12361255

1237-
return output.resolve(ctx=self)
1256+
return result
12381257

12391258
def _parse_partial(self, fn: Callable, args: List[str], **default_args) -> Partial[T]:
12401259
"""

0 commit comments

Comments
 (0)