* Run a single block by ID within an already-loaded file. * Called from handleRun when blockId is specified.
(
file: DeepnoteFile,
originalPath: string,
blockId: string,
notebookFilter: string | undefined,
pythonPath: string | undefined,
inputs: Record<string, unknown> | undefined,
options: { dryRun: boolean }
)
| 373 | * Called from handleRun when blockId is specified. |
| 374 | */ |
| 375 | async function handleRunBlock( |
| 376 | file: DeepnoteFile, |
| 377 | originalPath: string, |
| 378 | blockId: string, |
| 379 | notebookFilter: string | undefined, |
| 380 | pythonPath: string | undefined, |
| 381 | inputs: Record<string, unknown> | undefined, |
| 382 | options: { dryRun: boolean } |
| 383 | ) { |
| 384 | // Find the block |
| 385 | let targetBlock = null |
| 386 | let targetNotebook = null |
| 387 | |
| 388 | for (const notebook of file.project.notebooks) { |
| 389 | if (notebookFilter && notebook.name !== notebookFilter && notebook.id !== notebookFilter) { |
| 390 | continue |
| 391 | } |
| 392 | const block = notebook.blocks.find(b => b.id === blockId || b.id.startsWith(blockId)) |
| 393 | if (block) { |
| 394 | targetBlock = block |
| 395 | targetNotebook = notebook |
| 396 | break |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (!targetBlock || !targetNotebook) { |
| 401 | return { |
| 402 | content: [{ type: 'text', text: `Block not found: ${blockId}` }], |
| 403 | isError: true, |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (options.dryRun) { |
| 408 | return { |
| 409 | content: [ |
| 410 | { |
| 411 | type: 'text', |
| 412 | text: JSON.stringify( |
| 413 | { |
| 414 | dryRun: true, |
| 415 | level: 'block', |
| 416 | notebook: targetNotebook.name, |
| 417 | block: { |
| 418 | id: targetBlock.id.slice(0, 8), |
| 419 | fullId: targetBlock.id, |
| 420 | type: targetBlock.type, |
| 421 | }, |
| 422 | inputs: inputs || {}, |
| 423 | }, |
| 424 | null, |
| 425 | 2 |
| 426 | ), |
| 427 | }, |
| 428 | ], |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | // Run the specific block |
no test coverage detected