@@ -31,13 +31,12 @@ def find_7zip_executable() -> str:
31
31
possible_program_files = [
32
32
Path (r"C:\Program Files" ),
33
33
Path (r"C:\Program Files (x86)" ),
34
- Path (sys .prefix ).parent . parent / "7-Zip" ,
34
+ Path (sys .prefix ).parent / "t" ,
35
35
]
36
36
for base_dir in possible_program_files :
37
- for subdir in ["." , "App" ]:
38
- executable_path = base_dir / subdir / "7-Zip" / "7z.exe"
39
- if executable_path .is_file ():
40
- return str (executable_path )
37
+ executable_path = base_dir / "7-Zip" / "7z.exe"
38
+ if executable_path .is_file ():
39
+ return str (executable_path )
41
40
raise RuntimeError ("7ZIP is not installed on this computer." )
42
41
43
42
@@ -58,13 +57,11 @@ def replace_lines_in_file(filepath: Path, replacements: list[tuple[str, str]]):
58
57
print (f"Error: File not found: { filepath } " )
59
58
return
60
59
61
- updated_lines = list ( lines ) # Create a mutable copy
60
+ updated_lines = lines . copy ( ) # Create a mutable copy of lines
62
61
63
62
for index , line in enumerate (lines ):
64
63
for prefix , new_text in replacements :
65
- start_prefix = prefix
66
- if not prefix .startswith ("!" ):
67
- start_prefix = "set " + prefix
64
+ start_prefix = "set " + prefix if not prefix .startswith ("!" ) else prefix
68
65
if line .startswith (start_prefix + "=" ):
69
66
updated_lines [index ] = f"{ start_prefix } ={ new_text } \n "
70
67
@@ -75,10 +72,7 @@ def replace_lines_in_file(filepath: Path, replacements: list[tuple[str, str]]):
75
72
except Exception as e :
76
73
print (f"Error writing to file { filepath } : { e } " )
77
74
78
-
79
- def build_installer_7zip (
80
- script_template_path : Path , output_script_path : Path , replacements : list [tuple [str , str ]]
81
- ):
75
+ def build_installer_7zip (script_template_path : Path , output_script_path : Path , replacements : list [tuple [str , str ]]):
82
76
"""
83
77
Creates a 7-Zip installer script by copying a template and applying text replacements.
84
78
@@ -98,13 +92,10 @@ def build_installer_7zip(
98
92
replace_lines_in_file (output_script_path , data_to_replace )
99
93
100
94
try :
101
- # Execute the generated 7-Zip script
95
+ # Execute the generated 7-Zip script, with stdout=sys.stderr to see 7zip compressing
102
96
command = f'"{ output_script_path } "'
103
97
print (f"Executing 7-Zip script: { command } " )
104
- subprocess .run (
105
- command , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr
106
- # with stdout=sys.stdout, we would not see 7zip compressing
107
- )
98
+ subprocess .run (command , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr )
108
99
except subprocess .CalledProcessError as e :
109
100
print (f"Error executing 7-Zip script: { e } " , file = sys .stderr )
110
101
@@ -124,7 +115,7 @@ def _copy_items(source_directories: list[Path], target_directory: Path, verbose:
124
115
try :
125
116
copy_function (source_item , target_item )
126
117
if verbose :
127
- print (f" Copied: { source_item } -> { target_item } " )
118
+ print (f"Copied: { source_item } -> { target_item } " )
128
119
except Exception as e :
129
120
print (f"Error copying { source_item } to { target_item } : { e } " )
130
121
@@ -189,24 +180,15 @@ def __init__(
189
180
190
181
def _get_python_zip_file (self ) -> Path :
191
182
"""Finds the Python .zip file in the wheels directory."""
192
- patterns = [
193
- r"(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip" , # PyPy pattern
194
- r"python-([0-9\.rcba]*)((\.|\-)amd64)?\.(zip|zip)" , # Standard Python pattern
195
- ]
196
- for pattern in patterns :
197
- for filename in os .listdir (self .wheels_directory ):
198
- if re .match (pattern , filename ):
183
+ pattern = r"(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip"
184
+ for filename in os .listdir (self .wheels_directory ):
185
+ if re .match (pattern , filename ):
199
186
return self .wheels_directory / filename
200
187
raise RuntimeError (f"Could not find Python zip package in { self .wheels_directory } " )
201
188
202
189
@property
203
190
def package_index_markdown (self ) -> str :
204
- """
205
- Generates a Markdown formatted package index page.
206
-
207
- Returns:
208
- str: Markdown content for the package index.
209
- """
191
+ """Generates a Markdown formatted package index page."""
210
192
installed_tools_markdown = self ._get_installed_tools_markdown ()
211
193
installed_packages_markdown = self ._get_installed_packages_markdown ()
212
194
python_description = "Python programming language with standard library"
@@ -421,7 +403,7 @@ def _create_initial_batch_scripts(self):
421
403
utils .patch_sourcefile (destination_script_path , '{self.python_dir_name}' , self .python_directory_name )
422
404
utils .patch_sourcefile (destination_script_path , '{self.winpython_version_name}' , self .winpython_version_name )
423
405
utils .patch_sourcefile (destination_script_path , '{full_path_env_var}' , full_path_environment_variable )
424
- utils .patch_sourcefile (destination_script_path ,'{full_path_ps_env_var}' , full_path_powershell_environment_variable )
406
+ utils .patch_sourcefile (destination_script_path , '{full_path_ps_env_var}' , full_path_powershell_environment_variable )
425
407
426
408
def build (self , rebuild : bool = True , requirements_files_list = None , winpy_dirname : str = None ):
427
409
"""Make or finalise WinPython distribution in the target directory"""
@@ -450,8 +432,7 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam
450
432
if rebuild :
451
433
self ._copy_essential_files ()
452
434
self ._create_initial_batch_scripts ()
453
-
454
- utils .python_execmodule ("ensurepip" , self .distribution .target ) # Ensure pip is installed for PyPy
435
+ utils .python_execmodule ("ensurepip" , self .distribution .target )
455
436
self .distribution .patch_standard_packages ("pip" )
456
437
457
438
# Upgrade essential packages
@@ -567,19 +548,15 @@ def make_all(
567
548
else :
568
549
winpython_dirname = f"WPy{ architecture } -{ pyver .replace ('.' , '' )} { python_minor_version_str } { build_number } { release_level } "
569
550
570
- builder .build (
571
- rebuild = rebuild ,
572
- requirements_files_list = requirements_files_list ,
573
- winpy_dirname = winpython_dirname ,
574
- )
551
+ builder .build (rebuild = rebuild , requirements_files_list = requirements_files_list , winpy_dirname = winpython_dirname )
552
+
575
553
if ".zip" in str (create_installer ).lower ():
576
554
builder .create_installer_7zip (".zip" )
577
555
if ".7z" in str (create_installer ).lower ():
578
556
builder .create_installer_7zip (".7z" )
579
557
if "7zip" in str (create_installer ).lower ():
580
558
builder .create_installer_7zip (".exe" )
581
559
582
-
583
560
if __name__ == "__main__" :
584
561
# DO create only one Winpython distribution at a time
585
562
make_all (
0 commit comments