25
25
assert CHANGELOGS_DIRECTORY .is_dir (), f"Changelogs directory not found: { CHANGELOGS_DIRECTORY } "
26
26
assert PORTABLE_DIRECTORY .is_dir (), f"Portable directory not found: { PORTABLE_DIRECTORY } "
27
27
28
-
29
28
def find_7zip_executable () -> str :
30
29
"""Locates the 7-Zip executable (7z.exe)."""
31
30
possible_program_files = [
@@ -38,7 +37,6 @@ def find_7zip_executable() -> str:
38
37
return str (executable_path )
39
38
raise RuntimeError ("7ZIP is not installed on this computer." )
40
39
41
-
42
40
def replace_lines_in_file (filepath : Path , replacements : list [tuple [str , str ]]):
43
41
"""
44
42
Replaces lines in a file that start with a given prefix.
@@ -98,10 +96,8 @@ def build_installer_7zip(script_template_path: Path, output_script_path: Path, r
98
96
except subprocess .CalledProcessError as e :
99
97
print (f"Error executing 7-Zip script: { e } " , file = sys .stderr )
100
98
101
-
102
99
def _copy_items (source_directories : list [Path ], target_directory : Path , verbose : bool = False ):
103
100
"""Copies items from source directories to the target directory."""
104
-
105
101
target_directory .mkdir (parents = True , exist_ok = True )
106
102
for source_dir in source_directories :
107
103
if not source_dir .is_dir ():
@@ -118,7 +114,6 @@ def _copy_items(source_directories: list[Path], target_directory: Path, verbose:
118
114
except Exception as e :
119
115
print (f"Error copying { source_item } to { target_item } : { e } " )
120
116
121
-
122
117
def _parse_list_argument (argument_value : str | list [str ], separator = " " ) -> list [str ]:
123
118
"""Parse a separated list argument into a list of strings."""
124
119
if argument_value is None :
@@ -127,7 +122,6 @@ def _parse_list_argument(argument_value: str | list[str], separator=" ") -> list
127
122
return argument_value .split (separator )
128
123
return list (argument_value )
129
124
130
-
131
125
class WinPythonDistributionBuilder :
132
126
"""Builds a WinPython distribution."""
133
127
@@ -163,19 +157,19 @@ def __init__(
163
157
"""
164
158
self .build_number = build_number
165
159
self .release_level = release_level
166
- self .target_directory = Path (target_directory ) # Ensure Path object
167
- self .wheels_directory = Path (wheels_directory ) # Ensure Path object
160
+ self .target_directory = Path (target_directory )
161
+ self .wheels_directory = Path (wheels_directory )
168
162
self .tools_directories = tools_directories or []
169
163
self .documentation_directories = documentation_directories or []
170
164
self .verbose = verbose
171
- self .winpython_directory : Path | None = None # Will be set during build
172
- self .distribution : wppm .Distribution | None = None # Will be set during build
165
+ self .winpython_directory : Path | None = None
166
+ self .distribution : wppm .Distribution | None = None
173
167
self .base_directory = base_directory
174
168
self .install_options = install_options or []
175
169
self .flavor = flavor
176
170
self .python_zip_file : Path = self ._get_python_zip_file ()
177
- self .python_name = self .python_zip_file .stem # Filename without extension
178
- self .python_directory_name = "python" # Standardized Python directory name
171
+ self .python_name = self .python_zip_file .stem
172
+ self .python_directory_name = "python"
179
173
180
174
def _get_python_zip_file (self ) -> Path :
181
175
"""Finds the Python .zip file in the wheels directory."""
@@ -263,10 +257,7 @@ def winpython_version_name(self) -> str:
263
257
264
258
@property
265
259
def python_full_version (self ) -> str :
266
- """
267
- Retrieves the Python full version string from the distribution.
268
- Will be set after _extract_python is called and distribution is initialized.
269
- """
260
+ """Retrieves the Python full version string from the distribution."""
270
261
if self .distribution is None :
271
262
return "0.0.0" # Placeholder before initialization
272
263
return utils .get_python_long_version (self .distribution .target )
@@ -286,7 +277,7 @@ def architecture_bits(self) -> int:
286
277
"""Returns the architecture (32 or 64 bits) of the distribution."""
287
278
if self .distribution :
288
279
return self .distribution .architecture
289
- return 64 # Default to 64 if distribution is not initialized yet
280
+ return 64
290
281
291
282
@property
292
283
def pre_path_entries (self ) -> list [str ]:
@@ -308,14 +299,10 @@ def documentation_directories_list(self) -> list[Path]:
308
299
return self .documentation_directories
309
300
310
301
def create_installer_7zip (self , installer_type : str = ".exe" ):
311
- """
312
- Creates a WinPython installer using 7-Zip.
313
-
314
- Args: installer_type: Type of installer to create (".exe", ".7z", ".zip").
315
- """
302
+ """Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
316
303
self ._print_action (f"Creating WinPython installer ({ installer_type } )" )
317
304
template_name = "installer_7zip.bat"
318
- output_name = "installer_7zip-tmp.bat" # temp file to avoid overwriting template
305
+ output_name = "installer_7zip-tmp.bat"
319
306
if installer_type not in [".exe" , ".7z" , ".zip" ]:
320
307
print (f"Warning: Unsupported installer type '{ installer_type } '. Defaulting to .exe" )
321
308
installer_type = ".exe"
@@ -326,14 +313,10 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
326
313
("VERSION" , f"{ self .python_full_version } .{ self .build_number } { self .flavor } " ),
327
314
("VERSION_INSTALL" , f'{ self .python_full_version .replace ("." , "" )} { self .build_number } ' ),
328
315
("RELEASELEVEL" , self .release_level ),
329
- ("INSTALLER_OPTION" , installer_type ), # Pass installer type as option to bat script
316
+ ("INSTALLER_OPTION" , installer_type ),
330
317
]
331
318
332
- build_installer_7zip (
333
- PORTABLE_DIRECTORY / template_name ,
334
- PORTABLE_DIRECTORY / output_name ,
335
- replacements
336
- )
319
+ build_installer_7zip (PORTABLE_DIRECTORY / template_name , PORTABLE_DIRECTORY / output_name , replacements )
337
320
338
321
def _print_action (self , text : str ):
339
322
"""Prints an action message with progress indicator."""
0 commit comments