@@ -48,6 +48,7 @@ def __init__(self,
4848 origin_paths_for_cache : Optional [List [pathlib .Path ]],
4949 code_defaults : Optional [Dict ],
5050 session_defaults : Optional [Dict ],
51+ only_code_output : bool ,
5152 progress : Progress ):
5253 self .code_chunks = code_chunks
5354 self .cross_origin_sessions = cross_origin_sessions
@@ -62,6 +63,7 @@ def __init__(self,
6263 self ._origin_paths_for_cache_as_strings = [p .as_posix () for p in origin_paths_for_cache ]
6364 self .code_defaults = code_defaults
6465 self .session_defaults = session_defaults
66+ self ._only_code_output = only_code_output
6567 self ._progress = progress
6668
6769 self ._old_cache_index : Optional [Dict ] = None
@@ -90,7 +92,7 @@ def exit_code(self) -> int:
9092 if any (s .status .prevent_exec for s in self ._sessions .values ()):
9193 code ^= 0b00000100
9294 if (any (s .status .has_errors and not s .status .prevent_exec for s in self ._sessions .values ()) or
93- any (s .status .has_errors and not s . status . prevent_exec for s in self ._sources .values ())):
95+ any (s .status .has_errors for s in self ._sources .values ())):
9496 code ^= 0b00001000
9597 if any (s .status .has_warnings for s in self ._sessions .values ()):
9698 code ^= 0b00010000
@@ -110,6 +112,9 @@ def process(self):
110112 self ._resolve_code_copying ()
111113 self ._create_sessions_and_sources ()
112114 self ._prep_cache ()
115+ if self ._only_code_output and self ._cached_sessions :
116+ # Resolve output copying as early as possible
117+ self ._resolve_output_copying (from_cache = True )
113118
114119
115120 def exec (self ):
@@ -181,6 +186,7 @@ def _set_chunk_keys(self):
181186 '''
182187 Assign code chunk session/source keys.
183188 '''
189+ placeholder_lang_num = 0
184190 for cc in self .code_chunks :
185191 if cc .execute :
186192 if self .cross_origin_sessions :
@@ -193,6 +199,9 @@ def _set_chunk_keys(self):
193199 else :
194200 key = CodeKey (cc .options ['lang' ], cc .options ['source' ], 'source' , cc .origin_name )
195201 cc .key = key
202+ if cc .options ['inherited_lang' ]:
203+ cc .options ['placeholder_lang' ] = f'{ placeholder_lang_num } _placeholder'
204+ placeholder_lang_num += 1
196205
197206
198207 def _index_named_code_chunks (self ):
@@ -292,7 +301,7 @@ def _resolve_code_copying(self):
292301 unresolved_chunks = still_unresolved_chunks
293302 still_unresolved_chunks = []
294303
295- def _resolve_output_copying (self ):
304+ def _resolve_output_copying (self , * , from_cache : bool = False ):
296305 '''
297306 For code chunks with copying, handle the output copying. The output
298307 copying for commands like "paste" must be handled after code is
@@ -303,11 +312,11 @@ def _resolve_output_copying(self):
303312 # dependencies; that's already been handled in
304313 # `_resolve_code_copying()`. Still need to check for errors that
305314 # prevent copying, since there can be runtime source errors or other
306- # errors related to output. Code chunks with `.has_output == True`
307- # are copying code-only code chunks and thus have no output for
308- # copying.
315+ # errors related to output. Code chunks with
316+ # `.needs_to_copy == False` are copying code-only code chunks and thus
317+ # have no output for copying.
309318 unresolved_chunks = [cc for cc in self .code_chunks
310- if cc .command == 'paste' and not cc .errors .prevent_exec and not cc .has_output ]
319+ if cc .command == 'paste' and not cc .errors .prevent_exec and cc .needs_to_copy ]
311320 still_unresolved_chunks = []
312321 while True :
313322 for cc in unresolved_chunks :
@@ -322,11 +331,13 @@ def _resolve_output_copying(self):
322331 traceback = '\n ' .join (traceback_list )
323332 msg = f'Code chunk(s) have error(s) that prevent copying:\n { traceback } '
324333 cc .errors .append (message .SourceError (msg ))
325- elif any (not copied_cc .has_output for copied_cc in cc .copy_chunks ):
334+ self ._progress .source_chunk_complete (cc .source , chunk = cc )
335+ elif any (copied_cc .needs_to_copy for copied_cc in cc .copy_chunks ):
326336 still_unresolved_chunks .append (cc )
327337 else :
328338 cc .copy_output ()
329- if not still_unresolved_chunks :
339+ self ._progress .source_chunk_complete (cc .source , chunk = cc )
340+ if not still_unresolved_chunks or (from_cache and len (unresolved_chunks ) == len (still_unresolved_chunks )):
330341 break
331342 unresolved_chunks = still_unresolved_chunks
332343 still_unresolved_chunks = []
@@ -347,6 +358,9 @@ def _create_sessions_and_sources(self):
347358 self ._session_hash_root_sets [session .hash_root ].add (session )
348359 for source in self ._sources .values ():
349360 source .finalize ()
361+ for cc in source .code_chunks :
362+ if not cc .needs_to_copy or cc .errors .prevent_exec :
363+ self ._progress .source_chunk_complete (cc .source , chunk = cc )
350364 self ._progress .register_sessions (self ._sessions .values ())
351365 self ._progress .register_sources (self ._sources .values ())
352366
0 commit comments