@@ -14,6 +14,22 @@ import type { DeepnoteProject, DeepnoteNotebook } from '../../platform/deepnote/
1414import { IKernelProvider } from '../../kernels/types' ;
1515import { getDisplayPath } from '../../platform/common/platform/fs-paths' ;
1616
17+ const DEEPNOTE_CLOUD_INIT_NOTEBOOK_BLOCK_CONTENT = `%%bash
18+ # If your project has a 'requirements.txt' file, we'll install it here.
19+ if test -f requirements.txt
20+ then
21+ pip install -r ./requirements.txt
22+ else echo "There's no requirements.txt, so nothing to install."
23+ fi` . trim ( ) ;
24+
25+ const VSCODE_INIT_NOTEBOOK_BLOCK_CONTENT = `import os, sys, subprocess
26+
27+ if os.path.exists("requirements.txt"):
28+ print("Installing requirements.txt")
29+ subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=False)
30+ else:
31+ print("There's no requirements.txt, so nothing to install.")` . trim ( ) ;
32+
1733/**
1834 * Service responsible for running init notebooks before the main notebook starts.
1935 * Init notebooks typically contain setup code like pip installs.
@@ -253,8 +269,20 @@ export class DeepnoteInitNotebookRunner {
253269 logger . info ( `Executing init notebook block ${ i + 1 } /${ codeBlocks . length } ` ) ;
254270
255271 try {
272+ // Make sure the init notebook execution works cross-platform
273+ let blockContent = block . content ?? '' ;
274+ const isWindows = process . platform === 'win32' ;
275+ if ( isWindows && blockContent . trim ( ) === DEEPNOTE_CLOUD_INIT_NOTEBOOK_BLOCK_CONTENT ) {
276+ blockContent = VSCODE_INIT_NOTEBOOK_BLOCK_CONTENT ;
277+ logger . info (
278+ `Replacing Deepnote Cloud init notebook block ${
279+ i + 1
280+ } content with VSCode init notebook block`
281+ ) ;
282+ }
283+
256284 // Execute the code silently in the background
257- const outputs = await kernelExecution . executeHidden ( block . content ?? '' ) ;
285+ const outputs = await kernelExecution . executeHidden ( blockContent ) ;
258286
259287 // Log outputs for debugging
260288 if ( outputs && outputs . length > 0 ) {
0 commit comments