@@ -495,7 +495,7 @@ def _copy_default_scripts(self):
495495 destination = self .winpy_dir / "scripts"
496496 _copy_items ([origin ], destination , self .verbose )
497497 self ._print_action_done ()
498-
498+
499499 def _create_initial_batch_scripts (self ):
500500 """Creates initial batch scripts, including environment setup."""
501501 self ._print_action ("Creating initial batch scripts" )
@@ -515,112 +515,14 @@ def _create_initial_batch_scripts(self):
515515 if self .distribution and (Path (self .distribution .target ) / r"lib-python\3\idlelib" ).is_dir ():
516516 batch_replacements .append ((r"\Lib\idlelib" , r"\lib-python\3\idlelib" ))
517517
518-
519- env_bat_content = f"""@echo off
520- set WINPYDIRBASE=%~dp0..
521-
522- rem get a normalized path
523- set WINPYDIRBASETMP=%~dp0..
524- pushd %WINPYDIRBASETMP%
525- set WINPYDIRBASE=%__CD__%
526- if "%WINPYDIRBASE:~-1%"=="\\ " set WINPYDIRBASE=%WINPYDIRBASE:~0,-1%
527- set WINPYDIRBASETMP=
528- popd
529-
530- set WINPYDIR=%WINPYDIRBASE%\\ { self .python_dir_name }
531- rem 2019-08-25 pyjulia needs absolutely a variable PYTHON=%WINPYDIR%\\ python.exe
532- set PYTHON=%WINPYDIR%\\ python.exe
533- set PYTHONPATHz=%WINPYDIR%;%WINPYDIR%\\ Lib;%WINPYDIR%\\ DLLs
534- set WINPYVER={ self .winpython_version_name }
535-
536- rem 2023-02-12 utf-8 on console to avoid pip crash
537- rem see https://github.com/pypa/pip/issues/11798#issuecomment-1427069681
538- set PYTHONIOENCODING=utf-8
539- rem set PYTHONUTF8=1 creates issues in "movable" patching
540-
541- set HOME=%WINPYDIRBASE%\\ settings
542- rem see https://github.com/winpython/winpython/issues/839
543- rem set USERPROFILE=%HOME%
544- set JUPYTER_DATA_DIR=%HOME%
545- set JUPYTER_CONFIG_DIR=%WINPYDIR%\\ etc\\ jupyter
546- set JUPYTER_CONFIG_PATH=%WINPYDIR%\\ etc\\ jupyter
547- set FINDDIR=%WINDIR%\\ system32
548-
549- rem Remove all double quotes
550- set PATH_CLEANED=%PATH:"=%
551- echo ";%PATH_CLEANED%;" | %FINDDIR%\\ find.exe /C /I ";%WINPYDIR%\\ ;" >nul
552- if %ERRORLEVEL% NEQ 0 (
553- set "PATH={ full_path_env_var } "
554- cd .
555- )
556- set PATH_CLEANED=
557-
558- rem force default pyqt5 kit for Spyder if PyQt5 module is there
559- if exist "%WINPYDIR%\\ Lib\\ site-packages\\ PyQt5\\ __init__.py" set QT_API=pyqt5
560- """
561- self .create_batch_script ("env.bat" , env_bat_content , replacements = batch_replacements )
562-
563-
564- ps1_content = r"""### WinPython_PS_Prompt.ps1 ###
565- $0 = $myInvocation.MyCommand.Definition
566- $dp0 = [System.IO.Path]::GetDirectoryName($0)
567- # $env:PYTHONUTF8 = 1 would create issues in "movable" patching
568- $env:WINPYDIRBASE = "$dp0\.."
569- # get a normalize path
570- # http://stackoverflow.com/questions/1645843/resolve-absolute-path-from-relative-path-and-or-file-name
571- $env:WINPYDIRBASE = [System.IO.Path]::GetFullPath( $env:WINPYDIRBASE )
572-
573- # avoid double_init (will only resize screen)
574- if (-not ($env:WINPYDIR -eq [System.IO.Path]::GetFullPath( $env:WINPYDIRBASE+""" + '"\\ ' + self .python_dir_name + '"' + r""")) ) {
575- $env:WINPYDIR = $env:WINPYDIRBASE+""" + '"\\ ' + self .python_dir_name + '"' + r"""
576- # 2019-08-25 pyjulia needs absolutely a variable PYTHON=%WINPYDIR%python.exe
577- $env:PYTHON = "%WINPYDIR%\python.exe"
578- $env:PYTHONPATHz = "%WINPYDIR%;%WINPYDIR%\Lib;%WINPYDIR%\DLLs"
579-
580- $env:WINPYVER = '""" + self .winpython_version_name + r"""'
581- # rem 2023-02-12 try utf-8 on console
582- # rem see https://github.com/pypa/pip/issues/11798#issuecomment-1427069681
583- $env:PYTHONIOENCODING = "utf-8"
584-
585- $env:HOME = "$env:WINPYDIRBASE\settings"
586-
587- # rem read https://github.com/winpython/winpython/issues/839
588- # $env:USERPROFILE = "$env:HOME"
589-
590- $env:WINPYDIRBASE = ""
591- $env:JUPYTER_DATA_DIR = "$env:HOME"
592-
593- if (-not $env:PATH.ToLower().Contains(";"+ $env:WINPYDIR.ToLower()+ ";")) {
594- $env:PATH = """ + '"' + full_path_ps_env_var + '"' + r""" }
595-
596- #rem force default pyqt5 kit for Spyder if PyQt5 module is there
597- if (Test-Path "$env:WINPYDIR\Lib\site-packages\PyQt5\__init__.py") { $env:QT_API = "pyqt5" }
598-
599- # PyQt5 qt.conf creation and winpython.ini creation done via Winpythonini.py (called per env_for_icons.bat for now)
600- # Start-Process -FilePath $env:PYTHON -ArgumentList ($env:WINPYDIRBASE + '\scripts\WinPythonIni.py')
601-
602-
603- ### Set-WindowSize
604-
605- Function Set-WindowSize {
606- Param([int]$x=$host.ui.rawui.windowsize.width,
607- [int]$y=$host.ui.rawui.windowsize.heigth,
608- [int]$buffer=$host.UI.RawUI.BufferSize.heigth)
609- $buffersize = new-object System.Management.Automation.Host.Size($x,$buffer)
610- $host.UI.RawUI.BufferSize = $buffersize
611- $size = New-Object System.Management.Automation.Host.Size($x,$y)
612- $host.ui.rawui.WindowSize = $size
613- }
614- # Windows10 yelling at us with 150 40 6000
615- # Set-WindowSize 195 40 6000
616-
617- ### Colorize to distinguish
618- $host.ui.RawUI.BackgroundColor = "Black"
619- $host.ui.RawUI.ForegroundColor = "White"
620- }
621- """
622- self .create_batch_script ("WinPython_PS_Prompt.ps1" , ps1_content , replacements = batch_replacements )
623-
518+ destination = self .winpy_dir / "scripts"
519+ for specials in ('env.bat' , 'WinPython_PS_Prompt.ps1' ):
520+ destspe = str (destination / specials )
521+ print ('destspe:' , destspe )
522+ utils .patch_sourcefile (destspe ,'{self.python_dir_name}' , self .python_dir_name )
523+ utils .patch_sourcefile (destspe ,'{self.winpython_version_name}' , self .winpython_version_name )
524+ utils .patch_sourcefile (destspe ,'{full_path_env_var}' , full_path_env_var )
525+ utils .patch_sourcefile (destspe ,'{full_path_ps_env_var}' , full_path_ps_env_var )
624526 self ._print_action_done ()
625527
626528
@@ -636,11 +538,6 @@ def _create_standard_batch_scripts(self):
636538 if self .distribution and (Path (self .distribution .target ) / r"lib-python\3\idlelib" ).is_dir ():
637539 batch_replacements .append ((r"\Lib\idlelib" , r"\lib-python\3\idlelib" ))
638540
639- self .create_batch_script ("readme.txt" , """These batch files are required to run WinPython icons.
640- These files should help the user writing his/her own
641- The environment variables are set-up in 'env.bat' and 'env_for_icons.bat'.""" ,
642- )
643-
644541 for ini_patch_script in [
645542 ("make_working_directory_be_not_winpython.bat" , "[active_environment" , "[inactive_environment" , "[inactive_environment_per_user]" , "[active_environment_per_user]" ),
646543 ("make_working_directory_be_winpython.bat" , "[active_environment" , "[inactive_environment" ),
@@ -692,8 +589,8 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:
692589 )
693590
694591 if remove_existing :
695- self ._create_initial_batch_scripts ()
696592 self ._copy_default_scripts ()
593+ self ._create_initial_batch_scripts ()
697594 self ._create_standard_batch_scripts ()
698595 self ._copy_launchers ()
699596
0 commit comments