Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change format based on black and isort #1351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion interpreter/core/computer/calendar/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from ..utils.run_applescript import run_applescript, run_applescript_capture


makeDateFunction = """
on makeDate(yr, mon, day, hour, min, sec)
set theDate to current date
Expand All @@ -20,6 +19,7 @@
end makeDate
"""


class Calendar:
def __init__(self, computer):
self.computer = computer
Expand Down
4 changes: 3 additions & 1 deletion interpreter/core/computer/clipboard/clipboard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import platform

from ...utils.lazy_import import lazy_import

# Lazy import of optional packages
pyperclip = lazy_import('pyperclip')
pyperclip = lazy_import("pyperclip")


class Clipboard:
def __init__(self, computer):
Expand Down
3 changes: 2 additions & 1 deletion interpreter/core/computer/docs/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ...utils.lazy_import import lazy_import

# Lazy import of aifs, imported when needed to speed up start time
aifs = lazy_import('aifs')
aifs = lazy_import("aifs")


class Docs:
def __init__(self, computer):
Expand Down
3 changes: 2 additions & 1 deletion interpreter/core/computer/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ...utils.lazy_import import lazy_import

# Lazy import of aifs, imported when needed
aifs = lazy_import('aifs')
aifs = lazy_import("aifs")


class Files:
def __init__(self, computer):
Expand Down
17 changes: 10 additions & 7 deletions interpreter/core/computer/terminal/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import threading
import time
import traceback

from .subprocess_language import SubprocessLanguage


class Java(SubprocessLanguage):
file_extension = "java"
name = "Java"
Expand All @@ -33,28 +35,28 @@ def detect_end_of_execution(self, line):
def run(self, code):
try:
# Extract the class name from the code
match = re.search(r'class\s+(\w+)', code)
match = re.search(r"class\s+(\w+)", code)
if not match:
yield {
"type": "console",
"format": "output",
"content": "Error: No class definition found in the provided code."
"content": "Error: No class definition found in the provided code.",
}
return

class_name = match.group(1)
file_name = f"{class_name}.java"

# Write the Java code to a file, preserving newlines
with open(file_name, "w", newline='\n') as file:
with open(file_name, "w", newline="\n") as file:
file.write(code)

# Compile the Java code
compile_process = subprocess.Popen(
["javac", file_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
text=True,
)

stdout, stderr = compile_process.communicate()
Expand All @@ -63,7 +65,7 @@ def run(self, code):
yield {
"type": "console",
"format": "output",
"content": f"Compilation Error:\n{stderr}"
"content": f"Compilation Error:\n{stderr}",
}
return

Expand All @@ -72,7 +74,7 @@ def run(self, code):
["java", class_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
text=True,
)

stdout_thread = threading.Thread(
Expand Down Expand Up @@ -115,7 +117,7 @@ def run(self, code):
yield {
"type": "console",
"format": "output",
"content": f"{traceback.format_exc()}"
"content": f"{traceback.format_exc()}",
}
finally:
# Clean up the generated Java files
Expand All @@ -125,6 +127,7 @@ def run(self, code):
if os.path.exists(class_file):
os.remove(class_file)


def preprocess_java(code):
"""
Add active line markers
Expand Down
11 changes: 6 additions & 5 deletions interpreter/core/computer/terminal/languages/ruby.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from pathlib import Path

from .subprocess_language import SubprocessLanguage


Expand All @@ -9,12 +10,12 @@ class Ruby(SubprocessLanguage):

def __init__(self):
super().__init__()
self.start_cmd = ["irb"]
self.start_cmd = ["irb"]

def preprocess_code(self, code):
"""
Add active line markers
Wrap in a tryCatch for better error handling
Wrap in a tryCatch for better error handling
Add end of execution marker
"""

Expand All @@ -39,7 +40,7 @@ def preprocess_code(self, code):
end
"""
self.code_line_count = len(processed_code.split("\n"))
#print(processed_code)
# print(processed_code)
return processed_code

def line_postprocessor(self, line):
Expand All @@ -48,7 +49,7 @@ def line_postprocessor(self, line):
self.code_line_count -= 1
return None
if "nil" in line:
return None
return None
return line

def detect_active_line(self, line):
Expand All @@ -57,4 +58,4 @@ def detect_active_line(self, line):
return None

def detect_end_of_execution(self, line):
return "##end_of_execution##" in line or "##execution_error##" in line
return "##end_of_execution##" in line or "##execution_error##" in line
2 changes: 1 addition & 1 deletion interpreter/core/computer/terminal/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from ..utils.recipient_utils import parse_for_recipient
from .languages.applescript import AppleScript
from .languages.html import HTML
from .languages.java import Java
from .languages.javascript import JavaScript
from .languages.powershell import PowerShell
from .languages.python import Python
from .languages.r import R
from .languages.react import React
from .languages.ruby import Ruby
from .languages.shell import Shell
from .languages.java import Java

# Should this be renamed to OS or System?

Expand Down
4 changes: 1 addition & 3 deletions interpreter/core/llm/run_text_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ def run_text_llm(llm, params):
if llm.execution_instructions:
try:
# Add the system message
params["messages"][0][
"content"
] += "\n" + llm.execution_instructions
params["messages"][0]["content"] += "\n" + llm.execution_instructions
except:
print('params["messages"][0]', params["messages"][0])
raise
Expand Down
7 changes: 6 additions & 1 deletion interpreter/core/render_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def render_message(interpreter, message):
)

# Extract the output content
outputs = (line["content"] for line in output if line.get("format") == "output" and "IGNORE_ALL_ABOVE_THIS_LINE" not in line["content"])
outputs = (
line["content"]
for line in output
if line.get("format") == "output"
and "IGNORE_ALL_ABOVE_THIS_LINE" not in line["content"]
)

# Replace the part with the output
parts[i] = "\n".join(outputs)
Expand Down
1 change: 1 addition & 0 deletions interpreter/core/utils/lazy_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib.util
import sys


def lazy_import(name, optional=True):
"""Lazily import a module, specified by the name. Useful for optional packages, to speed up startup times."""
# Check if module is already imported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@
# Set offline for all local models
interpreter.offline = True

import os, platform
import os
import platform

# Get the current user's login name
username = os.getlogin()
Expand Down
Loading