Skip to content

Commit

Permalink
Add function to get rendered arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb committed Oct 8, 2023
1 parent e8786ed commit 1ad3aab
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions benchbuild/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,17 @@ def __call__(self, *args: tp.Any, **kwargs: tp.Any) -> tp.Any:
cmd_w_output = self.as_plumbum(**kwargs)
return watch(cmd_w_output)(*args)

def rendered_args(self, **kwargs: tp.Any) -> tp.Tuple[str, ...]:
args = []

for arg in self._args:
if isinstance(arg, ArgsToken):
args.extend(arg.render(**kwargs))
else:
args.append(str(arg))

return tuple(args)

def as_plumbum(self, **kwargs: tp.Any) -> BoundEnvCommand:
"""
Convert this command into a plumbum compatible command.
Expand All @@ -597,14 +608,7 @@ def as_plumbum(self, **kwargs: tp.Any) -> BoundEnvCommand:
assert cmd_path.exists(), f"{str(cmd_path)} doesn't exist!"

cmd = local[str(cmd_path)]

args = []
for arg in self._args:
if isinstance(arg, ArgsToken):
args.extend(arg.render(**kwargs))
else:
args.append(str(arg))
cmd_w_args = cmd[args]
cmd_w_args = cmd[self.rendered_args(**kwargs)]
cmd_w_output = cmd_w_args
if self.output:
output_path = self.output.render(**kwargs)
Expand Down

0 comments on commit 1ad3aab

Please sign in to comment.