From 36b83edfc17327cf8caf4b79460b07b51a4a3a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20P=C3=BDrek?= Date: Mon, 3 Nov 2025 19:36:00 +0100 Subject: [PATCH] fix: init notebook execution on windows --- .../deepnoteInitNotebookRunner.node.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/notebooks/deepnote/deepnoteInitNotebookRunner.node.ts b/src/notebooks/deepnote/deepnoteInitNotebookRunner.node.ts index 55a7564ab4..ef57744621 100644 --- a/src/notebooks/deepnote/deepnoteInitNotebookRunner.node.ts +++ b/src/notebooks/deepnote/deepnoteInitNotebookRunner.node.ts @@ -14,6 +14,22 @@ import type { DeepnoteProject, DeepnoteNotebook } from '../../platform/deepnote/ import { IKernelProvider } from '../../kernels/types'; import { getDisplayPath } from '../../platform/common/platform/fs-paths'; +const DEEPNOTE_CLOUD_INIT_NOTEBOOK_BLOCK_CONTENT = `%%bash +# If your project has a 'requirements.txt' file, we'll install it here. +if test -f requirements.txt + then + pip install -r ./requirements.txt + else echo "There's no requirements.txt, so nothing to install." +fi`.trim(); + +const VSCODE_INIT_NOTEBOOK_BLOCK_CONTENT = `import os, sys, subprocess + +if os.path.exists("requirements.txt"): + print("Installing requirements.txt") + subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=False) +else: + print("There's no requirements.txt, so nothing to install.")`.trim(); + /** * Service responsible for running init notebooks before the main notebook starts. * Init notebooks typically contain setup code like pip installs. @@ -253,8 +269,20 @@ export class DeepnoteInitNotebookRunner { logger.info(`Executing init notebook block ${i + 1}/${codeBlocks.length}`); try { + // Make sure the init notebook execution works cross-platform + let blockContent = block.content ?? ''; + const isWindows = process.platform === 'win32'; + if (isWindows && blockContent.trim() === DEEPNOTE_CLOUD_INIT_NOTEBOOK_BLOCK_CONTENT) { + blockContent = VSCODE_INIT_NOTEBOOK_BLOCK_CONTENT; + logger.info( + `Replacing Deepnote Cloud init notebook block ${ + i + 1 + } content with VSCode init notebook block` + ); + } + // Execute the code silently in the background - const outputs = await kernelExecution.executeHidden(block.content ?? ''); + const outputs = await kernelExecution.executeHidden(blockContent); // Log outputs for debugging if (outputs && outputs.length > 0) {