Skip to content

Commit

Permalink
FIX: solving the nested functions problem in script exec
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed Feb 8, 2024
1 parent 0f69838 commit b066140
Show file tree
Hide file tree
Showing 4 changed files with 656 additions and 636 deletions.
Binary file added GH/PyGH/assets/img/single_comp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GH/PyGH/assets/img/snapshot_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions GH/PyGH/components/scriptsynccpy/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def safe_exec(self, path, globals, locals):
try:
with open(path, 'r') as f:
# add the path of the file to use the modules
path_dir = self.path.split("\\")
path_dir = path.split("\\")
path_dir = "\\".join(path_dir[:-1])
sys.path.insert(0, path_dir)

Expand All @@ -315,7 +315,7 @@ def safe_exec(self, path, globals, locals):
locals["stdout"] = output.getvalue()

# send the msg to the vscode server
msg_json = json.dumps({"script_path": self.path,
msg_json = json.dumps({"script_path": path,
"guid": str(ghenv.Component.InstanceGuid),
"msg": output.getvalue()})
msg_json = msg_json.encode('utf-8')
Expand All @@ -337,7 +337,7 @@ def safe_exec(self, path, globals, locals):
except Exception as e:

# send the error message to the vscode server
err_json = json.dumps({"script_path": self.path,
err_json = json.dumps({"script_path": path,
"guid": str(ghenv.Component.InstanceGuid),
"msg": "err:" + str(e)})
err_json = err_json.encode('utf-8')
Expand All @@ -349,9 +349,7 @@ def safe_exec(self, path, globals, locals):
err_msg = f"script-sync::Error in the code: {str(e)}"
raise Exception(err_msg)

def RunScript(self,
btn : bool,
x : int):
def RunScript(self, btn: bool, x: float):
""" This method is called whenever the component has to be recalculated it's the solve main instance. """

self.is_success = False
Expand All @@ -377,7 +375,7 @@ def RunScript(self,
).start()

# run the script
res = self.safe_exec(self.path, globals(), locals())
res = self.safe_exec(self.path, None, globals())
self.is_success = True
return

Expand Down
Loading

0 comments on commit b066140

Please sign in to comment.