19
19
# Define constant paths for clarity
20
20
CHANGELOGS_DIRECTORY = Path (__file__ ).parent / "changelogs"
21
21
PORTABLE_DIRECTORY = Path (__file__ ).parent / "portable"
22
+ NODEJS_RELATIVE_PATH = "n" # Relative path within WinPython dir
22
23
23
24
# Ensure necessary directories exist at the start
24
25
assert CHANGELOGS_DIRECTORY .is_dir (), f"Changelogs directory not found: { CHANGELOGS_DIRECTORY } "
@@ -58,14 +59,11 @@ def parse_list_argument(argument_value: str | list[str], separator=" ") -> list[
58
59
class WinPythonDistributionBuilder :
59
60
"""Builds a WinPython distribution."""
60
61
61
- NODEJS_RELATIVE_PATH = "n" # Relative path within WinPython dir
62
-
63
62
def __init__ (self , build_number : int , release_level : str , target_directory : Path , wheels_directory : Path ,
64
63
tools_directories : list [Path ] = None , documentation_directories : list [Path ] = None , verbose : bool = False ,
65
64
base_directory : Path = None , install_options : list [str ] = None , flavor : str = "" ):
66
65
"""
67
66
Initializes the WinPythonDistributionBuilder.
68
-
69
67
Args:
70
68
build_number: The build number (integer).
71
69
release_level: The release level (e.g., "beta", "").
@@ -97,7 +95,7 @@ def __init__(self, build_number: int, release_level: str, target_directory: Path
97
95
def _get_python_zip_file (self ) -> Path :
98
96
"""Finds the Python .zip file in the wheels directory."""
99
97
for source_item in self .wheels_directory .iterdir ():
100
- if re .match ("(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip" , source_item .name ):
98
+ if re .match (r "(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip" , source_item .name ):
101
99
return source_item
102
100
raise RuntimeError (f"Could not find Python zip package in { self .wheels_directory } " )
103
101
@@ -138,7 +136,7 @@ def get_tool_path(relative_path):
138
136
path = self .winpython_directory / relative_path if self .winpython_directory else
8000
span> None
139
137
return path if path and path .exists () else None
140
138
141
- if nodejs_path := get_tool_path (self . NODEJS_RELATIVE_PATH ):
139
+ if nodejs_path := get_tool_path (NODEJS_RELATIVE_PATH ):
142
140
installed_tools .append (("Nodejs" , utils .get_nodejs_version (nodejs_path )))
143
141
installed_tools .append (("npmjs" , utils .get_npmjs_version (nodejs_path )))
144
142
@@ -151,8 +149,7 @@ def get_tool_path(relative_path):
151
149
tool_lines = []
152
150
for name , version in installed_tools :
153
151
metadata = utils .get_package_metadata ("tools.ini" , name )
154
- url , description = metadata ["url" ], metadata ["description" ]
155
- tool_lines .append (f"[{ name } ]({ url } ) | { version } | { description } " )
152
+ tool_lines .append (f"[{ name } ]({ metadata ['url' ]} ) | { version } | { metadata ['description' ]} " )
156
153
return "\n " .join (tool_lines )
157
154
158
155
def _get_installed_packages_markdown (self ) -> str :
@@ -193,20 +190,16 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
193
190
"""Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
194
191
self ._print_action (f"Creating WinPython installer ({ installer_type } )" )
195
192
if installer_type not in [".exe" , ".7z" , ".zip" ]:
196
- print (f"Warning: Unsupported installer type '{ installer_type } '. Defaulting to .exe" )
197
- installer_type = ".exe"
193
+ raise RuntimeError ("installer_type {installer_type} is undefined" )
198
194
DISTDIR = self .winpython_directory
199
- filname_stemp = f"Winpython{ str (self .architecture_bits )} -{ self .python_full_version } .{ self .build_number } { self .flavor } { self .release_level } "
200
- fullfilename = DISTDIR .parent / (filname_stemp + installer_type )
201
- if installer_type == ".zip" :
202
- other = f'"{ find_7zip_executable ()} " -tzip -mx5 a "{ fullfilename } " "{ DISTDIR } " '
203
- if installer_type == ".7z" :
204
- other = f'"{ find_7zip_executable ()} " -mx5 a "{ fullfilename } " "{ DISTDIR } " '
205
- if installer_type == ".exe" :
206
- other = f'"{ find_7zip_executable ()} " -mx5 a "{ fullfilename } " "{ DISTDIR } " -sfx7z.sfx'
207
- print (f'Executing 7-Zip script: "{ other } "' )
195
+ filename_stem = f"Winpython{ self .architecture_bits } -{ self .python_full_version } .{ self .build_number } { self .flavor } { self .release_level } "
196
+ fullfilename = DISTDIR .parent / (filename_stem + installer_type )
197
+ sfx_option = "-sfx7z.sfx" if installer_type == ".exe" else ""
198
+ zip_option = "-tzip" if installer_type == ".zip" else ""
199
+ command = f'"{ find_7zip_executable ()} " { zip_option } -mx5 a "{ fullfilename } " "{ DISTDIR } " { sfx_option } '
200
+ print (f'Executing 7-Zip script: "{ command } "' )
208
201
try :
209
- subprocess .run (other , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr )
202
+ subprocess .run (command , shell = True , check = True , stderr = sys .stderr , stdout = sys .stderr )
210
203
except subprocess .CalledProcessError as e :
211
204
print (f"Error executing 7-Zip script: { e } " , file = sys .stderr )
212
205
@@ -243,22 +236,20 @@ def _copy_essential_files(self):
243
236
copy_items (self .tools_directories , tools_target_directory , self .verbose )
244
237
245
238
if (nodejs_current_directory := tools_target_directory / "n" ).is_dir ():
246
- self ._print_action (f"moving tools from { nodejs_current_directory } to { tools_target_directory .parent / self . NODEJS_RELATIVE_PATH } " )
239
+ self ._print_action (f"Moving tools from { nodejs_current_directory } to { tools_target_directory .parent / NODEJS_RELATIVE_PATH } " )
247
240
try :
248
- shutil .move (nodejs_current_directory , tools_target_directory .parent / self . NODEJS_RELATIVE_PATH )
241
+ shutil .move (nodejs_current_directory , tools_target_directory .parent / NODEJS_RELATIVE_PATH )
249
242
except Exception as e :
250
243
print (f"Error moving Node.js directory: { e } " )
251
244
252
245
def _create_initial_batch_scripts (self ):
253
246
"""Creates initial batch scripts, including environment setup."""
254
247
self ._print_action ("Creating initial batch scripts" )
255
-
256
248
# Replacements for batch scripts (PyPy compatibility)
257
249
executable_name = self .distribution .short_exe if self .distribution else "python.exe" # default to python.exe if distribution is not yet set
258
-
259
250
init_variables = [('WINPYthon_exe' , executable_name ), ('WINPYthon_subdirectory_name' , self .python_directory_name ), ('WINPYVER' , self .winpython_version_name )]
260
251
with open (self .winpython_directory / "scripts" / "env.ini" , "w" ) as f :
261
- f .writelines ([f'{ a } ={ b } \n ' for a , b in init_variables ])
252
+ f .writelines ([f'{ a } ={ b } \n ' for a , b in init_variables ])
262
253
263
254
def build (self , rebuild : bool = True , requirements_files_list = None , winpy_dirname : str = None ):
264
255
"""Make or finalise WinPython distribution in the target directory"""
@@ -296,9 +287,7 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam
296
287
297
288
if requirements_files_list :
298
289
for req in requirements_files_list :
299
- actions = ["install" , "-r" , req ]
300
- if self .install_options is not None :
301
- actions += self .install_options
290
+ actions = ["install" , "-r" , req ] + (self .install_options or [])
302
291
self ._print_action (f"Piping: { ' ' .join (actions )} " )
303
292
self .distribution .do_pip_action (actions )
304
293
self .distribution .patch_standard_packages ()
@@ -386,12 +375,9 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
386
375
387
376
builder .build (rebuild = rebuild , requirements_files_list = requirements_files_list , winpy_dirname = winpython_dirname )
388
377
389
- if ".zip" in create_installer .lower ():
390
- builder .create_installer_7zip (".zip" )
391
- if ".7z" in create_installer .lower ():
392
- builder .create_installer_7zip (".7z" )
393
- if "7zip" in create_installer .lower ():
394
- builder .create_installer_7zip (".exe" )
378
+ for installer_type in [".zip" , ".7z" , ".exe" ]:
379
+ if installer_type in create_installer .lower ().replace ("7zip" ,".exe" ):
380
+ builder .create_installer_7zip (installer_type )
395
381
396
382
if __name__ == "__main__" :
397
383
# DO create only one Winpython distribution at a time
@@ -409,4 +395,4 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
409
395
source_dirs = r"D:\WinPython\basedir34\packages.win-amd64" ,
410
396
toolsdirs = r"D:\WinPython\basedir34\t.Slim" ,
411
397
docsdirs = r"D:\WinPython\basedir34\docs.Slim" ,
412
- )
398
+ )
0 commit comments