MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / PythonREPL

Class PythonREPL

bmtools/tools/python/api.py:11–29  ·  view source on GitHub ↗

Simulates a standalone Python REPL.

Source from the content-addressed store, hash-verified

9
10
11class PythonREPL:
12 """Simulates a standalone Python REPL."""
13 def __init__(self) -> None:
14 self.globals: Optional[Dict] = globals()
15 self.locals: Optional[Dict] = None
16
17 def run(self, command: str) -> str:
18 """Run command with own globals/locals and returns anything printed."""
19 old_stdout = sys.stdout
20 sys.stdout = mystdout = StringIO()
21 try:
22 exec(command, self.globals, self.locals)
23 sys.stdout = old_stdout
24 output = mystdout.getvalue()
25 except Exception as e:
26 sys.stdout = old_stdout
27 output = repr(e)
28 print(output)
29 return output
30
31def build_tool(config) -> Tool:
32 tool = Tool(

Callers 1

build_toolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected