MCPcopy
hub / github.com/deepnote/deepnote / collectExecutableBlocks

Function collectExecutableBlocks

packages/cli/src/commands/run.ts:362–399  ·  view source on GitHub ↗

* Collect executable blocks from a DeepnoteFile. * Handles notebook and block filtering, and validates that requested blocks exist.

(
  file: DeepnoteFile,
  options: { notebook?: string; block?: string; blockIds?: string[] }
)

Source from the content-addressed store, hash-verified

360 * Handles notebook and block filtering, and validates that requested blocks exist.
361 */
362function collectExecutableBlocks(
363 file: DeepnoteFile,
364 options: { notebook?: string; block?: string; blockIds?: string[] }
365): DryRunBlockInfo[] {
366 const notebooks = getNotebooksForExecutionScope(file, options)
367 const idsToValidate = options.blockIds ?? (options.block ? [options.block] : [])
368 const blockIdFilter = options.blockIds ? new Set(options.blockIds) : options.block ? new Set([options.block]) : null
369
370 // Collect all executable blocks
371 const executableBlocks: DryRunBlockInfo[] = []
372 for (const notebook of notebooks) {
373 const sortedBlocks = [...notebook.blocks].sort((a, b) => a.sortingKey.localeCompare(b.sortingKey))
374 for (const block of sortedBlocks) {
375 if (!executableBlockTypeSet.has(block.type)) {
376 continue
377 }
378 // Skip if filtering by block IDs and this isn't in the set
379 if (blockIdFilter && !blockIdFilter.has(block.id)) {
380 continue
381 }
382 executableBlocks.push({
383 id: block.id,
384 type: block.type,
385 label: getBlockLabel(block),
386 notebook: notebook.name,
387 })
388 }
389 }
390
391 // Validate requested IDs when filtering yields no executable blocks.
392 if (executableBlocks.length === 0) {
393 for (const blockId of idsToValidate) {
394 assertExecutableBlockExists(blockId, notebooks)
395 }
396 }
397
398 return executableBlocks
399}
400
401function getNotebooksForExecutionScope(
402 file: DeepnoteFile,

Callers 1

dryRunDeepnoteProjectFunction · 0.85

Calls 3

getBlockLabelFunction · 0.90

Tested by

no test coverage detected