Skip to content

Commit e5fdc57

Browse files
committed
Fixed rare skill issue
1 parent 68ab324 commit e5fdc57

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

interpreter/core/computer/skills/skills.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@ def search(self, query):
2424

2525
def import_skills(self):
2626
previous_save_skills_setting = self.computer.save_skills
27+
2728
self.computer.save_skills = False
2829

30+
# Make sure it's not over 100mb
31+
total_size = 0
32+
for path, dirs, files in os.walk(self.path):
33+
for f in files:
34+
fp = os.path.join(path, f)
35+
total_size += os.path.getsize(fp)
36+
total_size = total_size / (1024 * 1024) # convert bytes to megabytes
37+
if total_size > 100:
38+
raise Warning(
39+
f"Skills at path {self.path} can't exceed 100mb. Try deleting some."
40+
)
41+
2942
code_to_run = ""
3043
for file in glob.glob(os.path.join(self.path, "*.py")):
3144
with open(file, "r") as f:
@@ -34,7 +47,24 @@ def import_skills(self):
3447
if self.computer.interpreter.debug:
3548
print("IMPORTING SKILLS:\n", code_to_run)
3649

37-
self.computer.run("python", code_to_run)
50+
output = self.computer.run("python", code_to_run)
51+
52+
if "traceback" in output.lower():
53+
# Import them individually
54+
for file in glob.glob(os.path.join(self.path, "*.py")):
55+
with open(file, "r") as f:
56+
code_to_run = f.read() + "\n"
57+
58+
if self.computer.interpreter.debug:
59+
print("IMPORTING SKILL:\n", code_to_run)
60+
61+
output = self.computer.run("python", code_to_run)
62+
63+
if "traceback" in output.lower():
64+
print(
65+
f"Skill at {file} might be broken— it produces a traceback when run."
66+
)
67+
3868
self.computer.save_skills = previous_save_skills_setting
3969

4070

0 commit comments

Comments
 (0)