Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/assets/PYTHON-RUNTIME.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ prepare_browser.py regenerates that virtual filesystem at build time.

The worker runs Python on the learner's device. Source edits are stored in
localStorage when available; variables and virtual filesystem state last only
until restart. The controller reapplies the editors on a fresh kernel.
until restart. A fresh Python session uses the saved project files and the current notebook cells.
No analytics, accounts, or backend execution are used.
7 changes: 4 additions & 3 deletions site/assets/notebook-lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const filePaths = {helper: 'helpers.py', config: 'config/analysis.toml'};
const baseConfig = '[paths]\ndata = "../data/raw/trials.csv"\noutput = "../results/baseline"\n\n[preprocessing]\nmin_rt_s = 0.2\nmax_rt_s = 2.0\n';
const baseHelper = 'def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0):\n return trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy()\n';
const storageKey = 'research-code-notebook-v1';
const pythonLoadTimeout = 300000;
const guide = q('[data-guide-action]');
const feedback = q('[data-guide-feedback]');
const stepPanel = q('#current-step');
Expand Down Expand Up @@ -97,7 +98,7 @@ function request(action, values = {}, timeout = 15000) {
const id = ++sequence;
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
terminate(action === 'init' ? 'Python took too long to load.' : 'Python stopped because the action timed out.');
terminate(action === 'init' ? 'Python did not finish downloading. Check your connection or run the downloaded project in Jupyter.' : 'Python stopped because the action timed out.');
}, timeout);
pending.set(id, {resolve, reject, timer});
worker.postMessage({id, action, ...values});
Expand Down Expand Up @@ -125,9 +126,9 @@ async function start() {
if (worker === activeWorker) terminate('Python could not load. Reload the page if retrying does not help.');
};
controls();
message('Loading Python and scientific packages…');
message('Starting Python…');
const projectFiles = Object.fromEntries(Object.entries(filePaths).map(([file, path]) => [path, files[file]]));
await request('init', {files: projectFiles}, 120000);
await request('init', {files: projectFiles}, pythonLoadTimeout);
ready = true;
}

Expand Down
4 changes: 3 additions & 1 deletion site/assets/python-worker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {loadPyodide} from './python-runtime/pyodide.mjs';
let python;
async function initialize(files) {
self.postMessage({type:'status',text:'Loading the local Python runtime and scientific packages…'});
self.postMessage({type:'status',text:'Downloading Python. The first run can take a few minutes.'});
python = await loadPyodide({indexURL:new URL('./python-runtime/',import.meta.url).href});
self.postMessage({type:'status',text:'Loading pandas, NumPy, and Matplotlib…'});
await python.loadPackage(['numpy','pandas','matplotlib']);
self.postMessage({type:'status',text:'Preparing the workshop data…'});
const project = await fetch(new URL('./browser-project.json',import.meta.url));
if(!project.ok) throw new Error('Browser project files are missing. Rebuild the site.');
const bundled = (await project.json()).files;
Expand Down
Loading