@@ -401,12 +401,22 @@ def _extract_python_archive(self):
401
401
expected_python_directory = self .winpython_directory / self .python_directory_name
402
402
if self .python_directory_name != self .python_name and not expected_python_directory .is_dir ():
403
403
os .rename (self .winpython_directory / self .python_name , expected_python_directory )
404
+
405
+ def _copy_essential_files (self ):
406
+ """Copies pre-made objects"""
407
+ self ._print_action ("Copying default scripts" )
408
+ _copy_items ([PORTABLE_DIRECTORY / "scripts" ], self .winpython_directory / "scripts" , self .verbose )
409
+
410
+ self ._print_action ("Copying launchers" )
411
+ _copy_items ([PORTABLE_DIRECTORY / "launchers_final" ], self .winpython_directory , self .verbose )
412
+
413
+ docs_target_directory = self .winpython_directory / "notebooks" / "docs"
414
+ self ._print_action (f"Copying documentation to { docs_target_directory } " )
415
+ _copy_items (self .documentation_directories_list , docs_target_directory , self .verbose )
404
416
405
- def _copy_tools (self ):
406
- """Copies development tools to the WinPython 't' directory."""
407
417
tools_target_directory = self .winpython_directory / "t"
408
418
self ._print_action (f"Copying tools to { tools_target_directory } " )
409
- _copy_items (self .tools_directories , tools_target_directory , self .verbose )
419
+ _copy_items (self .tools_directories , self . winpython_directory / "t" , self .verbose )
410
420
411
421
# Special handling for Node.js to move it up one level
412
422
nodejs_current_directory = tools_target_directory / "n"
@@ -417,22 +427,6 @@ def _copy_tools(self):
417
427
except Exception as e :
418
428
print (f"Error moving Node.js directory: { e } " )
419
429
420
- def _copy_documentation (self ):
421
- """Copies documentation files to the WinPython 'docs' directory."""
422
- docs_target_directory = self .winpython_directory / "notebooks" / "docs"
423
- self ._print_action (f"Copying documentation to { docs_target_directory } " )
424
- _copy_items (self .documentation_directories_list , docs_target_directory , self .verbose )
425
-
426
- def _copy_launchers (self ):
427
- """Copies pre-made launchers to the WinPython directory."""
428
- self ._print_action ("Creating launchers" )
429
- _copy_items ([PORTABLE_DIRECTORY / "launchers_final" ], self .winpython_directory , self .verbose )
430
-
431
- def _copy_default_scripts (self ):
432
- """Copies launchers and default scripts."""
433
- self ._print_action ("copying pre-made scripts" )
434
- _copy_items ([PORTABLE_DIRECTORY / "scripts" ], self .winpython_directory / "scripts" , self .verbose )
435
-
436
430
def _create_initial_batch_scripts (self ):
437
431
"""Creates initial batch scripts, including environment setup."""
438
432
self ._print_action ("Creating initial batch scripts" )
@@ -456,45 +450,33 @@ def _create_initial_batch_scripts(self):
456
450
utils .patch_sourcefile (destination_script_path , '{full_path_env_var}' , full_path_environment_variable )
457
451
utils .patch_sourcefile (destination_script_path ,'{full_path_ps_env_var}' , full_path_powershell_environment_variable )
458
452
459
- def build (self , rebuild : bool = True , requirements = None , winpy_dirname : str = None ):
460
- """Make WinPython distribution in target directory from the installers
461
- located in wheels_directory
462
-
463
- rebuild=True: (default) install all from scratch
464
- rebuild=False: for complementary purposes (create installers)
465
- requirements=file(s) of requirements (separated by space if several)"""
453
+ def build (self , rebuild : bool = True , requirements_files_list = None , winpy_dirname : str = None ):
454
+ """Make or finalise WinPython distribution in the target directory"""
455
+
466
456
python_zip_filename = self .python_zip_file .name
467
457
print (f"Building WinPython with Python archive: { python_zip_filename } " )
468
458
469
459
if winpy_dirname is None :
470
460
raise RuntimeError ("WinPython base directory to create is undefined" )
471
461
else :
472
462
self .winpython_directory = self .target_directory / winpy_dirname # Create/re-create the WinPython base directory
473
- self ._print_action (f"Creating WinPython { self .winpython_directory } base directory" )
474
- if self .winpython_directory .is_dir () and rebuild :
475
- try :
476
- shutil .rmtree (self .winpython_directory , onexc = utils .onerror )
477
- except TypeError : # before 3.12
478
- shutil .rmtree (self .winpython_directory , onerror = utils .onerror )
479
- os .makedirs (self .winpython_directory , exist_ok = True )
480
463
if rebuild :
464
+ self ._print_action (f"Creating WinPython { self .winpython_directory } base directory" )
465
+ if self .winpython_directory .is_dir ():
466
+ try :
467
+ shutil .rmtree (self .winpython_directory , onexc = utils .onerror )
468
+ except TypeError : # before 3.12
469
+ shutil .rmtree (self .winpython_directory , onerror = utils .onerror )
470
+ os .makedirs (self .winpython_directory , exist_ok = True )
481
471
# preventive re-Creation of settings directory
482
- # (necessary if user is starting an application with a batch)
483
- (self .winpython_directory / "settings" / "AppData" / "Roaming" ).mkdir (parents = True , exist_ok = True ) # Ensure settings dir exists
472
+ (self .winpython_directory / "settings" / "AppData" / "Roaming" ).mkdir (parents = True , exist_ok = True )
484
473
self ._extract_python_archive ()
485
474
486
- self .distribution = wppm .Distribution (
487
- self .python_executable_directory ,
488
- verbose = self .verbose ,
489
- indent = True ,
490
- )
475
+ self .distribution = wppm .Distribution (self .python_executable_directory , verbose = self .verbose )
491
476
492
477
if rebuild :
493
- self ._copy_default_scripts ()
478
+ self ._copy_essential_files ()
494
479
self ._create_initial_batch_scripts ()
495
- self ._copy_launchers ()
496
- self ._copy_tools ()
497
- self ._copy_documentation ()
498
480
499
481
utils .python_execmodule ("ensurepip" , self .distribution .target ) # Ensure pip is installed for PyPy
500
482
self .distribution .patch_standard_packages ("pip" )
@@ -503,53 +485,40 @@ def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = No
503
485
essential_packages = ["pip" , "setuptools" , "wheel" , "winpython" ]
504
486
for package_name in essential_packages :
505
487
actions = ["install" , "--upgrade" , "--pre" , package_name ] + self .install_options
506
- print (f"Piping: { ' ' .join (actions )} " )
507
488
self ._print_action (f"Piping: { ' ' .join (actions )} " )
508
489
self .distribution .do_pip_action (actions )
509
490
self .distribution .patch_standard_packages (package_name )
510
491
511
- if requirements :
512
- if not isinstance (requirements , list ):
513
- requirements = requirements .split ("," )
514
- for req in requirements :
515
- actions = ["install" , "-r" , req ]
516
- if self .install_options is not None :
517
- actions += self .install_options
518
- print (f"piping { ' ' .join (actions )} " )
519
- self ._print_action (f"piping { ' ' .join (actions )} " )
520
- self .distribution .do_pip_action (actions )
521
-
492
+ if requirements_files_list :
493
+ for req in requirements_files_list :
494
+ actions = ["install" , "-r" , req ]
495
+ if self .install_options is not None :
496
+ actions += self .install_options
497
+ self ._print_action (f"piping { ' ' .join (actions )} " )
498
+ self .distribution .do_pip_action (actions )
522
499
self .distribution .patch_standard_packages ()
523
500
524
- self ._print_action ("Cleaning up distribution" )
525
- self .distribution .clean_up ()
501
+ self ._print_action ("Cleaning up distribution" )
502
+ self .distribution .clean_up () # still usefull ?
526
503
# Writing package index
527
504
self ._print_action ("Writing package index" )
528
505
# winpyver2 = the version without build part but with self.distribution.architecture
529
506
self .winpyver2 = f"{ self .python_full_version } .{ self .build_number } "
530
507
output_markdown_filename = str (self .winpython_directory .parent / f"WinPython{ self .flavor } -{ self .distribution .architecture } bit-{ self .winpyver2 } .md" )
531
508
open (output_markdown_filename , "w" , encoding = 'utf-8' ).write (self .package_index_markdown )
532
509
533
- # Copy to winpython/changelogs
534
- shutil .copyfile (output_markdown_filename , str (Path (CHANGELOGS_DIRECTORY ) / Path (output_markdown_filename ).name ))
535
-
536
510
# Writing changelog
537
511
self ._print_action ("Writing changelog" )
538
- diff .write_changelog (
539
- self .winpyver2 ,
540
- basedir = self .base_directory ,
541
- flavor = self .flavor ,
542
- release_level = self .release_level ,
543
- architecture = self .distribution .architecture ,
544
- )
512
+ shutil .copyfile (output_markdown_filename , str (Path (CHANGELOGS_DIRECTORY ) / Path (output_markdown_filename ).name ))
513
+ diff .write_changelog (self .winpyver2 , None , self .base_directory , self .flavor , self .release_level , self .distribution .architecture )
545
514
546
515
547
- def rebuild_winpython_package (source_dir : Path , target_directory : Path , architecture : int = 64 , verbose : bool = False ):
516
+ def rebuild_winpython_package (source_directory : Path , target_directory : Path , architecture : int = 64 , verbose : bool = False ):
548
517
"""Rebuilds the winpython package from source using flit."""
549
518
for filename in os .listdir (target_directory ):
550
519
if filename .startswith ("winpython-" ) and filename .endswith ((".exe" , ".whl" , ".gz" )):
551
520
os .remove (Path (target_directory ) / filename )
552
- utils .buildflit_wininst (source_dir , copy_to = target_directory , verbose = verbose )
521
+ utils .buildflit_wininst (source_directory , copy_to = target_directory , verbose = verbose )
553
522
554
523
555
524
def make_all (
@@ -618,19 +587,19 @@ def make_all(
618
587
flavor = flavor ,
619
588
)
620
589
# define the directory where to create the distro
621
- my_x = "" .join (builder .python_name .replace (".amd64" , "" ).split ("." )[- 2 :- 1 ])
622
- while not my_x .isdigit () and len (my_x ) > 0 :
623
- my_x = my_x [:- 1 ]
590
+ python_minor_version_str = "" .join (builder .python_name .replace (".amd64" , "" ).split ("." )[- 2 :- 1 ])
591
+ while not python_minor_version_str .isdigit () and len (python_minor_version_str ) > 0 :
592
+ python_minor_version_str = python_minor_version_str [:- 1 ]
624
593
# simplify for PyPy
625
- if not python_target_release == None :
626
- winpy_dirname = f"WPy{ architecture } -{ python_target_release } { build_number } { release_level } "
594
+ if python_target_release is not None :
595
+ winpython_dirname = f"WPy{ architecture } -{ python_target_release } { build_number } { release_level } "
627
596
else :
628
- winpy_dirname = f"WPy{ architecture } -{ pyver .replace ('.' , '' )} { my_x } { build_number } { release_level } "
597
+ winpython_dirname = f"WPy{ architecture } -{ pyver .replace ('.' , '' )} { python_minor_version_str } { build_number } { release_level } "
629
598
630
599
builder .build (
631
600
rebuild = rebuild ,
632
- requirements = requirements_files_list ,
633
- winpy_dirname = winpy_dirname ,
601
+ requirements_files_list = requirements_files_list ,
602
+ winpy_dirname = winpython_dirname ,
634
603
)
635
604
if ".zip" in str (create_installer ).lower ():
636
605
builder .create_installer_7zip (".zip" )
0 commit comments