@@ -57,32 +57,27 @@ def __init__(
5757 self .lua_binary = lua_binary
5858 self .lua_args = lua_args or []
5959 self .lua_actual_version = None
60-
6160 # Validate required files exist
6261 if not os .path .exists (self .lua_config_script ):
6362 raise FileNotFoundError (
6463 f"Main config file not found: { self .lua_config_script } "
6564 )
66-
6765 # Initialize internal state
6866 self ._variables : Dict [str , str ] = {}
6967 self ._metadata : Dict [str , str ] = {}
70-
7168 # Initialize temporary directory
7269 self ._setup_temp_dir ()
73-
74- # Detect Lua binary
75- if not self .lua_binary :
76- self ._detect_lua_binary ()
77-
78- # Execute the Lua loader
79- self ._run_lua_loader ()
80-
81- # Parse results
82- self ._parse_results ()
83-
84- # Clean up temp directory
85- self ._cleanup ()
70+ try :
71+ # Detect Lua binary
72+ if not self .lua_binary :
73+ self ._detect_lua_binary ()
74+ # Execute the Lua loader
75+ self ._run_lua_loader ()
76+ # Parse results
77+ self ._parse_results ()
78+ finally :
79+ # Clean up temp directory
80+ self ._cleanup ()
8681
8782 def _setup_temp_dir (self ):
8883 """Setup temporary directory for storing exported variables."""
@@ -205,18 +200,15 @@ def _validate_lua_version(self, lua_binary: str) -> bool:
205200 )
206201 if not version_match :
207202 return False
208-
209203 act_version = [int (x ) for x in version_match .groups ()]
210204 min_version = [int (x ) for x in self .min_lua_version .split ("." )]
211205 max_version = [int (x ) for x in self .max_lua_version .split ("." )]
212-
213206 # Check version range
214207 for i , (act , min_v , max_v ) in enumerate (
215208 zip (act_version , min_version , max_version )
216209 ):
217210 if not (min_v <= act <= max_v ):
218211 return False
219-
220212 # Store the actual version if validation passes
221213 self .lua_actual_version = act_version
222214 return True
@@ -227,7 +219,6 @@ def _run_lua_loader(self):
227219 """Execute the Lua loader script with appropriate parameters."""
228220 # Build command line arguments
229221 cmd = [self .lua_binary , os .path .join (os .path .dirname (__file__ ), "loader.lua" )]
230-
231222 # Add version info
232223 cmd .extend (
233224 [
@@ -237,38 +228,28 @@ def _run_lua_loader(self):
237228 str (self .lua_actual_version [2 ]),
238229 ]
239230 )
240-
241231 # Add configuration parameters
242232 cmd .extend (["-c" , self .lua_config_script ])
243-
244233 # Add export variables
245234 for var in self .export_vars :
246235 cmd .extend (["-e" , var ])
247-
248236 # Add pre script
249237 if self .pre_script :
250238 cmd .extend (["-pre" , self .pre_script ])
251-
252239 # Add post script
253240 if self .post_script :
254241 cmd .extend (["-post" , self .post_script ])
255-
256242 # Add extra strings
257243 for extra in self .extra_strings :
258244 cmd .extend (["-ext" , extra ])
259-
260245 # Add work directory
261246 cmd .extend (["-w" , self .work_dir ])
262-
263247 # Add temp directory
264248 cmd .extend (["-t" , self .temp_dir ])
265-
266249 # Add -- separator
267250 cmd .append ("--" )
268-
269251 # Add additional Lua arguments
270252 cmd .extend (self .lua_args )
271-
272253 # Execute the command
273254 try :
274255 result = subprocess .run (cmd , capture_output = True , text = True , timeout = 180 )
@@ -327,7 +308,6 @@ def _parse_results(self):
327308 exports = self ._parse_text_fields (self ._index_file )
328309 meta = self ._parse_text_fields (self ._meta_file )
329310 data = self ._parse_text_fields (self ._data_file )
330-
331311 for index , value in enumerate (exports ):
332312 self ._variables [value ] = data [index ]
333313 self ._metadata [value ] = meta [index ]
0 commit comments