Local
Local Environment class
Full source code
import os
import platform
import subprocess
from dataclasses import asdict, dataclass, field
from typing import Any
@dataclass
class LocalEnvironmentConfig:
cwd: str = ""
env: dict[str, str] = field(default_factory=dict)
timeout: int = 30
class LocalEnvironment:
def __init__(self, *, config_class: type = LocalEnvironmentConfig, **kwargs):
"""This class executes bash commands directly on the local machine."""
self.config = config_class(**kwargs)
def execute(self, command: str, cwd: str = "", *, timeout: int | None = None):
"""Execute a command in the local environment and return the result as a dict."""
cwd = cwd or self.config.cwd or os.getcwd()
result = subprocess.run(
command,
shell=True,
text=True,
cwd=cwd,
env=os.environ | self.config.env,
timeout=timeout or self.config.timeout,
encoding="utf-8",
errors="replace",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
return {"output": result.stdout, "returncode": result.returncode}
def get_template_vars(self) -> dict[str, Any]:
return asdict(self.config) | platform.uname()._asdict() | os.environ
minisweagent.environments.local
LocalEnvironmentConfig
dataclass
LocalEnvironmentConfig(
cwd: str = "",
env: dict[str, str] = dict(),
timeout: int = 30,
)
cwd
class-attribute
instance-attribute
cwd: str = ''
env
class-attribute
instance-attribute
env: dict[str, str] = field(default_factory=dict)
timeout
class-attribute
instance-attribute
timeout: int = 30
LocalEnvironment
LocalEnvironment(
*, config_class: type = LocalEnvironmentConfig, **kwargs
)
This class executes bash commands directly on the local machine.
Source code in src/minisweagent/environments/local.py
16 17 18 | |
config
instance-attribute
config = config_class(**kwargs)
execute
execute(
command: str,
cwd: str = "",
*,
timeout: int | None = None,
)
Execute a command in the local environment and return the result as a dict.
Source code in src/minisweagent/environments/local.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
get_template_vars
get_template_vars() -> dict[str, Any]
Source code in src/minisweagent/environments/local.py
37 38 | |