@@ -501,6 +501,15 @@ def _create_launchers(self):
501501 shutil .copy2 (item , self .winpy_dir )
502502 self ._print_action_done ()
503503
504+ def _copy_default_scripts (self ):
505+ """Copies launchers and defeult scripts."""
506+ self ._print_action ("copying pre-made scripts" )
507+ origin = PORTABLE_DIR / "scripts"
508+ destination = self .winpy_dir / "scripts"
509+ for item in origin .rglob ('*.*' ):
510+ shutil .copy2 (item , destination )
511+ if self .verbose :
512+ print (f" Copied : { item .name } -> { destination } " )
504513
505514 def _create_initial_batch_scripts (self ):
506515 """Creates initial batch scripts, including environment setup."""
@@ -679,113 +688,6 @@ def _create_initial_batch_scripts(self):
679688"""
680689 self .create_batch_script ("env_for_icons.bat" , env_for_icons_bat_content , replacements = batch_replacements )
681690
682-
683- winpython_ini_py_content = r"""
684- # Prepares a dynamic list of variables settings from a .ini file
685- import os
686- import subprocess
687- from pathlib import Path
688-
689- winpython_inidefault=r'''
690- [debug]
691- state = disabled
692- [inactive_environment_per_user]
693- ## <?> changing this segment to [active_environment_per_user] makes this segment of lines active or not
694- HOME = %HOMEDRIVE%%HOMEPATH%\Documents\WinPython%WINPYVER%\settings
695- USERPROFILE = %HOME%
696- JUPYTER_DATA_DIR = %HOME%
697- WINPYWORKDIR = %HOMEDRIVE%%HOMEPATH%\Documents\WinPython%WINPYVER%\Notebooks
698- [inactive_environment_common]
699- USERPROFILE = %HOME%
700- [environment]
701- ## <?> Uncomment lines to override environment variables
702- #JUPYTERLAB_SETTINGS_DIR = %HOME%\.jupyter\lab
703- #JUPYTERLAB_WORKSPACES_DIR = %HOME%\.jupyter\lab\workspaces
704- #R_HOME=%WINPYDIRBASE%\t\R
705- #R_HOMEbin=%R_HOME%\bin\x64
706- #JULIA_HOME=%WINPYDIRBASE%\t\Julia\bin\
707- #JULIA_EXE=julia.exe
708- #JULIA=%JULIA_HOME%%JULIA_EXE%
709- #JULIA_PKGDIR=%WINPYDIRBASE%\settings\.julia
710- #QT_PLUGIN_PATH=%WINPYDIR%\Lib\site-packages\pyqt5_tools\Qt\plugins
711- '''
712-
713- def get_file(file_name):
714- if file_name.startswith("..\\"):
715- file_name = os.path.join(os.path.dirname(os.path.dirname(__file__)), file_name[3:])
716- elif file_name.startswith(".\\"):
717- file_name = os.path.join(os.path.dirname(__file__), file_name[2:])
718- try:
719- with open(file_name, 'r') as file:
720- return file.read()
721- except FileNotFoundError:
722- if file_name[-3:] == 'ini':
723- os.makedirs(Path(file_name).parent, exist_ok=True)
724- with open(file_name, 'w') as file:
725- file.write(winpython_inidefault)
726- return winpython_inidefault
727-
728- def translate(line, env):
729- parts = line.split('%')
730- for i in range(1, len(parts), 2):
731- if parts[i] in env:
732- parts[i] = env[parts[i]]
733- return ''.join(parts)
734-
735- def main():
736- import sys
737- args = sys.argv[1:]
738- file_name = args[0] if args else "..\\settings\\winpython.ini"
739-
740- my_lines = get_file(file_name).splitlines()
741- segment = "environment"
742- txt = ""
743- env = os.environ.copy() # later_version: env = os.environ
744-
745- # default directories (from .bat)
746- os.makedirs(Path(env['WINPYDIRBASE']) / 'settings' / 'Appdata' / 'Roaming', exist_ok=True)
747-
748- # default qt.conf for Qt directories
749- qt_conf='''echo [Paths]
750- echo Prefix = .
751- echo Binaries = .
752- '''
753-
754- pathlist = [Path(env['WINPYDIR']) / 'Lib' / 'site-packages' / i for i in ('PyQt5', 'PyQt6', 'Pyside6')]
755- for p in pathlist:
756- if p.is_dir():
757- if not (p / 'qt.conf').is_file():
758- with open(p / 'qt.conf', 'w') as file:
759- file.write(qt_conf)
760-
761- for l in my_lines:
762- if l.startswith("["):
763- segment = l[1:].split("]")[0]
764- elif not l.startswith("#") and "=" in l:
765- data = l.split("=", 1)
766- if segment == "debug" and data[0].strip() == "state":
767- data[0] = "WINPYDEBUG"
768- if segment in ["environment", "debug", "active_environment_per_user", "active_environment_common"]:
769- txt += f"set {data[0].strip()}={translate(data[1].strip(), env)}&& "
770- env[data[0].strip()] = translate(data[1].strip(), env)
771- if segment == "debug" and data[0].strip() == "state":
772- txt += f"set WINPYDEBUG={data[1].strip()}&&"
773-
774- print(txt)
775-
776- # set potential directory
777- for i in ('HOME', 'WINPYWORKDIR'):
778- if i in env:
779- os.makedirs(Path(env[i]), exist_ok=True)
780- # later_version:
781- # p = subprocess.Popen(["start", "cmd", "/k", "set"], shell = True)
782- # p.wait() # I can wait until finished (although it too finishes after start finishes)
783-
784- if __name__ == "__main__":
785- main()
786- """
787- self .create_batch_script ("WinPythonIni.py" , winpython_ini_py_content )
788-
789691 self ._print_action_done ()
790692
791693
@@ -994,8 +896,10 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:
994896
995897 if remove_existing :
996898 self ._create_initial_batch_scripts ()
899+ self ._copy_default_scripts ()
997900 self ._create_standard_batch_scripts ()
998901 self ._create_launchers ()
902+
999903 utils .python_execmodule ("ensurepip" , self .distribution .target ) # Ensure pip is installed for PyPy
1000904 self .distribution .patch_standard_packages ("pip" )
1001905
0 commit comments