Skip to content

Commit

Permalink
🔌 apply default lite plugin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Jan 3, 2025
1 parent e6be71f commit a5c6e7b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 50 deletions.
7 changes: 7 additions & 0 deletions .changeset/lovely-roses-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'thebe-react': minor
'thebe-lite': minor
'demo-simple': minor
---

Clients no longer have to explicitly supply `litePluginSettings` unless they explicitly want to override them. This simplifies upgrades as clients should just bump packages, and the correct plugin settings for the bundled pyodide kernel will be applied by default.
12 changes: 0 additions & 12 deletions apps/simple/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@
}
}
</script>
<script id="jupyter-config-data" type="application/json">
{
"litePluginSettings": {
"@jupyterlite/pyodide-kernel-extension:kernel": {
"pipliteUrls": ["https://unpkg.com/@jupyterlite/[email protected]/pypi/all.json"],
"pipliteWheelUrl": "https://unpkg.com/@jupyterlite/[email protected]/pypi/piplite-0.4.7-py3-none-any.whl"
}
},
"enableMemoryStorage": true,
"settingsStorageDrivers": ["memoryStorageDriver"]
}
</script>
<!-- this following is the thebe entrypoint script -->
<script src="thebe-lite.min.js"></script>
<script src="index.js"></script>
Expand Down
12 changes: 0 additions & 12 deletions apps/simple/static/ipywidgets-lite.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
useBinder: false
}
</script>
<script id="jupyter-config-data" type="application/json">
{
"litePluginSettings": {
"@jupyterlite/pyodide-kernel-extension:kernel": {
"pipliteUrls": ["https://unpkg.com/@jupyterlite/[email protected]/pypi/all.json"],
"pipliteWheelUrl": "https://unpkg.com/@jupyterlite/[email protected]/pypi/piplite-0.4.7-py3-none-any.whl"
}
},
"enableMemoryStorage": true,
"settingsStorageDrivers": ["memoryStorageDriver"]
}
</script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
Expand Down
12 changes: 0 additions & 12 deletions apps/simple/static/lite.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
useBinder: false
}
</script>
<script id="jupyter-config-data" type="application/json">
{
"litePluginSettings": {
"@jupyterlite/pyodide-kernel-extension:kernel": {
"pipliteUrls": ["https://unpkg.com/@jupyterlite/[email protected]/pypi/all.json"],
"pipliteWheelUrl": "https://unpkg.com/@jupyterlite/[email protected]/pypi/piplite-0.4.7-py3-none-any.whl"
}
},
"enableMemoryStorage": true,
"settingsStorageDrivers": ["memoryStorageDriver"]
}
</script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
Expand Down
26 changes: 23 additions & 3 deletions packages/lite/src/jlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,29 @@ export async function startJupyterLiteServer(config?: LiteServerConfig): Promise
* Do not rely on a configuration being on the document body, accept configuration via arguments
* and set options on the page config directly
*/
if (config?.litePluginSettings) {
PageConfig.setOption('litePluginSettings', JSON.stringify(config.litePluginSettings));
}
const defaultLiteConfig = {
litePluginSettings: {
'@jupyterlite/pyodide-kernel-extension:kernel': {
pipliteUrls: ['https://unpkg.com/@jupyterlite/[email protected]/pypi/all.json'],
pipliteWheelUrl:
'https://unpkg.com/@jupyterlite/[email protected]/pypi/piplite-0.4.7-py3-none-any.whl',
},
},
enableMemoryStorage: true,
settingsStorageDrivers: ['memoryStorageDriver'],
};
PageConfig.setOption(
'litePluginSettings',
JSON.stringify({ ...defaultLiteConfig.litePluginSettings, ...config?.litePluginSettings }),
);
PageConfig.setOption(
'enableMemoryStorage',
JSON.stringify(config?.enableMemoryStorage ?? defaultLiteConfig.enableMemoryStorage),
);
PageConfig.setOption(
'settingsStorageDrivers',
JSON.stringify(config?.settingsStorageDrivers ?? defaultLiteConfig.settingsStorageDrivers),
);

/**
* Seems like there are 4 different extensions we may want to handle
Expand Down
4 changes: 3 additions & 1 deletion packages/lite/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import type { ServiceManager } from '@jupyterlab/services';
*/

export type LiteServerConfig = {
litePluginSettings: Record<string, any>;
litePluginSettings?: Record<string, any>;
enableMemoryStorage?: boolean;
settingsStorageDrivers?: string[];
};

export interface ThebeLiteGlobal {
Expand Down
11 changes: 1 addition & 10 deletions packages/react/src/ThebeServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,7 @@ export function ThebeServerProvider({
setConnecting(true);
if (customConnectFn) customConnectFn(server);
else if (useBinder) server.connectToServerViaBinder(customRepoProviders);
else if (useJupyterLite)
server.connectToJupyterLiteServer({
litePluginSettings: {
'@jupyterlite/pyodide-kernel-extension:kernel': {
pipliteUrls: ['https://unpkg.com/@jupyterlite/[email protected]/pypi/all.json'],
pipliteWheelUrl:
'https://unpkg.com/@jupyterlite/[email protected]/pypi/piplite-0.4.7-py3-none-any.whl',
},
},
});
else if (useJupyterLite) server.connectToJupyterLiteServer();
else server.connectToJupyterServer();

server.ready.then(
Expand Down

0 comments on commit a5c6e7b

Please sign in to comment.