43
43
rich .traceback .install ()
44
44
45
45
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
+
46
68
class StagedScript :
47
69
"""
48
70
The base class for all staged scripts.
@@ -147,7 +169,7 @@ def __init__(
147
169
and optionally pass in additional arguments.
148
170
"""
149
171
for stage in stages :
150
- self . _validate_stage_name (stage )
172
+ validate_stage_name (stage )
151
173
self .args = Namespace ()
152
174
self .commands_executed : list [str ] = []
153
175
self .console = Console (
@@ -165,29 +187,6 @@ def __init__(
165
187
self .stages_to_run : set [str ] = set ()
166
188
self .start_time = datetime .now (tz = timezone .utc )
167
189
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
-
191
190
#
192
191
# The `stage` decorator.
193
192
#
@@ -245,9 +244,7 @@ def stage(stage_name: str, heading: str) -> Callable:
245
244
heading: A heading message to print indicating what will
246
245
happen in the stage.
247
246
"""
248
- __class__ ._validate_stage_name ( # type: ignore[name-defined]
249
- stage_name
250
- )
247
+ validate_stage_name (stage_name )
251
248
252
249
def decorator (func : Callable ) -> Callable :
253
250
def get_phase_method ( # noqa: D417
0 commit comments