@marimo-team/islands 0.25.2-dev3 → 0.25.2-dev31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConnectedDataExplorerComponent-C2d9ysUI.js → ConnectedDataExplorerComponent-CglAbSke.js} +11 -11
- package/dist/{ErrorBoundary-C5H0YXQW.js → ErrorBoundary-DsBSKWiR.js} +8 -8
- package/dist/{abnfDiagram-VCTEODGH-AFhOQTt8.js → abnfDiagram-VCTEODGH-Bd5MYz7g.js} +3 -3
- package/dist/{any-language-editor-CycIVIeP.js → any-language-editor-dqxlUDlT.js} +3 -3
- package/dist/{architectureDiagram-5GKGNRK7-BngksAAQ.js → architectureDiagram-5GKGNRK7-12FmGgo8.js} +5 -5
- package/dist/assets/__vite-browser-external-BqAtzd2P.js +1 -0
- package/dist/assets/{worker-D7hWi02M.js → worker-Bf8dt6S-.js} +5 -5
- package/dist/{blockDiagram-I7D4REHJ-CvBmppdy.js → blockDiagram-I7D4REHJ-BeHOjyDk.js} +9 -9
- package/dist/{button-DdXAm8iz.js → button-B0Xgl-Qn.js} +12 -0
- package/dist/{c4Diagram-7LVT6UL2-EceL4_jH.js → c4Diagram-7LVT6UL2-Bao10t_O.js} +7 -7
- package/dist/{capabilities-B3ce_GNu.js → capabilities-D7Ad8-zw.js} +1 -1
- package/dist/{cells-Cv93oav_.js → cells-BUbzm9iX.js} +13 -13
- package/dist/{channel-z7HZXHwv.js → channel-BxCkvUgE.js} +1 -1
- package/dist/{chat-ui-fVyVOhYN.js → chat-ui-DJpsSmlB.js} +18 -18
- package/dist/{check-B7cIK6gb.js → check-DGZ74tV2.js} +1 -1
- package/dist/{chunk-4HAMMTFA-BPTTOOC5.js → chunk-4HAMMTFA-CH7Gpamd.js} +5 -5
- package/dist/{chunk-75Z2AOVW-C4AOleKf.js → chunk-75Z2AOVW-AI7CvgKn.js} +1 -1
- package/dist/{chunk-DU6HZSFF-1TwWR6gh.js → chunk-DU6HZSFF-BSvuTkX4.js} +1 -1
- package/dist/{chunk-F27PBJKO-DMI1PBe4.js → chunk-F27PBJKO-CLshwT9T.js} +1 -1
- package/dist/{chunk-GMAD6QVW-vStrMz2P.js → chunk-GMAD6QVW-wnHcn-lH.js} +3 -3
- package/dist/{chunk-GVQU2GXP-2HwWgs4u.js → chunk-GVQU2GXP-7O2p8hut.js} +2 -2
- package/dist/{chunk-IMKFNOWR-UOVZuZVn.js → chunk-IMKFNOWR-BlsbbLiS.js} +6 -6
- package/dist/{chunk-L3NEJ4N5-RhC7i0I2.js → chunk-L3NEJ4N5-B9_Alrxb.js} +5 -5
- package/dist/{chunk-OSK3NFVY-CZV09N-U.js → chunk-OSK3NFVY-PeQPH2fD.js} +6 -6
- package/dist/{chunk-P2QGCYS3-0TAWai9C.js → chunk-P2QGCYS3-D9twiFuU.js} +1 -1
- package/dist/{chunk-POPQ4Y6H-Cc3_56GX.js → chunk-POPQ4Y6H-BUiNs18s.js} +1 -1
- package/dist/{chunk-PWAF6VOD-lNxB9k8z.js → chunk-PWAF6VOD-D8S9NPCy.js} +1 -1
- package/dist/{chunk-SHT3W25Y-CrEPyWy1.js → chunk-SHT3W25Y-DoIB7Bub.js} +8 -8
- package/dist/{chunk-SVP7TREG-uIyyySp6.js → chunk-SVP7TREG-B0dScloT.js} +2 -2
- package/dist/{chunk-TICWLB2K-DdXM3eg6.js → chunk-TICWLB2K-C-lzn2th.js} +6 -6
- package/dist/classDiagram-ZZMXUADV-C5vpBHoS.js +30 -0
- package/dist/classDiagram-v2-VYDZK3BY-BS2Wadt0.js +30 -0
- package/dist/{code-visibility-DOh8H9K5.js → code-visibility-BiRk5YLT.js} +6 -6
- package/dist/{common-BJXaiNuk.js → common-BCp7UGN5.js} +22 -22
- package/dist/{copy-icon-CLdENY__.js → copy-icon-qmRg_VTX.js} +3 -3
- package/dist/{cynefinDiagram-5FMLGOSQ-zknaAsGy.js → cynefinDiagram-5FMLGOSQ-fxnL4mfp.js} +3 -3
- package/dist/{dagre-GXQ25YYZ-BhMOoMGJ.js → dagre-GXQ25YYZ-D5NkGE9i.js} +10 -10
- package/dist/{data-grid-overlay-editor-DVk573OG.js → data-grid-overlay-editor-dYW2R3MH.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-V5-Z-EDY.js → diagram-S7CK7UJ4-CATbk1XK.js} +4 -4
- package/dist/{diagram-UQ7AKVKN-qw8AjDal.js → diagram-UQ7AKVKN-Cjha5vrC.js} +3 -3
- package/dist/{diagram-VSXAHHWV-CR7BJygZ.js → diagram-VSXAHHWV-DPAWJ9Nw.js} +2 -2
- package/dist/{diagram-VX7I27RA-DfuqFb1E.js → diagram-VX7I27RA-BHfAjgGw.js} +5 -5
- package/dist/{diagram-Z3DM3KII-DpWwlYZB.js → diagram-Z3DM3KII-eAoDps6E.js} +3 -3
- package/dist/{dialog-CgNq6y9-.js → dialog-CILKhbsG.js} +3 -3
- package/dist/{dropdown-menu-CZy06LAq.js → dropdown-menu-BaqM0t4N.js} +7 -7
- package/dist/{ebnfDiagram-PWID7BFC-C20OnNMZ.js → ebnfDiagram-PWID7BFC-D8RYnIZC.js} +3 -3
- package/dist/{erDiagram-RLTQ6QDP-DBXLWO9v.js → erDiagram-RLTQ6QDP-BfmoNNce.js} +12 -12
- package/dist/{error-banner-B94dcDmP.js → error-banner-DzAmP0AQ.js} +2 -2
- package/dist/{error-entries-DLl0XqoW.js → error-entries-B9WBDeky.js} +2 -2
- package/dist/{feedback-button-DDiklug9.js → feedback-button-Bz_FnBP3.js} +10 -10
- package/dist/flowDiagram-HODETNUW-Du_I0oTA.js +16 -0
- package/dist/{formats-Cl_67ghI.js → formats-Q9gwlLyD.js} +3 -3
- package/dist/{ganttDiagram-EL5Y4UJY-cRRaDt88.js → ganttDiagram-EL5Y4UJY-B4m_YsKa.js} +2 -2
- package/dist/{gitGraphDiagram-WWUBYQGX-Pox5k9-Y.js → gitGraphDiagram-WWUBYQGX-QRBbvWXh.js} +2 -2
- package/dist/{glide-data-editor-BGagFNmI.js → glide-data-editor-YvyWfJNT.js} +11 -11
- package/dist/{glide-utils-B3rUT5PI.js → glide-utils-CzzWU59p.js} +3 -3
- package/dist/{globals-dZEW_NZh.js → globals-CmV07bVM.js} +3 -3
- package/dist/{html-to-image-CmkwfNkf.js → html-to-image-Btymxku9.js} +11 -11
- package/dist/{infoDiagram-27XIBGKW-ntpxMfrq.js → infoDiagram-27XIBGKW-CHsocw1z.js} +2 -2
- package/dist/{ishikawaDiagram-5VMMS53U-BllIlHE5.js → ishikawaDiagram-5VMMS53U-DZdZJdsT.js} +3 -3
- package/dist/{journeyDiagram-3NMN7TZE-EPJDPlt0.js → journeyDiagram-3NMN7TZE-BeeJdJo3.js} +2 -2
- package/dist/{kanban-definition-UXKFOSKX-GYtNMjtS.js → kanban-definition-UXKFOSKX-B1rrJRmN.js} +9 -9
- package/dist/{label-BslhXqL6.js → label-MNhNNoN6.js} +2 -2
- package/dist/{loader-DEZSzvma.js → loader-C9OUkMrj.js} +1 -1
- package/dist/main.js +177 -150
- package/dist/{mermaid-Dnzoxjt1.js → mermaid-CEceCleL.js} +54 -54
- package/dist/{mindmap-definition-YA3MSWOX-Cth76xgH.js → mindmap-definition-YA3MSWOX-C6-S9h9O.js} +11 -11
- package/dist/{number-overlay-editor-BvOlx4Sw.js → number-overlay-editor-C-KXfL6O.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-Cu4uOXii.js → pegDiagram-XKGWAZYB-BL-R6P57.js} +3 -3
- package/dist/{pieDiagram-E7YTZNPT-Bh3eDa9s.js → pieDiagram-E7YTZNPT-DuAOxSRy.js} +3 -3
- package/dist/{process-output-CYN5E-iO.js → process-output-CTQmCUD0.js} +4 -4
- package/dist/purify.es-DMv5zIkJ.js +866 -0
- package/dist/{quadrantDiagram-AXDQQJYC--kqzFC3w.js → quadrantDiagram-AXDQQJYC-keLfFx9f.js} +1 -1
- package/dist/{railroadDiagram-O6MQD6OU-DG-M6Rnc.js → railroadDiagram-O6MQD6OU-f-sfFoX9.js} +3 -3
- package/dist/{requirementDiagram-BXWQKSXE-DCwsThh0.js → requirementDiagram-BXWQKSXE-BICupkaf.js} +11 -11
- package/dist/{reveal-component-BYSyNNYH.js → reveal-component-CpKCz6Sm.js} +10 -10
- package/dist/{sankeyDiagram-P5KCCOFB-BdzhT0BM.js → sankeyDiagram-P5KCCOFB-Bh4EsJox.js} +1 -1
- package/dist/{select-C6plhmZr.js → select-BcObMjGz.js} +4 -4
- package/dist/{sequenceDiagram-WJ2MYXX4-CbXB1_PU.js → sequenceDiagram-WJ2MYXX4-DBFRnNGU.js} +4 -4
- package/dist/{spec-DQBRQSba.js → spec-BSchR9UD.js} +16 -14
- package/dist/{stateDiagram-D77RDMKH-A-Zf3Sb2.js → stateDiagram-D77RDMKH-CUP7QQW8.js} +13 -13
- package/dist/stateDiagram-v2-MP3YSRHH-B5mAItmH.js +30 -0
- package/dist/style.css +1 -1
- package/dist/{swimlanes-42K2YHIH-B_pMf0J4.js → swimlanes-42K2YHIH-BtIMdg7b.js} +10 -10
- package/dist/swimlanesDiagram-VR7AAH4N-CGnrrHpw.js +30 -0
- package/dist/{swiper-component-IOUowglM.js → swiper-component-DkV7T44B.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-DTXFjTTM.js → timeline-definition-24CTP7MA-UwihiSH2.js} +3 -3
- package/dist/{toDate-C67bxMWn.js → toDate-DWVp6uE1.js} +3 -3
- package/dist/{toast-DvY70eFX.js → toast-DcoJGS3-.js} +4 -4
- package/dist/{tooltip-qB8NlSqV.js → tooltip-Bi36DgYh.js} +2 -2
- package/dist/{use-restore-focus-D5D9xEjZ.js → use-restore-focus-ZgG5Br63.js} +1 -1
- package/dist/{useAsyncData-BD6AStMt.js → useAsyncData-BD7NLQ3_.js} +1 -1
- package/dist/{useDateFormatter-BXQGu86d.js → useDateFormatter-D8XWr8lL.js} +2 -2
- package/dist/{useDeepCompareMemoize-D_HNdyvI.js → useDeepCompareMemoize-CawMGSRU.js} +1 -1
- package/dist/{useIframeCapabilities-CVtNkI3Y.js → useIframeCapabilities-BUMBOpsM.js} +1 -1
- package/dist/{useLifecycle-DPgiiwwU.js → useLifecycle-3vGhRa1o.js} +3 -3
- package/dist/{useTheme-DzXmYZ5V.js → useTheme-BOw801nZ.js} +2 -2
- package/dist/{vega-component-tFOzgarw.js → vega-component-9siY74NS.js} +9 -9
- package/dist/{vennDiagram-4TSXK5OY-BPHjZo0R.js → vennDiagram-4TSXK5OY-D5LNVIRI.js} +3 -3
- package/dist/{wardleyDiagram-VM6X3IG4-6fTLYBuD.js → wardleyDiagram-VM6X3IG4-BwKf-b0_.js} +3 -3
- package/dist/{xychartDiagram-S5SC5T6Z-BYjwjrzE.js → xychartDiagram-S5SC5T6Z-Cg_vyuW2.js} +5 -5
- package/package.json +7 -7
- package/src/components/chat/tool-call/__tests__/tool-result.test.tsx +56 -0
- package/src/components/chat/tool-call/tool-result.tsx +3 -3
- package/src/components/data-table/charts/__tests__/schemas.test.ts +25 -0
- package/src/components/data-table/charts/__tests__/spec.test.ts +26 -23
- package/src/components/data-table/charts/constants.ts +11 -10
- package/src/components/data-table/charts/types.ts +1 -0
- package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +42 -0
- package/src/components/editor/actions/useNotebookActions.tsx +20 -0
- package/src/components/editor/actions/useSetOutputsExpanded.ts +67 -0
- package/src/core/edit-app.tsx +16 -0
- package/src/core/hotkeys/hotkeys.ts +12 -0
- package/src/core/wasm/__tests__/bootstrap.test.ts +33 -1
- package/src/core/wasm/worker/bootstrap.ts +22 -3
- package/src/css/katex.min.css +145 -144
- package/src/plugins/impl/CheckboxPlugin.tsx +1 -1
- package/src/plugins/impl/DatePickerPlugin.tsx +5 -3
- package/src/plugins/impl/DateRangePlugin.tsx +5 -3
- package/src/plugins/impl/DateTimePickerPlugin.tsx +5 -3
- package/src/plugins/impl/DropdownPlugin.tsx +1 -1
- package/src/plugins/impl/FileBrowserPlugin.tsx +45 -15
- package/src/plugins/impl/MultiselectPlugin.tsx +1 -1
- package/src/plugins/impl/NumberPlugin.tsx +1 -1
- package/src/plugins/impl/RadioPlugin.tsx +5 -1
- package/src/plugins/impl/RangeSliderPlugin.tsx +1 -1
- package/src/plugins/impl/SearchableSelect.tsx +1 -1
- package/src/plugins/impl/SliderPlugin.tsx +1 -1
- package/src/plugins/impl/SwitchPlugin.tsx +6 -1
- package/src/plugins/impl/__tests__/FileBrowserPlugin.test.tsx +85 -2
- package/src/plugins/impl/__tests__/widget-labels.test.tsx +122 -0
- package/src/plugins/impl/chat/ChatPlugin.tsx +1 -1
- package/src/plugins/impl/common/labeled.tsx +9 -3
- package/dist/assets/__vite-browser-external-C9iR87Zl.js +0 -1
- package/dist/classDiagram-ZZMXUADV-BiATbBE4.js +0 -30
- package/dist/classDiagram-v2-VYDZK3BY-JnH97GYw.js +0 -30
- package/dist/flowDiagram-HODETNUW-DL52nMkt.js +0 -16
- package/dist/purify.es-DgKyQviY.js +0 -805
- package/dist/stateDiagram-v2-MP3YSRHH-D9YMnUGx.js +0 -30
- package/dist/swimlanesDiagram-VR7AAH4N-Ctgy-yGP.js +0 -30
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import {
|
|
5
|
+
getNotebook,
|
|
6
|
+
type NotebookState,
|
|
7
|
+
useCellActions,
|
|
8
|
+
} from "@/core/cells/cells";
|
|
9
|
+
import type { CellId } from "@/core/cells/ids";
|
|
10
|
+
import { isOutputEmpty } from "@/core/cells/outputs";
|
|
11
|
+
import { useRequestClient } from "@/core/network/requests";
|
|
12
|
+
import type { CellConfig } from "@/core/network/types";
|
|
13
|
+
import { Objects } from "@/utils/objects";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The `expand_output` config changes needed to expand or clamp every output.
|
|
17
|
+
*
|
|
18
|
+
* Both actions skip cells without output, so their source isn't annotated
|
|
19
|
+
* with a config that has no effect.
|
|
20
|
+
*/
|
|
21
|
+
export function outputExpansionConfigs(
|
|
22
|
+
notebook: NotebookState,
|
|
23
|
+
expanded: boolean,
|
|
24
|
+
): Record<CellId, Partial<CellConfig>> {
|
|
25
|
+
const configs: Record<CellId, Partial<CellConfig>> = {};
|
|
26
|
+
for (const cellId of notebook.cellIds.inOrderIds) {
|
|
27
|
+
const cell = notebook.cellData[cellId];
|
|
28
|
+
if (
|
|
29
|
+
cell === undefined ||
|
|
30
|
+
(cell.config.expand_output ?? false) === expanded
|
|
31
|
+
) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (isOutputEmpty(notebook.cellRuntime[cellId]?.output)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
configs[cellId] = { expand_output: expanded };
|
|
38
|
+
}
|
|
39
|
+
return configs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Hook returning a callback that shows every cell's output in full, or clamps
|
|
44
|
+
* every output to a fixed height, by setting each cell's `expand_output` config.
|
|
45
|
+
*/
|
|
46
|
+
export const useSetOutputsExpanded = () => {
|
|
47
|
+
const { updateCellConfig } = useCellActions();
|
|
48
|
+
const { saveCellConfig } = useRequestClient();
|
|
49
|
+
|
|
50
|
+
return useCallback(
|
|
51
|
+
async (expanded: boolean) => {
|
|
52
|
+
const newConfigs = outputExpansionConfigs(getNotebook(), expanded);
|
|
53
|
+
|
|
54
|
+
const entries = Objects.entries(newConfigs);
|
|
55
|
+
if (entries.length === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await saveCellConfig({ configs: newConfigs });
|
|
60
|
+
|
|
61
|
+
for (const [cellId, config] of entries) {
|
|
62
|
+
updateCellConfig({ cellId, config });
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[updateCellConfig, saveCellConfig],
|
|
66
|
+
);
|
|
67
|
+
};
|
package/src/core/edit-app.tsx
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
useRunStaleCells,
|
|
24
24
|
} from "../components/editor/cell/useRunCells";
|
|
25
25
|
import { useSetCodeVisibility } from "../components/editor/actions/useSetCodeVisibility";
|
|
26
|
+
import { useSetOutputsExpanded } from "../components/editor/actions/useSetOutputsExpanded";
|
|
26
27
|
import { CellArray } from "../components/editor/renderers/cell-array";
|
|
27
28
|
import { CellsRenderer } from "../components/editor/renderers/cells-renderer";
|
|
28
29
|
import { useHotkey } from "../hooks/useHotkey";
|
|
@@ -115,6 +116,7 @@ export const EditApp: React.FC<AppProps> = ({
|
|
|
115
116
|
const runAllCells = useRunAllCells();
|
|
116
117
|
const togglePresenting = useTogglePresenting();
|
|
117
118
|
const setCodeVisibility = useSetCodeVisibility();
|
|
119
|
+
const setOutputsExpanded = useSetOutputsExpanded();
|
|
118
120
|
|
|
119
121
|
// HOTKEYS
|
|
120
122
|
useHotkey("global.runStale", () => {
|
|
@@ -141,6 +143,20 @@ export const EditApp: React.FC<AppProps> = ({
|
|
|
141
143
|
useHotkey("global.hideAllMarkdownCode", () => {
|
|
142
144
|
setCodeVisibility(true, "markdown");
|
|
143
145
|
});
|
|
146
|
+
useHotkey(
|
|
147
|
+
"global.expandAllOutputs",
|
|
148
|
+
() => {
|
|
149
|
+
setOutputsExpanded(true);
|
|
150
|
+
},
|
|
151
|
+
{ disabled: !isEditing },
|
|
152
|
+
);
|
|
153
|
+
useHotkey(
|
|
154
|
+
"global.clampAllOutputs",
|
|
155
|
+
() => {
|
|
156
|
+
setOutputsExpanded(false);
|
|
157
|
+
},
|
|
158
|
+
{ disabled: !isEditing },
|
|
159
|
+
);
|
|
144
160
|
useHotkey("global.collapseAllSections", () => {
|
|
145
161
|
collapseAllCells();
|
|
146
162
|
});
|
|
@@ -389,6 +389,18 @@ const DEFAULT_HOT_KEY = {
|
|
|
389
389
|
group: "Editing",
|
|
390
390
|
key: NOT_SET,
|
|
391
391
|
},
|
|
392
|
+
"global.expandAllOutputs": {
|
|
393
|
+
name: "Expand all outputs",
|
|
394
|
+
group: "Editing",
|
|
395
|
+
key: NOT_SET,
|
|
396
|
+
additionalKeywords: ["show full output", "unclamp"],
|
|
397
|
+
},
|
|
398
|
+
"global.clampAllOutputs": {
|
|
399
|
+
name: "Clamp all outputs",
|
|
400
|
+
group: "Editing",
|
|
401
|
+
key: NOT_SET,
|
|
402
|
+
additionalKeywords: ["collapse outputs", "shrink outputs"],
|
|
403
|
+
},
|
|
392
404
|
"global.collapseAllSections": {
|
|
393
405
|
name: "Collapse all sections",
|
|
394
406
|
group: "Editing",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { loadPyodide } from "pyodide";
|
|
4
4
|
import type { PyodideInterface } from "pyodide";
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { DefaultWasmController } from "../worker/bootstrap";
|
|
6
|
+
import { DefaultWasmController, requirementName } from "../worker/bootstrap";
|
|
7
7
|
|
|
8
8
|
vi.mock("pyodide", () => ({ loadPyodide: vi.fn() }));
|
|
9
9
|
vi.mock("../worker/getMarimoWheel", () => ({
|
|
@@ -61,3 +61,35 @@ describe("WASM runtime sources", () => {
|
|
|
61
61
|
expect(controller.requirePyodide).toBe(pyodide);
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
|
+
|
|
65
|
+
describe("requirementName", () => {
|
|
66
|
+
it("returns the distribution name for a bare requirement", () => {
|
|
67
|
+
expect(requirementName("pandas")).toBe("pandas");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it.each([
|
|
71
|
+
["pandas==2.1.0", "pandas"],
|
|
72
|
+
["pandas>=2", "pandas"],
|
|
73
|
+
["pandas<=2", "pandas"],
|
|
74
|
+
["pandas~=2.1", "pandas"],
|
|
75
|
+
["pandas!=2.0", "pandas"],
|
|
76
|
+
["nltools===0.6.0.dev2", "nltools"],
|
|
77
|
+
])("cuts the specifier off %s", (requirement, expected) => {
|
|
78
|
+
expect(requirementName(requirement)).toBe(expected);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("cuts extras and markers", () => {
|
|
82
|
+
expect(requirementName("rich[jupyter]>=13")).toBe("rich");
|
|
83
|
+
expect(requirementName('cowsay==6.1; sys_platform == "emscripten"')).toBe(
|
|
84
|
+
"cowsay",
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("cuts a URL requirement at the name", () => {
|
|
89
|
+
expect(requirementName("pkg @ https://example.com/pkg.whl")).toBe("pkg");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("tolerates surrounding whitespace", () => {
|
|
93
|
+
expect(requirementName(" pandas >= 2 ")).toBe("pandas");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -30,6 +30,17 @@ type SessionResources = [
|
|
|
30
30
|
// 3.b Install from micropip
|
|
31
31
|
// 4. Initialize the notebook
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* The distribution name of a PEP 508 requirement: "pandas>=2" -> "pandas".
|
|
35
|
+
*
|
|
36
|
+
* Extras, markers and URL forms are all cut at their first delimiter, which is
|
|
37
|
+
* enough for the "already installed" lookups this is used for.
|
|
38
|
+
*/
|
|
39
|
+
export function requirementName(requirement: string): string {
|
|
40
|
+
// Trim first: a leading space would otherwise split into an empty name.
|
|
41
|
+
return requirement.trim().split(/[[<>=!~;@\s]/)[0];
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
export class DefaultWasmController implements WasmController {
|
|
34
45
|
protected pyodide: PyodideInterface | null = null;
|
|
35
46
|
private packageLoadQueue = Promise.resolve();
|
|
@@ -314,18 +325,26 @@ export class DefaultWasmController implements WasmController {
|
|
|
314
325
|
});
|
|
315
326
|
loadSpan.end();
|
|
316
327
|
|
|
317
|
-
// Load from micropip
|
|
328
|
+
// Load from micropip.
|
|
329
|
+
//
|
|
330
|
+
// `imports` are PEP 508 requirements and may carry a version specifier
|
|
331
|
+
// ("pandas>=2", "nltools==0.6.0.dev2"). micropip wants them whole, but the
|
|
332
|
+
// "do we already have this?" checks below are keyed by name, so compare on
|
|
333
|
+
// the name and install the requirement.
|
|
318
334
|
loadSpan = t.startSpan("micropip.install");
|
|
319
335
|
const missingPackages = imports.filter(
|
|
320
|
-
(pkg) => !pyodide.loadedPackages[pkg],
|
|
336
|
+
(pkg) => !pyodide.loadedPackages[requirementName(pkg)],
|
|
321
337
|
);
|
|
322
338
|
if (missingPackages.length > 0) {
|
|
339
|
+
const byName = missingPackages.map(
|
|
340
|
+
(pkg) => [requirementName(pkg), pkg] as const,
|
|
341
|
+
);
|
|
323
342
|
await pyodide
|
|
324
343
|
.runPythonAsync(`
|
|
325
344
|
import micropip
|
|
326
345
|
import sys
|
|
327
346
|
# Filter out builtins
|
|
328
|
-
missing = [
|
|
347
|
+
missing = [req for name, req in ${JSON.stringify(byName)} if name not in sys.modules]
|
|
329
348
|
if len(missing) > 0:
|
|
330
349
|
print("Loading from micropip:", missing)
|
|
331
350
|
await micropip.install(missing)
|