@@ -127,19 +127,9 @@ class WinPythonDistributionBuilder:
127
127
128
128
NODEJS_RELATIVE_PATH = r"\n" # Relative path within WinPython dir
129
129
130
- def __init__ (
131
- self ,
132
- build_number : int ,
133
- release_level : str ,
134
- target_directory : Path ,
135
- wheels_directory : Path ,
136
- tools_directories : list [Path ] = None ,
137
- documentation_directories : list [Path ] = None ,
138
- verbose : bool = False ,
139
- base_directory : Path = None ,
140
- install_options : list [str ] = None ,
141
- flavor : str = "" ,
142
- ):
130
+ def __init__ (self , build_number : int , release_level : str , target_directory : Path , wheels_directory : Path ,
131
+ tools_directories : list [Path ] = None , documentation_directories : list [Path ] = None , verbose : bool = False ,
132
+ base_directory : Path = None , install_options : list [str ] = None , flavor : str = "" ):
143
133
"""
144
134
Initializes the WinPythonDistributionBuilder.
145
135
@@ -269,7 +259,7 @@ def python_executable_directory(self) -> str:
269
259
if python_path_directory and python_path_directory .is_dir ():
270
260
return str (python_path_directory )
271
261
else :
272
- python_path_executable = self .winpython_directory / self .python_name if self .winpython_directory else None # Fallback for older structure
262
+ python_path_executable = self .winpython_directory / self .python_name if self .winpython_directory else None
273
263
return str (python_path_executable ) if python_path_executable else ""
274
264
275
265
@property
@@ -321,15 +311,12 @@ def _print_action(self, text: str):
321
311
def _extract_python_archive (self ):
322
312
"""Extracts the Python zip archive to create the base Python environment."""
323
313
self ._print_action ("Extracting Python archive" )
324
- utils .extract_archive (
325
- str (self .python_zip_file ),
326
- targetdir = str (self .winpython_directory ), # Extract directly to winpython_directory
327
- )
314
+ utils .extract_archive (self .python_zip_file , self .winpython_directory )
328
315
# Relocate to /python subfolder if needed (for newer structure) #2024-12-22 to /python
329
316
expected_python_directory = self .winpython_directory / self .python_directory_name
330
317
if self .python_directory_name != self .python_name and not expected_python_directory .is_dir ():
331
318
os .rename (self .winpython_directory / self .python_name , expected_python_directory )
332
-
319
+
333
320
def _copy_essential_files (self ):
334
321
"""Copies pre-made objects"""
335
322
self ._print_action ("Copying default scripts" )
@@ -347,11 +334,9 @@ def _copy_essential_files(self):
347
334
_copy_items (self .tools_directories , tools_target_directory , self .verbose )
348
335
349
336
# Special handling for Node.js to move it up one level
350
- nodejs_current_directory = tools_target_directory / "n"
351
- nodejs_target_directory = self .winpython_directory / self .NODEJS_RELATIVE_PATH
352
- if nodejs_current_directory != nodejs_target_directory and nodejs_current_directory .is_dir ():
337
+ if (nodejs_current_directory := tools_target_directory / "n" ).is_dir ():
353
338
try :
354
- shutil .move (nodejs_current_directory , nodejs_target_directory )
339
+ shutil .move (nodejs_current_directory , self . winpython_directory / self . NODEJS_RELATIVE_PATH )
355
340
except Exception as e :
356
341
print (f"Error moving Node.js directory: { e } " )
357
342
@@ -380,14 +365,13 @@ def _create_initial_batch_scripts(self):
380
365
381
366
def build (self , rebuild : bool = True , requirements_files_list = None , winpy_dirname : str = None ):
382
367
"""Make or finalise WinPython distribution in the target directory"""
383
-
384
- python_zip_filename = self .python_zip_file .name
385
- print (f"Building WinPython with Python archive: { python_zip_filename } " )
368
+ print (f"Building WinPython with Python archive: { self .python_zip_file .name } " )
386
369
387
370
if winpy_dirname is None :
388
371
raise RuntimeError ("WinPython base directory to create is undefined" )
389
372
else :
390
373
self .winpython_directory = self .target_directory / winpy_dirname # Create/re-create the WinPython base directory
374
+
391
375
if rebuild :
392
376
self ._print_action (f"Creating WinPython { self .winpython_directory } base directory" )
393
377
if self .winpython_directory .is_dir ():
@@ -448,37 +432,32 @@ def rebuild_winpython_package(source_directory: Path, target_directory: Path, ar
448
432
utils .buildflit_wininst (source_directory , copy_to = target_directory , verbose = verbose )
449
433
450
434
451
- def make_all (
452
- build_number : int ,
453
- release_level : str ,
454
- pyver : str ,
455
- architecture : int ,
456
- basedir : Path ,
457
- verbose : bool = False ,
458
- rebuild : bool = True ,
459
- create_installer : str = "True" ,
460
- install_options = ["--no-index" ],
461
- flavor : str = "" ,
462
- requirements : str | list [Path ] = None ,
463
- find_links : str | list [Path ] = None ,
464
- source_dirs : Path = None ,
465
- toolsdirs : str | list [Path ] = None ,
466
- docsdirs : str | list [Path ] = None ,
467
- python_target_release : str = None , # e.g. "37101" for 3.7.10
435
+ def make_all (build_number : int , release_level : str , pyver : str , architecture : int , basedir : Path ,
436
+ verbose : bool = False , rebuild : bool = True , create_installer : str = "True" , install_options = ["--no-index" ],
437
+ flavor : str = "" , requirements : str | list [Path ] = None , find_links : str | list [Path ] = None ,
438
+ source_dirs : Path = None , toolsdirs : str | list [Path ] = None , docsdirs : str | list [Path ] = None ,
439
+ python_target_release : str = None , # e.g. "37101" for 3.7.10
468
440
):
469
- """Make a WinPython distribution for a given set of parameters:
470
- `build_number`: build number [int]
471
- `release_level`: release level (e.g. 'beta1', '') [str]
472
- `pyver`: python version ('3.4' or 3.5')
473
- `architecture`: [int] (32 or 64)
474
- `basedir`: where to create the build (r'D:\Winpython\b asedir34')
475
- `requirements`: package lists for pip (r'D:\r equirements.txt')
476
- `install_options`: pip options (r'--no-index --pre --trusted-host=None')
477
- `find_links`: package directories (r'D:\Winpython\packages.srcreq')
478
- `source_dirs`: the python.zip + rebuilt winpython wheel package directory
479
- `toolsdirs`: r'D:\WinPython\b asedir34\t .Slim'
480
- `docsdirs`: r'D:\WinPython\b asedir34\docs.Slim'"""
481
-
441
+ """
442
+ Make a WinPython distribution for a given set of parameters:
443
+ Args:
444
+ build_number: build number [int]
445
+ release_level: release level (e.g. 'beta1', '') [str]
446
+ pyver: python version ('3.4' or 3.5')
447
+ architecture: [int] (32 or 64)
448
+ basedir: where to create the build (r'D:\Winpython\b asedir34')
449
+ verbose: Enable verbose output (bool).
450
+ rebuild: Whether to rebuild the distribution (bool).
451
+ create_installer: Type of installer to create (str).
452
+ install_options: pip options (r'--no-index --pre --trusted-host=None')
453
+ flavor: WinPython flavor (str).
454
+ requirements: package lists for pip (r'D:\r equirements.txt')
455
+ find_links: package directories (r'D:\Winpython\packages.srcreq')
456
+ source_dirs: the python.zip + rebuilt winpython wheel package directory
457
+ toolsdirs: Directory with development tools r'D:\WinPython\b asedir34\t .Slim'
458
+ docsdirs: Directory with documentation r'D:\WinPython\b asedir34\docs.Slim'
459
+ python_target_release: Target Python release (str).
460
+ """
482
461
assert basedir is not None , "The *basedir* directory must be specified"
483
462
assert architecture in (32 , 64 )
484
463
@@ -492,24 +471,19 @@ def make_all(
492
471
build_directory = str (Path (basedir ) / ("bu" + flavor ))
493
472
494
473
if rebuild :
495
- # Rebuild Winpython Wheel Package
496
474
utils .print_box (f"Making WinPython { architecture } bits at { Path (basedir ) / ('bu' + flavor )} " )
497
475
os .makedirs (Path (build_directory ), exist_ok = True )
498
476
# use source_dirs as the directory to re-build Winpython wheel
499
477
winpython_source_dir = Path (__file__ ).resolve ().parent
500
478
rebuild_winpython_package (winpython_source_dir , source_dirs , architecture , verbose )
501
479
502
480
builder = WinPythonDistributionBuilder (
503
- build_number ,
504
- release_level ,
505
- build_directory ,
506
- wheels_directory = source_dirs ,
481
+ build_number , release_level , build_directory , wheels_directory = source_dirs ,
507
482
tools_directories = [Path (d ) for d in tools_dirs_list ],
508
483
documentation_directories = [Path (d ) for d in docs_dirs_list ],
509
- verbose = verbose ,
510
- base_directory = basedir ,
484
+ verbose = verbose , base_directory = basedir ,
511
485
install_options = install_options_list + find_links_options ,
512
- flavor = flavor ,
486
+ flavor = flavor
513
487
)
514
488
# define the directory where to create the distro
515
489
python_minor_version_str = "" .join (builder .python_name .replace (".amd64" , "" ).split ("." )[- 2 :- 1 ])
0 commit comments