4343rich .traceback .install ()
4444
4545
46+ def validate_stage_name (stage_name : str ) -> None :
47+ """
48+ Validate a stage name.
49+
50+ Ensure a stage name consists of only lowercase letters. This is
51+ both to simplify implementation details within the
52+ :class:`StagedScript` class, and to provide the best user experience
53+ for users of your :class:`StagedScript` subclasses.
54+
55+ Args:
56+ stage_name: The name of the stage.
57+
58+ Raises:
59+ ValueError: If the stage name is invalid.
60+ """
61+ if not re .match ("^[a-z]+$" , stage_name ):
62+ message = (
63+ f"Stage name { stage_name !r} must contain only lowercase letters."
64+ )
65+ raise ValueError (message )
66+
67+
4668class StagedScript :
4769 """
4870 The base class for all staged scripts.
@@ -147,7 +169,7 @@ def __init__(
147169 and optionally pass in additional arguments.
148170 """
149171 for stage in stages :
150- self . _validate_stage_name (stage )
172+ validate_stage_name (stage )
151173 self .args = Namespace ()
152174 self .commands_executed : list [str ] = []
153175 self .console = Console (
@@ -165,29 +187,6 @@ def __init__(
165187 self .stages_to_run : set [str ] = set ()
166188 self .start_time = datetime .now (tz = timezone .utc )
167189
168- @staticmethod
169- def _validate_stage_name (stage_name : str ) -> None :
170- """
171- Validate the stage name.
172-
173- Ensure the stage name consists of only lowercase letters. This
174- is both to simplify implementation details within the class, and
175- to provide the best user experience for users of your
176- :class:`StagedScript` subclasses.
177-
178- Args:
179- stage_name: The name of the stage.
180-
181- Raises:
182- ValueError: If the stage name is invalid.
183- """
184- if not re .match ("^[a-z]+$" , stage_name ):
185- message = (
186- f"Stage name { stage_name !r} must contain only lowercase "
187- "letters."
188- )
189- raise ValueError (message )
190-
191190 #
192191 # The `stage` decorator.
193192 #
@@ -245,9 +244,7 @@ def stage(stage_name: str, heading: str) -> Callable:
245244 heading: A heading message to print indicating what will
246245 happen in the stage.
247246 """
248- __class__ ._validate_stage_name ( # type: ignore[name-defined]
249- stage_name
250- )
247+ validate_stage_name (stage_name )
251248
252249 def decorator (func : Callable ) -> Callable :
253250 def get_phase_method ( # noqa: D417
0 commit comments