MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / execute_script

Function execute_script

pythonFiles/tests/ipython/scripts.py:20–42  ·  view source on GitHub ↗
(file, replace_dict=dict([]))

Source from the content-addressed store, hash-verified

18
19
20def execute_script(file, replace_dict=dict([])):
21 from IPython import get_ipython
22
23 regex = (
24 re.compile("|".join(replace_dict.keys()))
25 if len(replace_dict.keys()) > 0
26 else None
27 )
28
29 # Open the file. Read all lines into a string
30 contents = ""
31 with open(file, "r") as fp:
32 for line in fp:
33 # Replace the key value pairs
34 contents += (
35 line
36 if regex == None
37 else regex.sub(lambda m: replace_dict[m.group()], line)
38 )
39
40 # Execute this script as a cell
41 result = get_ipython().run_cell(contents)
42 return result.success
43
44
45def execute_code(code):

Callers 2

get_variablesFunction · 0.70
get_variable_valueFunction · 0.70

Calls 3

joinMethod · 0.80
groupMethod · 0.80
keysMethod · 0.45

Tested by

no test coverage detected