99from rich .pretty import install
1010from rich .traceback import install as install_traceback
1111from pydantic import ValidationError
12- from typing import Any , cast
12+ from typing import Any , cast
1313
1414from ..__about__ import __version__
1515from ..config .app import replace_placeholders
@@ -112,7 +112,6 @@ def cli(
112112 :param env_config: Filename to a environment's TOML config file.
113113 :param kwargs: Additional keyword arguments.
114114 """
115-
116115 if ctx .invoked_subcommand is None :
117116 # If no subcommand is invoked, show the help message
118117 click .echo (10 * '-' )
@@ -127,9 +126,9 @@ def cli(
127126 context .verbose = verbose
128127 context .dry_run = dry_run
129128 context .debug = debug
130-
129+
131130 # --- PHASE 1: Load and Validate Application Config (and setup logging) ---
132-
131+ #
133132 # 1. Load the raw application config dictionary
134133 (
135134 context .appconfigfiles ,
@@ -162,7 +161,7 @@ def cli(
162161 setup_logging (cliverbosity = verbose , user_config = {'logging' : logging_config })
163162
164163 # --- PHASE 2: Load Environment Config, Validate, and Acquire Lock ---
165-
164+ #
166165 # 1. Load raw Environment Config
167166 (
168167 context .envconfigfiles ,
@@ -175,10 +174,10 @@ def cli(
175174 DEFAULT_ENV_CONFIG_FILENAME ,
176175 DEFAULT_ENV_CONFIG ,
177176 )
178-
177+
179178 # Explicitly cast the raw_envconfig type to silence Pylance
180179 raw_envconfig = cast (dict [str , Any ], raw_envconfig )
181-
180+
182181 # 2. VALIDATE the raw environment config dictionary using Pydantic
183182 try :
184183 # Pydantic validation handles placeholder replacement via @model_validator
@@ -191,14 +190,14 @@ def cli(
191190 context .envconfigfiles , e
192191 )
193192 ctx .exit (1 )
194-
193+
195194 env_config_path = context .envconfigfiles [0 ] if context .envconfigfiles else None
196-
195+
197196 # --- CONCURRENCY CONTROL: Use explicit __enter__ and cleanup registration ---
198197 if env_config_path :
199198 # 1. Instantiate the lock object
200199 ctx .obj .env_lock = PidFileLock (resource_path = env_config_path )
201-
200+
202201 try :
203202 # 2. Acquire the lock by explicitly calling the __enter__ method.
204203 ctx .obj .env_lock .__enter__ ()
@@ -212,16 +211,16 @@ def cli(
212211 # Handles critical errors
213212 log .error ("Failed to set up environment lock: %s" , e )
214213 ctx .exit (1 )
215-
214+
216215 # 3. Register the lock's __exit__ method to be called when the context terminates.
217216 # We use a lambda to supply the three mandatory positional arguments (None)
218217 # expected by __exit__, satisfying the click.call_on_close requirement.
219218 ctx .call_on_close (lambda : ctx .obj .env_lock .__exit__ (None , None , None ))
220-
219+
221220# Add subcommand
222221cli .add_command (build )
223222cli .add_command (c14n )
224223cli .add_command (config )
225224cli .add_command (repo )
226225cli .add_command (metadata )
227- cli .add_command (validate )
226+ cli .add_command (validate )
0 commit comments