24
24
from datetime import datetime , timedelta , timezone
25
25
from pathlib import Path
26
26
from subprocess import CompletedProcess
27
- from typing import Callable , NamedTuple
27
+ from typing import Callable , Dict , List , NamedTuple , Optional , Set
28
28
29
29
import __main__
30
30
import rich .traceback
@@ -122,14 +122,14 @@ class StagedScript:
122
122
Attributes:
123
123
args (Namespace): The parsed command line arguments for the
124
124
script.
125
- commands_executed (list [str]): The commands that were executed
125
+ commands_executed (List [str]): The commands that were executed
126
126
in the shell.
127
127
console (Console): Used to print rich text to the console.
128
128
current_stage (str): The name of the stage being run.
129
129
dry_run (bool): If ``True``, don't actually run the command
130
130
that would be executed in the shell; instead just print it
131
131
out.
132
- durations (list [StageDuration]): A mapping from stage names to
132
+ durations (List [StageDuration]): A mapping from stage names to
133
133
how long it took for each to run. This is implemented as a
134
134
``list`` of named tuples instead of as a ``dict`` to allow
135
135
the flexibility for stages to be run multiple times.
@@ -145,12 +145,12 @@ class StagedScript:
145
145
script_success (bool): Subclass developers can toggle this
146
146
attribute to indicate whether the script has succeeded.
147
147
stage_start_time (datetime): The time at which a stage began.
148
- stages (set [str]): The stages registered for an instantiation
148
+ stages (Set [str]): The stages registered for an instantiation
149
149
of a :class:`StagedScript` subclass, which are used to
150
150
automatically populate pieces of the
151
151
:class:`ArgumentParser`. This may be a subset of all the
152
152
stages defined in the subclass.
153
- stages_to_run (set [str]): Which stages to run, as specified by
153
+ stages_to_run (Set [str]): Which stages to run, as specified by
154
154
the user via the command line arguments.
155
155
start_time (datetime): The time at which this object was
156
156
initialized.
@@ -176,9 +176,9 @@ class StagedScript:
176
176
177
177
def __init__ (
178
178
self ,
179
- stages : set [str ],
179
+ stages : Set [str ],
180
180
* ,
181
- console_force_terminal : bool | None = None ,
181
+ console_force_terminal : Optional [ bool ] = None ,
182
182
console_log_path : bool = True ,
183
183
print_commands : bool = True ,
184
184
):
@@ -207,20 +207,20 @@ def __init__(
207
207
for stage in stages :
208
208
self ._validate_stage_name (stage )
209
209
self .args = Namespace ()
210
- self .commands_executed : list [str ] = []
210
+ self .commands_executed : List [str ] = []
211
211
self .console = Console (
212
212
force_terminal = console_force_terminal , log_path = console_log_path
213
213
)
214
214
self .current_stage = "CURRENT STAGE NOT SET"
215
215
self .dry_run = False
216
- self .durations : list [StageDuration ] = []
216
+ self .durations : List [StageDuration ] = []
217
217
self .print_commands = print_commands
218
218
self .script_name = Path (__main__ .__file__ ).name
219
219
self .script_stem = Path (__main__ .__file__ ).stem
220
220
self .script_success = True
221
221
self .stage_start_time = datetime .now (tz = timezone .utc )
222
222
self .stages = stages
223
- self .stages_to_run : set [str ] = set ()
223
+ self .stages_to_run : Set [str ] = set ()
224
224
self .start_time = datetime .now (tz = timezone .utc )
225
225
226
226
@staticmethod
@@ -364,7 +364,7 @@ def parser(self) -> ArgumentParser:
364
364
setattr (self , f"{ stage } _retry_timeout_arg" , retry_timeout )
365
365
return ap
366
366
367
- def parse_args (self , argv : list [str ]) -> None :
367
+ def parse_args (self , argv : List [str ]) -> None :
368
368
"""
369
369
Parse the command line arguments.
370
370
@@ -376,7 +376,7 @@ def parse_args(self, argv: list[str]) -> None:
376
376
377
377
.. code-block:: python
378
378
379
- def parse_args(self, argv: list [str]) -> None:
379
+ def parse_args(self, argv: List [str]) -> None:
380
380
super().parse_args(argv)
381
381
# Parse additional arguments and store as attributes.
382
382
self.foo = self.args.foo
@@ -912,7 +912,7 @@ def print_heading(self, message: str, *, color: str = "cyan") -> None:
912
912
self .console .log (Panel (f"[bold]{ message } " , style = color ))
913
913
914
914
def print_script_execution_summary (
915
- self , extra_sections : dict [ str , str ] | None = None
915
+ self , extra_sections : Optional [ Dict [ str , str ]] = None
916
916
) -> None :
917
917
"""
918
918
Print a summary of everything that was done by the script.
@@ -934,11 +934,11 @@ def print_script_execution_summary(
934
934
935
935
def print_script_execution_summary(
936
936
self,
937
- extra_sections: dict[ str, str] | None = None
937
+ extra_sections: Optional[Dict[ str, str]] = None
938
938
) -> None:
939
939
extras = {"Additional section": "With some details."}
940
940
if extra_sections is not None:
941
- extras |= extra_sections
941
+ extras.update( extra_sections)
942
942
super().print_script_execution_summary(
943
943
extra_sections=extras
944
944
)
@@ -955,7 +955,7 @@ def print_script_execution_summary(
955
955
),
956
956
}
957
957
if extra_sections is not None :
958
- sections |= extra_sections
958
+ sections . update ( extra_sections )
959
959
items = ["" ]
960
960
for section , details in sections .items ():
961
961
items .extend ([f"➤ { section } :" , Padding (details , (1 , 0 , 1 , 4 ))])
@@ -969,7 +969,7 @@ def run(
969
969
command : str ,
970
970
* ,
971
971
pretty_print : bool = False ,
972
- print_command : bool | None = None ,
972
+ print_command : Optional [ bool ] = None ,
973
973
** kwargs ,
974
974
) -> CompletedProcess :
975
975
"""
@@ -1028,7 +1028,7 @@ def _get_timing_report(self) -> Table:
1028
1028
return table
1029
1029
1030
1030
@staticmethod
1031
- def _current_arg_is_long_flag (args : list [str ]) -> bool :
1031
+ def _current_arg_is_long_flag (args : List [str ]) -> bool :
1032
1032
"""
1033
1033
Determine if the first argument in the list is a long flag.
1034
1034
@@ -1041,7 +1041,7 @@ def _current_arg_is_long_flag(args: list[str]) -> bool:
1041
1041
return len (args ) > 0 and args [0 ].startswith ("--" )
1042
1042
1043
1043
@staticmethod
1044
- def _next_arg_is_flag (args : list [str ]) -> bool :
1044
+ def _next_arg_is_flag (args : List [str ]) -> bool :
1045
1045
"""
1046
1046
Determine if the second argument in the list is a flag.
1047
1047
0 commit comments