MCPcopy Index your code
hub / github.com/deepnote/deepnote / getDagForBlocks

Function getDagForBlocks

packages/reactivity/src/dag.ts:36–71  ·  view source on GitHub ↗
(
  blocks: DeepnoteBlock[],
  options: {
    // If true, the function will not throw an error and return partial DAG
    // this may happen when there is an error in one of the processed blocks.
    // Partial DAG should be used only in the DAG chart.
    acceptPartialDAG: boolean
    pythonInterpreter?: string
  } = { acceptPartialDAG: false }
)

Source from the content-addressed store, hash-verified

34 }
35
36export async function getDagForBlocks(
37 blocks: DeepnoteBlock[],
38 options: {
39 // If true, the function will not throw an error and return partial DAG
40 // this may happen when there is an error in one of the processed blocks.
41 // Partial DAG should be used only in the DAG chart.
42 acceptPartialDAG: boolean
43 pythonInterpreter?: string
44 } = { acceptPartialDAG: false }
45) {
46 try {
47 const blocksWithContentDeps = await getBlockDependencies(blocks, {
48 pythonInterpreter: options.pythonInterpreter,
49 })
50
51 const blocksWithErrorInContentDeps = blocksWithContentDeps.filter(block => block.error)
52 const blocksWithoutErrorsInContentDeps = blocksWithContentDeps.filter(block => !block.error)
53
54 if (blocksWithErrorInContentDeps.length > 0 && !options.acceptPartialDAG) {
55 const firstErrorBlock = blocksWithErrorInContentDeps[0]
56 if (firstErrorBlock?.error?.type === 'SyntaxError') {
57 throw new SyntaxError(firstErrorBlock.error.message)
58 }
59 }
60
61 const allBlocksForDAG = options.acceptPartialDAG ? blocksWithContentDeps : blocksWithoutErrorsInContentDeps
62 const dag = buildDagFromBlocks(allBlocksForDAG)
63 return { dag, blocksWithErrorInContentDeps, newlyComputedBlocksContentDeps: blocksWithContentDeps }
64 } catch (error) {
65 if (error instanceof SyntaxError) {
66 throw error
67 }
68
69 throw new DagError(error instanceof Error ? error.message : String(error))
70 }
71}
72
73/**
74 * Takes blocks, creates DAG and returns blocks that should be executed based in blocksToExecute for downstream execution.

Callers 5

dag.test.tsFile · 0.90
checkForIssuesFunction · 0.90
analyzeDagFunction · 0.90
getDownstreamBlocksFunction · 0.85
getUpstreamBlocksFunction · 0.85

Calls 2

getBlockDependenciesFunction · 0.90
buildDagFromBlocksFunction · 0.90

Tested by

no test coverage detected