|
1 | 1 | import json
|
| 2 | +import os |
2 | 3 | import time
|
3 | 4 |
|
4 | 5 | from ..utils.recipient_utils import parse_for_recipient
|
5 | 6 | from .languages.applescript import AppleScript
|
6 | 7 | from .languages.html import HTML
|
| 8 | +from .languages.java import Java |
7 | 9 | from .languages.javascript import JavaScript
|
8 | 10 | from .languages.powershell import PowerShell
|
9 | 11 | from .languages.python import Python
|
10 | 12 | from .languages.r import R
|
11 | 13 | from .languages.react import React
|
12 | 14 | from .languages.ruby import Ruby
|
13 | 15 | from .languages.shell import Shell
|
14 |
| -from .languages.java import Java |
15 | 16 |
|
16 | 17 | # Should this be renamed to OS or System?
|
17 | 18 |
|
| 19 | +import_computer_api_code = """ |
| 20 | +import os |
| 21 | +os.environ["INTERPRETER_COMPUTER_API"] = "False" # To prevent infinite recurring import of the computer API |
| 22 | +
|
| 23 | +import time |
| 24 | +import datetime |
| 25 | +from interpreter import interpreter |
| 26 | +
|
| 27 | +computer = interpreter.computer |
| 28 | +""".strip() |
| 29 | + |
18 | 30 |
|
19 | 31 | class Terminal:
|
20 | 32 | def __init__(self, computer):
|
@@ -48,13 +60,14 @@ def run(self, language, code, stream=False, display=False):
|
48 | 60 | self.computer.import_computer_api
|
49 | 61 | and not self.computer._has_imported_computer_api
|
50 | 62 | and "computer" in code
|
| 63 | + and os.getenv("INTERPRETER_COMPUTER_API", "True") != "False" |
51 | 64 | ):
|
52 | 65 | self.computer._has_imported_computer_api = True
|
53 | 66 | # Give it access to the computer via Python
|
54 | 67 | time.sleep(0.5)
|
55 | 68 | self.computer.run(
|
56 | 69 | language="python",
|
57 |
| - code="import time\nimport datetime\nfrom interpreter import interpreter\ncomputer = interpreter.computer", # We ask it to use time, so |
| 70 | + code=import_computer_api_code, |
58 | 71 | display=self.computer.verbose,
|
59 | 72 | )
|
60 | 73 |
|
|
0 commit comments