MCPcopy
hub / github.com/deepnote/deepnote / resolveUpstreamExecutionBlockIds

Function resolveUpstreamExecutionBlockIds

packages/cli/src/commands/run.ts:443–488  ·  view source on GitHub ↗
(
  file: DeepnoteFile,
  options: { notebook?: string; block?: string },
  pythonInterpreter: string
)

Source from the content-addressed store, hash-verified

441}
442
443async function resolveUpstreamExecutionBlockIds(
444 file: DeepnoteFile,
445 options: { notebook?: string; block?: string },
446 pythonInterpreter: string
447): Promise<string[] | undefined> {
448 if (!options.block) {
449 return undefined
450 }
451
452 const notebooks = getNotebooksForExecutionScope(file, options)
453
454 // If notebook is not specified, scope DAG analysis to the notebook containing the target block.
455 const scopeNotebooks = selectScopeNotebooks(notebooks, options)
456
457 const allBlocks = scopeNotebooks.flatMap(notebook => notebook.blocks)
458 if (allBlocks.length === 0) {
459 return undefined
460 }
461
462 const blocksToExecute = allBlocks.filter(block => block.id === options.block)
463 const upstreamResult = await getUpstreamBlocks(allBlocks, blocksToExecute, {
464 pythonInterpreter,
465 })
466
467 if (upstreamResult.status === 'fatal') {
468 debug(`DAG analysis failed with fatal error, running single block without deps: ${upstreamResult.error.message}`)
469 return undefined
470 }
471
472 if (upstreamResult.status === 'missing-deps') {
473 const depsWithErrors = upstreamResult.newlyComputedBlocksContentDeps.filter(block => block.error)
474 if (depsWithErrors.length > 0) {
475 debug(`DAG analysis found ${depsWithErrors.length} blocks with dependency errors, using partial DAG`)
476 }
477 }
478
479 const upstreamIds = upstreamResult.blocksToExecuteWithDeps
480 .filter(block => block.id !== options.block)
481 .map(block => block.id)
482 if (upstreamIds.length === 0) {
483 return undefined
484 }
485 const blockIds = [...new Set([...upstreamIds, options.block])]
486 debug(`Block ${options.block} has ${upstreamIds.length} upstream dependencies: ${upstreamIds.join(', ')}`)
487 return blockIds
488}
489
490export function createRunAction(program: Command): (path: string | undefined, options: RunOptions) => Promise<void> {
491 return async (path, options) => {

Callers 2

dryRunDeepnoteProjectFunction · 0.85
runDeepnoteProjectFunction · 0.85

Calls 4

getUpstreamBlocksFunction · 0.90
debugFunction · 0.90
selectScopeNotebooksFunction · 0.85

Tested by

no test coverage detected