@@ -46,14 +46,13 @@ def build_installer_7zip(script_template_path: Path, output_script_path: Path, r
46
46
("PORTABLE_DIR=" , f"PORTABLE_DIR={ PORTABLE_DIRECTORY } & rem " ),
47
47
("SEVENZIP_EXE=" , f"SEVENZIP_EXE={ find_7zip_executable ()} & rem " ),
48
48
] + [(f"{ a } =" , f"{ a } ={ b } & rem " ) for a , b in replacements ]
49
-
49
+
50
50
utils .replace_in_file (script_template_path , data_to_replace , output_script_path )
51
51
52
52
try :
53
53
# Execute the generated 7-Zip script, with stdout=sys.stderr to see 7zip compressing
54
- command = f'"{ output_script_path } "'
55
- print (f"Executing 7-Zip script: { command } " )
56
- subprocess .run (command , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr )
54
+ print (f'Executing 7-Zip script: "{ output_script_path } "' )
55
+ subprocess .run (f'"{ output_script_path } "' , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr )
57
56
except subprocess .CalledProcessError as e :
58
57
print (f"Error executing 7-Zip script: { e } " , file = sys .stderr )
59
58
@@ -76,11 +75,9 @@ def copy_items(source_directories: list[Path], target_directory: Path, verbose:
76
75
77
76
def parse_list_argument (argument_value : str | list [str ], separator = " " ) -> list [str ]:
78
77
"""Parse a separated list argument into a list of strings."""
79
- if argument_value is None :
78
+ if not argument_value :
80
79
return []
81
- if isinstance (argument_value , str ):
82
- return argument_value .split (separator )
83
- return list (argument_value )
80
+ return argument_value .split (separator ) if isinstance (argument_value , str ) else list (argument_value )
84
81
85
82
class WinPythonDistributionBuilder :
86
83
"""Builds a WinPython distribution."""
@@ -163,20 +160,17 @@ def _get_installed_tools_markdown(self) -> str:
163
160
164
161
def get_tool_path (relative_path ):
165
162
path = self .winpython_directory / relative_path if self .winpython_directory else None
166
- return path if path and ( path .is_file () or path . is_dir () ) else None
163
+ return path if path and path .exists ( ) else None
167
164
168
165
if nodejs_path := get_tool_path (self .NODEJS_RELATIVE_PATH ):
169
- node_version = utils .get_nodejs_version (nodejs_path )
170
- npm_version = utils .get_npmjs_version (nodejs_path )
171
- installed_tools += [("Nodejs" , node_version ), ("npmjs" , npm_version )]
166
+ installed_tools .append (("Nodejs" , utils .get_nodejs_version (nodejs_path )))
167
+ installed_tools .append (("npmjs" , utils .get_npmjs_version (nodejs_path )))
172
168
173
- if pandoc_executable := get_tool_path ("t/pandoc.exe" ):
174
- pandoc_version = utils .get_pandoc_version (str (pandoc_executable .parent ))
175
- installed_tools .append (("Pandoc" , pandoc_version ))
169
+ if pandoc_exe := get_tool_path ("t/pandoc.exe" ):
170
+ installed_tools .append (("Pandoc" , utils .get_pandoc_version (str (pandoc_exe .parent ))))
176
171
177
- if vscode_executable := get_tool_path ("t/VSCode/Code.exe" ):
178
- vscode_version = utils .getFileProperties (str (vscode_executable ))["FileVersion" ]
179
- installed_tools .append (("VSCode" , vscode_version ))
172
+ if vscode_exe := get_tool_path ("t/VSCode/Code.exe" ):
173
+ installed_tools .append (("VSCode" , utils .getFileProperties (str (vscode_exe ))["FileVersion" ]))
180
174
181
175
tool_lines = []
182
176
for name , version in installed_tools :
@@ -187,7 +181,7 @@ def get_tool_path(relative_path):
187
181
188
182
def _get_installed_packages_markdown (self ) -> str :
189
183
"""Generates Markdown for installed packages section in package index."""
190
- if self .distribution is None :
184
+ if not self .distribution :
191
185
return "" # Distribution not initialized yet.
192
186
self .installed_packages = self .distribution .get_installed_packages (update = True )
193
187
package_lines = [
@@ -204,25 +198,20 @@ def winpython_version_name(self) -> str:
204
198
@property
205
199
def python_full_version (self ) -> str :
206
200
"""Retrieves the Python full version string from the distribution."""
207
- if self .distribution is None :
208
- return "0.0.0" # Placeholder before initialization
209
- return utils .get_python_long_version (self .distribution .target )
201
+ return utils .get_python_long_version (self .distribution .target ) if self .distribution else "0.0.0"
210
202
211
203
@property
212
204
def python_executable_directory (self ) -> str :
213
205
"""Returns the directory containing the Python executable."""
214
- python_path_directory = self .winpython_directory / self .python_directory_name if self .winpython_directory else None
215
- if python_path_directory and python_path_directory .is_dir ():
216
- return str (python_path_directory )
217
- python_path_executable = self .winpython_directory / self .python_name if self .winpython_directory else None
218
- return str (python_path_executable ) if python_path_executable else ""
206
+ if self .winpython_directory :
207
+ python_path_directory = self .winpython_directory / self .python_directory_name
208
+ return str (python_path_directory ) if python_path_directory .is_dir () else str (self .winpython_directory / self .python_name )
209
+ return ""
219
210
220
211
@property
221
212
def architecture_bits (self ) -> int :
222
213
"""Returns the architecture (32 or 64 bits) of the distribution."""
223
- if self .distribution :
224
- return self .distribution .architecture
225
- return 64
214
+ return self .distribution .architecture if self .distribution else 64
226
215
227
216
def create_installer_7zip (self , installer_type : str = ".exe" ):
228
217
"""Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
@@ -241,7 +230,6 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
241
230
("RELEASELEVEL" , self .release_level ),
242
231
("INSTALLER_OPTION" , installer_type ),
243
232
]
244
-
245
233
build_installer_7zip (PORTABLE_DIRECTORY / template_name , self .target_directory / output_name , replacements )
246
234
247
235
def _print_action (self , text : str ):
@@ -351,9 +339,9 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam
351
339
352
340
def rebuild_winpython_package (source_directory : Path , target_directory : Path , architecture : int = 64 , verbose : bool = False ):
353
341
"""Rebuilds the winpython package from source using flit."""
354
- for filename in os . listdir ( target_directory ):
355
- if filename . startswith ( "winpython-" ) and filename . endswith (( ".exe" , ".whl" , ".gz" ) ):
356
- os . remove ( Path ( target_directory ) / filename )
342
+ for file in target_directory . glob ( "winpython-*" ):
343
+ if file . suffix in ( ".exe" , ".whl" , ".gz" ):
344
+ file . unlink ( )
357
345
utils .buildflit_wininst (source_directory , copy_to = target_directory , verbose = verbose )
358
346
359
347
def make_all (build_number : int , release_level : str , pyver : str , architecture : int , basedir : Path ,
@@ -391,14 +379,14 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
391
379
find_links_dirs_list = parse_list_argument (find_links , "," )
392
380
requirements_files_list = [Path (f ) for f in parse_list_argument (requirements , "," ) if f ]
393
381
find_links_options = [f"--find-links={ link } " for link in find_links_dirs_list + [source_dirs ]]
394
- build_directory = str ( Path (basedir ) / ("bu" + flavor ) )
382
+ build_directory = Path (basedir ) / ("bu" + flavor )
395
383
396
384
if rebuild :
397
385
utils .print_box (f"Making WinPython { architecture } bits at { Path (basedir ) / ('bu' + flavor )} " )
398
- os .makedirs (Path ( build_directory ) , exist_ok = True )
386
+ os .makedirs (build_directory , exist_ok = True )
399
387
# use source_dirs as the directory to re-build Winpython wheel
400
388
winpython_source_dir = Path (__file__ ).resolve ().parent
401
- rebuild_winpython_package (winpython_source_dir , source_dirs , architecture , verbose )
389
+ rebuild_winpython_package (winpython_source_dir , Path ( source_dirs ) , architecture , verbose )
402
390
403
391
builder = WinPythonDistributionBuilder (
404
392
build_number , release_level , build_directory , wheels_directory = source_dirs ,
@@ -420,11 +408,11 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
420
408
421
409
builder .build (rebuild = rebuild , requirements_files_list = requirements_files_list , winpy_dirname = winpython_dirname )
422
410
423
- if ".zip" in str ( create_installer ) .lower ():
411
+ if ".zip" in create_installer .lower ():
424
412
builder .create_installer_7zip (".zip" )
425
- if ".7z" in str ( create_installer ) .lower ():
413
+ if ".7z" in create_installer .lower ():
426
414
builder .create_installer_7zip (".7z" )
427
- if "7zip" in str ( create_installer ) .lower ():
415
+ if "7zip" in create_installer .lower ():
428
416
builder .create_installer_7zip (".exe" )
429
417
430
418
if __name__ == "__main__" :
0 commit comments