Skip to content

Commit

Permalink
Add env to LocalRuntime.execute
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosejimenez committed Nov 16, 2024
1 parent 08ce709 commit 86b7b8d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/swerex/runtime/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class Command(BaseModel):
command has a non-zero exit code and `check` is True.
"""

env: dict[str, str] | None = None
"""Environment variables to pass to the command."""


class CommandResponse(BaseModel):
stdout: str = ""
Expand Down
2 changes: 1 addition & 1 deletion src/swerex/runtime/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async def execute(self, command: Command) -> CommandResponse:
NonZeroExitCodeError: If the command has a non-zero exit code and `check` is True.
"""
try:
result = subprocess.run(command.command, shell=command.shell, timeout=command.timeout, capture_output=True)
result = subprocess.run(command.command, shell=command.shell, timeout=command.timeout, env=command.env, capture_output=True)
r = CommandResponse(
stdout=result.stdout.decode(errors="backslashreplace"),
stderr=result.stderr.decode(errors="backslashreplace"),
Expand Down

0 comments on commit 86b7b8d

Please sign in to comment.