Skip to content

Commit 003af56

Browse files
committed
add julia powerrun support
1 parent 66b8949 commit 003af56

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

api/kernels/julia/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ RUN KERNEL_PATH=`julia -e 'import IJulia; print(joinpath(dirname(pathof(IJulia))
1414
# the same (because the path is not the same)
1515
ln -sf $KERNEL_PATH /kernel.jl
1616

17+
RUN julia -e 'import Pkg; Pkg.add("Reexport")'
18+
RUN julia -e 'import Pkg; Pkg.status()'
19+
1720
COPY ./start.sh /start.sh
1821
COPY ./conn.json /conn.json
1922

api/kernels/julia/codepod.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function ensureModuleDefined(namespace)
1818
for name in names
1919
name = Symbol(name)
2020
if !isdefined(eval(mod), name)
21-
include_string(eval(mod), "module $name end")
21+
include_string(eval(mod), "module $name using Reexport end")
2222
end
2323
mod = :($mod.$name)
2424
end
@@ -47,4 +47,4 @@ function CODEPOD_DELETE_IMPORT(ns, name)
4747
end
4848

4949
import Pkg
50-
Pkg.activate("CODEPOD")
50+
# Pkg.activate("CODEPOD")

ui/src/components/repo/pod.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,30 @@ export function DeckTitle({ id }) {
197197
<Divider />
198198
</Box>
199199
)}
200+
{pod.error && (
201+
<Box overflow="scroll" maxH="3xs" border="1px" bg="gray.50">
202+
<Text color="red">Error: {pod.error.evalue}</Text>
203+
{pod.error.stacktrace && (
204+
<Box>
205+
<Text>StackTrace</Text>
206+
{/* <Code w="100%" whiteSpace="pre-wrap" bg="gray.50" fontSize="sm">
207+
{stripAnsi(pod.error.stacktrace.join("\n"))}
208+
</Code> */}
209+
<Box
210+
whiteSpace="pre-wrap"
211+
fontSize="sm"
212+
// this inline-style also works
213+
// but it cannot be applied to <Ansi/> tag
214+
// style={{
215+
// whiteSpace: "pre-wrap",
216+
// }}
217+
>
218+
<Ansi>{pod.error.stacktrace.join("\n")}</Ansi>
219+
</Box>
220+
</Box>
221+
)}
222+
</Box>
223+
)}
200224
{pod.running && <Text>Running ..</Text>}
201225
<Box
202226
style={{

ui/src/lib/ws/middleware.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,81 @@ function handlePowerRun({ id, doEval, storeAPI, socket }) {
133133
},
134134
})
135135
);
136+
} else if (pod.lang === "julia") {
137+
let names = pod.children
138+
.filter(({ id }) => pods[id].type !== "DECK")
139+
.filter(({ id }) => pods[id].exports)
140+
.map(({ id }) =>
141+
Object.entries(pods[id].exports)
142+
.filter(([k, v]) => v)
143+
.map(([k, v]) => k)
144+
);
145+
names = [].concat(...names);
146+
let nses = getUtilNs({ id, pods });
147+
const child_deck_nses = pods[id].children
148+
.filter(({ id }) => pods[id].type === "DECK" && !pods[id].thundar)
149+
.map(({ id, type }) => pods[id].ns);
150+
nses = nses.concat(child_deck_nses);
151+
// if it is a test desk, get parent
152+
if (pod.thundar) {
153+
nses.push(pods[pod.parent].ns);
154+
}
155+
156+
// exported subdecks
157+
let exported_decks = pods[id].children
158+
.filter(
159+
({ id }) =>
160+
pods[id].type === "DECK" &&
161+
pods[id].exports &&
162+
pods[id].exports["self"]
163+
)
164+
.map(({ id, type }) => pods[id].ns);
165+
166+
// nses = nses.concat(exported_decks);
167+
168+
function ns2jlmod(ns) {
169+
return "Main." + ns.replaceAll("/", ".");
170+
}
171+
172+
let code = `
173+
${nses
174+
.map(
175+
(ns) =>
176+
`include_string(eval(:(${ns2jlmod(pod.ns)})), "using $(eval(:(${ns2jlmod(
177+
ns
178+
)})))")`
179+
)
180+
.join("\n")}
181+
182+
${exported_decks.map(
183+
(ns) =>
184+
`include_string(eval(:(${ns2jlmod(
185+
pod.ns
186+
)})), "@reexport using $(eval(:(${ns2jlmod(ns)})))")`
187+
)}
188+
189+
${names.length > 0 ? `export ${names.join(",")}` : ""}
190+
191+
`;
192+
// console.log("code:", code);
193+
// ${struct_names.map((name) => `(struct ${name} ())`)}
194+
195+
storeAPI.dispatch(repoSlice.actions.clearResults(pod.id));
196+
storeAPI.dispatch(repoSlice.actions.setRunning(pod.id));
197+
socket.send(
198+
JSON.stringify({
199+
type: "runCode",
200+
payload: {
201+
lang: pod.lang,
202+
code,
203+
namespace: pod.ns,
204+
// raw: true,
205+
// FIXME this is deck's ID
206+
podId: pod.id,
207+
sessionId: storeAPI.getState().repo.sessionId,
208+
},
209+
})
210+
);
136211
}
137212
if (doEval) {
138213
// run all children pods

0 commit comments

Comments
 (0)