MCPcopy Create free account
hub / github.com/SourceCode-AI/aura / execute_interpreter

Function execute_interpreter

aura/python_executor.py:69–107  ·  view source on GitHub ↗

Run script/command inside the defined interpreter and retrieve the JSON encoded output :param command: command/path to script to execute :param interpreter: command/path to the Python interpreter used for execution :param stdin: stdin to pass to the execute program :return: jso

(*, command: List[str], interpreter: str, stdin=None, native_callback: Optional[Callable]=None)

Source from the content-addressed store, hash-verified

67
68
69def execute_interpreter(*, command: List[str], interpreter: str, stdin=None, native_callback: Optional[Callable]=None):
70 """
71 Run script/command inside the defined interpreter and retrieve the JSON encoded output
72
73 :param command: command/path to script to execute
74 :param interpreter: command/path to the Python interpreter used for execution
75 :param stdin: stdin to pass to the execute program
76 :return: json decoded stdout
77 """
78 if interpreter == "native":
79 try:
80 return native_callback(command)
81 except Exception as exc:
82 raise PythonExecutorError(f"Native interpreter failed") from exc
83
84 full_args = [interpreter] + command
85 proc = subprocess.run(
86 args=full_args,
87 stdout=subprocess.PIPE,
88 stderr=subprocess.PIPE,
89 shell=False,
90 input=stdin
91 )
92 if proc.returncode == 0:
93 payload = None
94 try:
95 payload = proc.stdout
96 return loads(payload)
97 except JSONDecodeError:
98 LOGGER.exception(f"Error decoding interpreter JSON: {repr(payload)}")
99 new_exception = PythonExecutorError("Error decoding python interpreter JSON")
100 new_exception.stdout = payload
101 new_exception.stderr = proc.stderr
102 raise new_exception
103 else:
104 exc = PythonExecutorError(f"Interpreter exited with non-zero status code: {proc.returncode}")
105 exc.stderr = proc.stderr
106 exc.stdout = proc.stdout
107 raise exc
108
109
110def get_native_source_code(command):

Callers 2

run_with_interpretersFunction · 0.85
init_native_environmentFunction · 0.85

Calls 2

PythonExecutorErrorClass · 0.85
runMethod · 0.45

Tested by

no test coverage detected