Skip to content

Commit 6bf9dc3

Browse files
committed
remove deprecated python kernel code
1 parent 586d5da commit 6bf9dc3

File tree

2 files changed

+2
-74
lines changed

2 files changed

+2
-74
lines changed

cpkernel/kernels/python/codepod.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,20 @@ def code2parts(code):
2525
print('evaluating expr ..')
2626
print(eval(expr))
2727

28-
from collections import defaultdict
29-
3028
d = {}
3129

32-
"""
33-
here's the new plan for python's eval
34-
35-
Python's module is closely bound to the file system, so it is not possible to use that.
36-
37-
I have to use my own globals and locals during exec/eval.
38-
39-
Then, I'll just record the calling relationships for the modules. When evaluating, I'll:
40-
41-
1. eval_func(code, nses)
42-
- nses is a list of namespaces in order, the last one is this ns
43-
- that should be it. The question is where to compute nses. I would
44-
1. compute it when powerRunTree
45-
2. let the kernel knows it by using CODEPOD_ADD_IMPORT. The kernel will record this.
46-
"""
47-
48-
# from ns to nses that should imported
49-
import_d = defaultdict(set)
50-
# from ns to exported names
51-
export_d = defaultdict(set)
52-
# from ns to subdeck nses
53-
export_sub_d = defaultdict(set)
54-
# to=>[from=>names]
55-
reexport_d = defaultdict(lambda: defaultdict(set))
56-
5730
def CODEPOD_GETMOD(ns):
5831
if ns not in d:
5932
d[ns] = types.ModuleType(ns)
6033
d[ns].__dict__["CODEPOD_GETMOD"] = CODEPOD_GETMOD
6134
return d[ns]
6235

63-
def merge_dicts(dicts):
64-
"""
65-
Given any number of dictionaries, shallow copy and merge into a new dict,
66-
precedence goes to key-value pairs in latter dictionaries.
67-
"""
68-
result = {}
69-
for dictionary in dicts:
70-
result.update(dictionary)
71-
return result
72-
73-
def CODEPOD_ADD_IMPORT(FROM, TO):
74-
import_d[TO].add(FROM)
75-
def CODEPOD_REMOVE_IMPORT(FROM, TO):
76-
if FROM in import_d[TO]:
77-
import_d[TO].remove(FROM)
78-
def CODEPOD_SET_EXPORT(ns, exports):
79-
export_d[ns] = exports
80-
def CODEPOD_SET_EXPORT_SUB(ns, nses):
81-
export_sub_d[ns] = nses
82-
def CODEPOD_ADD_REEXPORT(from_ns, to_ns, names):
83-
reexport_d[to_ns][from_ns].update(names)
84-
8536
def CODEPOD_EVAL(code, ns):
8637
# the codepod(code) is the program sent to backend
8738
# codepod is defined on the kernel
8839
mod = CODEPOD_GETMOD(ns)
8940
[stmt, expr] = code2parts(code)
90-
91-
# _dict = merge_dicts([{k:v for k,v in CODEPOD_GETMOD(x).__dict__.items() if k in export_d[x]} for x in import_d[ns]])
92-
# for from_ns, names in reexport_d[ns].items():
93-
# for name in names:
94-
# v = CODEPOD_GETMOD(from_ns).__dict__.get(name, None)
95-
# if v:
96-
# _dict[name] = v
41+
9742
if stmt:
9843
exec(stmt, mod.__dict__)
9944
if expr:

ui/src/lib/ws/middleware.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ function powerRun_python({ id, storeAPI, socket }) {
223223
let pod = pods[id];
224224
// python powerrun
225225
// 1. create the module
226-
let names = pod.children
227-
.filter(({ id }) => pods[id].type !== "DECK")
228-
.filter(({ id }) => pods[id].exports)
229-
.map(({ id }) => pods[id].exports);
230-
names = [].concat(...names);
231226
let nses = getUtilNs({ id, pods });
232227
const child_deck_nses = pods[id].children
233228
.filter(({ id }) => pods[id].type === "DECK" && !pods[id].thundar)
@@ -249,7 +244,7 @@ function powerRun_python({ id, storeAPI, socket }) {
249244
// 3. [ ] delete a function. Just delete the parent's def? Not sure.
250245

251246
let allexports = getChildExports({ id, pods });
252-
let export_code = Object.keys(allexports)
247+
let code = Object.keys(allexports)
253248
.map((ns) =>
254249
allexports[ns]
255250
.map(
@@ -260,18 +255,6 @@ function powerRun_python({ id, storeAPI, socket }) {
260255
)
261256
.join("\n");
262257

263-
// 2. import the namespaces
264-
let code = `${nses
265-
.map(
266-
(ns) => `
267-
CODEPOD_ADD_IMPORT("${ns}", "${pod.ns}")`
268-
)
269-
.join("\n")}
270-
271-
CODEPOD_SET_EXPORT("${pod.ns}", {${names.map((name) => `"${name}"`).join(",")}})
272-
273-
${export_code}
274-
`;
275258
// console.log("==== PYTHON CODE", code);
276259
storeAPI.dispatch(repoSlice.actions.clearResults(pod.id));
277260
storeAPI.dispatch(repoSlice.actions.setRunning(pod.id));

0 commit comments

Comments
 (0)