Skip to content

Commit

Permalink
fix: run ruff check --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Sep 18, 2024
1 parent 48d1796 commit 2a642ba
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 766 deletions.
2 changes: 1 addition & 1 deletion agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import sys
from agent.cli import cli

from agent.cli import cli

if __name__ == "__main__":
if getattr(sys, "frozen", False):
Expand Down
26 changes: 10 additions & 16 deletions agent/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from agent.utils import get_execution_result

if TYPE_CHECKING:
from typing import Any, Optional
from typing import Any

from agent.job import Job, Step


class Base:
if TYPE_CHECKING:
job_record: "Optional[Job]"
step_record: "Optional[Step]"
job_record: Job | None
step_record: Step | None

def __init__(self):
self.directory = None
Expand Down Expand Up @@ -65,7 +65,7 @@ def execute(
"traceback": "".join(traceback.format_exc()),
}
)
raise AgentException(self.data)
raise AgentException(self.data) from e
else:
self.data.update({"status": "Success"})
finally:
Expand All @@ -81,9 +81,7 @@ def execute(
self.log()
return self.data

def run_subprocess(
self, command, directory, input, executable, non_zero_throw=True
):
def run_subprocess(self, command, directory, input, executable, non_zero_throw=True):
# Start a child process and start reading output immediately
with subprocess.Popen(
command,
Expand All @@ -102,9 +100,7 @@ def run_subprocess(
# This is equivalent of check=True
# Raise an exception if the process returns a non-zero return code
if non_zero_throw and returncode:
raise subprocess.CalledProcessError(
returncode, command, output=output
)
raise subprocess.CalledProcessError(returncode, command, output=output)
return output, returncode

def parse_output(self, process) -> str:
Expand All @@ -122,7 +118,7 @@ def parse_output(self, process) -> str:
elif char == b"\r":
# Publish output and then wipe current line.
# Include the overwritten line in the output
self.publish_lines(lines + [line.decode(errors="replace")])
self.publish_lines([*lines, line.decode(errors="replace")])
line = b""
elif char == b"\n":
lines.append(line.decode(errors="replace"))
Expand All @@ -136,12 +132,12 @@ def parse_output(self, process) -> str:
self.publish_lines(lines)
return "\n".join(lines)

def publish_lines(self, lines: "list[str]"):
def publish_lines(self, lines: list[str]):
output = "\n".join(lines)
self.data.update({"output": output})
self.update_redis()

def publish_data(self, data: "Any"):
def publish_data(self, data: Any):
if not isinstance(data, str):
data = json.dumps(data, default=str)

Expand Down Expand Up @@ -222,9 +218,7 @@ def modified_time(file):
"name": x,
"size": stats.st_size / 1000,
"created": str(datetime.fromtimestamp(stats.st_ctime)),
"modified": str(
datetime.fromtimestamp(stats.st_mtime)
),
"modified": str(datetime.fromtimestamp(stats.st_mtime)),
}
)

Expand Down
Loading

0 comments on commit 2a642ba

Please sign in to comment.