Skip to content

Commit 71cce2a

Browse files
committed
cleanup
1 parent 9ee4920 commit 71cce2a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/lib/python/pyodide.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function runScenario(scenario: string) {
9595
const result = await asyncRunScenario(pythonProgram, {
9696
scenario_json: scenario,
9797
pathname: window.location.pathname,
98-
BASE_URL: window.location.origin + window.location.pathname
98+
model_identifier: window.location.pathname.split("/").slice(-2, -1)[0],
9999
});
100100
if (result.error) {
101101
console.error(result.error);

src/lib/python/pyodide_worker.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare global {
55
interface Window {
66
pyodide: PyodideInterface;
77
scenario_json: string;
8-
BASE_URL: string;
8+
model_identifier: string;
99
}
1010
}
1111

@@ -23,7 +23,7 @@ async function loadPyodideAndPackages(pathname: string) {
2323
self.onmessage = async (event) => {
2424
// The data passed in from the main thread must contain these fields.
2525
// TODO: Type this properly
26-
const { id, python, pathname, scenario_json, BASE_URL } = event.data;
26+
const { id, python, pathname, scenario_json, model_identifier } = event.data;
2727

2828
// Load packages
2929
try {
@@ -38,11 +38,8 @@ self.onmessage = async (event) => {
3838
// So, on the TypeScript side (pyodide.ts) we can do `from js import
3939
// scenario_json`.
4040
self.scenario_json = scenario_json;
41-
// The BASE_URL is more tricky because it must be accessed from the Python
42-
// package itself. We need to set this as a global variable here, which lets
43-
// us do `import pyodide_js; pyodide_js.globals.get("BASE_URL")` (in the
44-
// `cache.py` file).
45-
let model_identifier = BASE_URL.split("/").slice(-2, -1)[0];
41+
// model_identifier sets the DEMOLAND environment variable in the Python
42+
// code. That's how we can access the model identifier in the Python code.
4643
self.pyodide.globals.set("DEMOLAND", model_identifier);
4744

4845
try {

0 commit comments

Comments
 (0)