77import threading
88import types
99from types import FrameType
10- from typing import Any
10+ from typing import Any , Iterable
1111
1212import click
1313import watchfiles
1717from rich .table import Table
1818
1919from . import flow , lib , setting
20- from .setup import make_setup_bundle , make_drop_bundle , flow_names_with_setup
20+ from .setup import flow_names_with_setup
2121
2222# Create ServerSettings lazily upon first call, as environment variables may be loaded from files, etc.
2323COCOINDEX_HOST = "https://cocoindex.io"
@@ -244,15 +244,15 @@ def show(app_flow_specifier: str, color: bool, verbose: bool) -> None:
244244
245245
246246def _setup_flows (
247+ flow_iter : Iterable [flow .Flow ],
247248 * ,
248- flow_full_names : list [str ],
249249 force : bool ,
250250 quiet : bool = False ,
251251 always_show_setup : bool = False ,
252252) -> None :
253- setup_bundle = make_setup_bundle (flow_full_names = flow_full_names )
253+ setup_bundle = flow . make_setup_bundle (flow_iter )
254254 description , is_up_to_date = setup_bundle .describe ()
255- if always_show_setup or not ( quiet and ( force or is_up_to_date )) :
255+ if always_show_setup or not is_up_to_date :
256256 click .echo (description )
257257 if is_up_to_date :
258258 if not quiet :
@@ -285,9 +285,7 @@ def setup(app_target: str, force: bool) -> None:
285285 """
286286 app_ref = _get_app_ref_from_specifier (app_target )
287287 _load_user_app (app_ref )
288- _setup_flows (
289- flow_full_names = flow .flow_full_names (), force = force , always_show_setup = True
290- )
288+ _setup_flows (flow .flows ().values (), force = force , always_show_setup = True )
291289
292290
293291@cli .command ("drop" )
@@ -311,7 +309,6 @@ def drop(app_target: str | None, flow_name: tuple[str, ...], force: bool) -> Non
311309 2. Drop specific named flows: `cocoindex drop <APP_TARGET> [FLOW_NAME...]`
312310 """
313311 app_ref = None
314- flow_names : list [str ] = []
315312
316313 if not app_target :
317314 raise click .UsageError (
@@ -321,44 +318,39 @@ def drop(app_target: str | None, flow_name: tuple[str, ...], force: bool) -> Non
321318
322319 app_ref = _get_app_ref_from_specifier (app_target )
323320 _load_user_app (app_ref )
321+
322+ flows : Iterable [flow .Flow ]
324323 if flow_name :
325- flow_names = list (flow_name )
326- click .echo (
327- f"Preparing to drop specified flows: { ', ' .join (flow_names )} (in '{ app_ref } ')." ,
328- err = True ,
329- )
324+ flows = []
325+ for name in flow_name :
326+ try :
327+ flows .append (flow .flow_by_name (name ))
328+ except KeyError :
329+ click .echo (
330+ f"Warning: Failed to get flow `{ name } `. Ignored." ,
331+ err = True ,
332+ )
330333 else :
331- flow_names = flow .flow_names ()
332- if not flow_names :
333- click .echo (f"No flows found defined in '{ app_ref } ' to drop." )
334- return
335- click .echo (
336- f"Preparing to drop all flows defined in '{ app_ref } ': { ', ' .join (flow_names )} ." ,
337- err = True ,
338- )
334+ flows = flow .flows ().values ()
339335
340- flow_full_names = []
341- for name in flow_names :
342- try :
343- flow_full_names .append (flow .flow_by_name (name ).full_name )
344- except KeyError :
345- click .echo (
346- f"Warning: Failed to get flow `{ name } `. Ignored." ,
347- err = True ,
348- )
336+ flow_full_names = ", " .join (fl .full_name for fl in flows )
337+ click .echo (
338+ f"Preparing to drop specified flows: { flow_full_names } (in '{ app_ref } ')." ,
339+ err = True ,
340+ )
349341
350- if not flow_full_names :
342+ if not flows :
351343 click .echo ("No flows identified for the drop operation." )
352344 return
353345
354- setup_bundle = make_drop_bundle (flow_full_names = flow_full_names )
346+ setup_bundle = flow . make_drop_bundle (flows )
355347 description , is_up_to_date = setup_bundle .describe ()
356348 click .echo (description )
357349 if is_up_to_date :
358350 click .echo ("No flows need to be dropped." )
359351 return
360352 if not force and not click .confirm (
361- f"\n This will apply changes to drop setup for: { ', ' . join ( flow_full_names ) } . Continue? [yes/N]" ,
353+ f"\n This will apply changes to drop setup for: { flow_full_names } . Continue? [yes/N]" ,
362354 default = False ,
363355 show_default = False ,
364356 ):
@@ -420,19 +412,15 @@ def update(
420412 if flow_name is None :
421413 if setup :
422414 _setup_flows (
423- flow_full_names = flow .flow_full_names (),
415+ flow .flows (). values (),
424416 force = force ,
425417 quiet = quiet ,
426418 )
427419 return flow .update_all_flows (options )
428420 else :
429421 fl = flow .flow_by_name (flow_name )
430422 if setup :
431- _setup_flows (
432- flow_full_names = [fl .full_name ],
433- force = force ,
434- quiet = quiet ,
435- )
423+ _setup_flows ((fl ,), force = force , quiet = quiet )
436424 with flow .FlowLiveUpdater (fl , options ) as updater :
437425 updater .wait ()
438426 return updater .update_stats ()
0 commit comments