Skip to content

Commit 5ab926a

Browse files
committed
Change run_code function to fix error on linux machines
1 parent d7051f6 commit 5ab926a

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

io_scene_halo/global_functions/global_functions.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,30 +1642,41 @@ def get_data_checksum():
16421642
return pack_datetime(now.year, now.month, now.day, now.hour, now.minute)
16431643

16441644
def run_code(code_string):
1645-
def toolset_exec(code):
1646-
if bpy.context.preferences.addons["io_scene_halo"].preferences.enable_profiling:
1645+
import inspect
1646+
import sys
1647+
from .. import crash_report
1648+
1649+
def toolset_exec(code, glb, loc):
1650+
prefs = bpy.context.preferences.addons["io_scene_halo"].preferences
1651+
1652+
if prefs.enable_profiling:
16471653
import cProfile
1648-
cProfile.runctx(code, globals(), caller_locals)
1654+
cProfile.runctx(code, glb, loc)
16491655

1650-
elif bpy.context.preferences.addons["io_scene_halo"].preferences.enable_debug:
1656+
elif prefs.enable_debug:
16511657
import pdb
1652-
pdb.runctx(code, globals(), caller_locals)
1658+
pdb.runctx(code, glb, loc)
16531659

16541660
else:
1655-
exec(code, globals(), caller_locals)
1661+
exec(code, glb, loc)
16561662

1657-
import inspect
1658-
from .. import crash_report
16591663
frame = inspect.currentframe()
1664+
16601665
try:
16611666
caller_locals = frame.f_back.f_locals
16621667
report = caller_locals['self'].report
16631668

1664-
# this hack is horrible but it works??
1665-
toolset_exec(f"""locals()['__this_is_a_horrible_hack'] = {code_string}""")
1666-
result = caller_locals['__this_is_a_horrible_hack']
1667-
caller_locals.pop('__this_is_a_horrible_hack', None)
1668-
return result
1669+
exec_locals = dict(caller_locals)
1670+
1671+
try:
1672+
result = eval(code_string, globals(), exec_locals)
1673+
return result
1674+
1675+
except SyntaxError:
1676+
compiled = compile(code_string, "<string>", "exec")
1677+
toolset_exec(compiled, globals(), exec_locals)
1678+
1679+
return exec_locals.get("result")
16691680

16701681
except ParseError as parse_error:
16711682
crash_report.report_crash()

0 commit comments

Comments
 (0)