1- from typing import Any , Dict , List , Union
1+ from typing import Any , Dict , List , Optional , Union
22
33from rich .markup import escape
44from rich .table import Table
2424from dstack .api import Run
2525
2626
27- def print_run_plan (run_plan : RunPlan , offers_limit : int = 3 ):
27+ def print_run_plan (
28+ run_plan : RunPlan , max_offers : Optional [int ] = None , include_run_properties : bool = True
29+ ):
2830 job_plan = run_plan .job_plans [0 ]
2931
3032 props = Table (box = None , show_header = False )
@@ -39,29 +41,30 @@ def print_run_plan(run_plan: RunPlan, offers_limit: int = 3):
3941 if job_plan .job_spec .max_duration
4042 else "-"
4143 )
42- inactivity_duration = None
43- if isinstance (run_plan .run_spec .configuration , DevEnvironmentConfiguration ):
44- inactivity_duration = "-"
45- if isinstance (run_plan .run_spec .configuration .inactivity_duration , int ):
46- inactivity_duration = format_pretty_duration (
47- run_plan .run_spec .configuration .inactivity_duration
48- )
49- if job_plan .job_spec .retry is None :
50- retry = "-"
51- else :
52- retry = escape (job_plan .job_spec .retry .pretty_format ())
53-
54- profile = run_plan .run_spec .merged_profile
55- creation_policy = profile .creation_policy
56- # FIXME: This assumes the default idle_duration is the same for client and server.
57- # If the server changes idle_duration, old clients will see incorrect value.
58- termination_policy , termination_idle_time = get_termination (
59- profile , DEFAULT_RUN_TERMINATION_IDLE_TIME
60- )
61- if termination_policy == TerminationPolicy .DONT_DESTROY :
62- idle_duration = "-"
63- else :
64- idle_duration = format_pretty_duration (termination_idle_time )
44+ if include_run_properties :
45+ inactivity_duration = None
46+ if isinstance (run_plan .run_spec .configuration , DevEnvironmentConfiguration ):
47+ inactivity_duration = "-"
48+ if isinstance (run_plan .run_spec .configuration .inactivity_duration , int ):
49+ inactivity_duration = format_pretty_duration (
50+ run_plan .run_spec .configuration .inactivity_duration
51+ )
52+ if job_plan .job_spec .retry is None :
53+ retry = "-"
54+ else :
55+ retry = escape (job_plan .job_spec .retry .pretty_format ())
56+
57+ profile = run_plan .run_spec .merged_profile
58+ creation_policy = profile .creation_policy
59+ # FIXME: This assumes the default idle_duration is the same for client and server.
60+ # If the server changes idle_duration, old clients will see incorrect value.
61+ termination_policy , termination_idle_time = get_termination (
62+ profile , DEFAULT_RUN_TERMINATION_IDLE_TIME
63+ )
64+ if termination_policy == TerminationPolicy .DONT_DESTROY :
65+ idle_duration = "-"
66+ else :
67+ idle_duration = format_pretty_duration (termination_idle_time )
6568
6669 if req .spot is None :
6770 spot_policy = "auto"
@@ -75,30 +78,32 @@ def th(s: str) -> str:
7578
7679 props .add_row (th ("Project" ), run_plan .project_name )
7780 props .add_row (th ("User" ), run_plan .user )
78- props .add_row (th ("Configuration" ), run_plan .run_spec .configuration_path )
79- props .add_row (th ("Type" ), run_plan .run_spec .configuration .type )
81+ if include_run_properties :
82+ props .add_row (th ("Configuration" ), run_plan .run_spec .configuration_path )
83+ props .add_row (th ("Type" ), run_plan .run_spec .configuration .type )
8084 props .add_row (th ("Resources" ), pretty_req )
81- props .add_row (th ("Max price" ), max_price )
82- props .add_row (th ("Max duration" ), max_duration )
83- if inactivity_duration is not None : # None means n/a
84- props .add_row (th ("Inactivity duration" ), inactivity_duration )
8585 props .add_row (th ("Spot policy" ), spot_policy )
86- props .add_row (th ("Retry policy" ), retry )
87- props .add_row (th ("Creation policy" ), creation_policy )
88- props .add_row (th ("Idle duration" ), idle_duration )
86+ props .add_row (th ("Max price" ), max_price )
87+ if include_run_properties :
88+ props .add_row (th ("Retry policy" ), retry )
89+ props .add_row (th ("Creation policy" ), creation_policy )
90+ props .add_row (th ("Idle duration" ), idle_duration )
91+ props .add_row (th ("Max duration" ), max_duration )
92+ if inactivity_duration is not None : # None means n/a
93+ props .add_row (th ("Inactivity duration" ), inactivity_duration )
8994 props .add_row (th ("Reservation" ), run_plan .run_spec .configuration .reservation or "-" )
9095
9196 offers = Table (box = None )
9297 offers .add_column ("#" )
9398 offers .add_column ("BACKEND" )
9499 offers .add_column ("REGION" )
95- offers .add_column ("INSTANCE" )
100+ offers .add_column ("INSTANCE TYPE " )
96101 offers .add_column ("RESOURCES" )
97102 offers .add_column ("SPOT" )
98103 offers .add_column ("PRICE" )
99104 offers .add_column ()
100105
101- job_plan .offers = job_plan .offers [:offers_limit ]
106+ job_plan .offers = job_plan .offers [:max_offers ] if max_offers else job_plan . offers
102107
103108 for i , offer in enumerate (job_plan .offers , start = 1 ):
104109 r = offer .instance .resources
0 commit comments