Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 22 additions & 57 deletions winpython/portable/launchers_final/scripts/WinPython_PS_Prompt.ps1
Original file line number Diff line number Diff line change
@@ -1,57 +1,23 @@
### WinPython_PS_Prompt.ps1 ###
$0 = $myInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)

# default if env.cfg fails
$env:WINPYthon_subdirectory_name = "python"
$env:WINPYthon_exe = "python.exe"
# Define the path to the config file
Get-Content (${PSScriptRoot} +"\env.ini") | ForEach-Object {
$parts = $_ -split '=', 2
if ($parts.Count -eq 2) {
Set-Variable -Name ($parts[0]).Trim() -Value $parts[1].Trim() -Scope Global
}
}

# $env:PYTHONUTF8 = 1 would create issues in "movable" patching
$env:WINPYDIRBASE = "$dp0\.."
$env:WINPYDIRBASE = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) + "\.."
# get a normalize path
# http://stackoverflow.com/questions/1645843/resolve-absolute-path-from-relative-path-and-or-file-name
$env:WINPYDIRBASE = [System.IO.Path]::GetFullPath( $env:WINPYDIRBASE )

# avoid double_init (will only resize screen)
if (-not ($env:WINPYDIR -eq [System.IO.Path]::GetFullPath( $env:WINPYDIRBASE+"\{self.python_dir_name}")) ) {
$env:WINPYDIR = $env:WINPYDIRBASE+ "\" +$env:WINPYthon_subdirectory_name
$env:WINPYDIR = $env:WINPYDIRBASE+ "\python"
# 2019-08-25 pyjulia needs absolutely a variable PYTHON=%WINPYDIR%python.exe
$env:PYTHON = $env:WINPYthon_exe
$env:PYTHON = $env:WINPYDIRBASE+ "\python\python.exe"

$env:WINPYVER = $env:WINPYVER
# rem 2023-02-12 try utf-8 on console
# rem see https://github.com/pypa/pip/issues/11798#issuecomment-1427069681
$env:PYTHONIOENCODING = "utf-8"

$env:HOME = "$env:WINPYDIRBASE\settings"

$env:JUPYTER_DATA_DIR = "$env:HOME"

# keep Variables alive !
Set-Variable -Name "WINPYDIRBASE" -Value $env:WINPYDIRBASE -Scope Global
Set-Variable -Name "WINPYDIR" -Value $env:WINPYDIR -Scope Global
Set-Variable -Name "PYTHON" -Value $env:PYTHON -Scope Global
Set-Variable -Name "PYTHONIOENCODING" -Value $env:PYTHONIOENCODING -Scope Global
#Set-Variable -Name "HOME" -Value $env:HOME -Scope Global
Set-Variable -Name "JUPYTER_DATA_DIR" -Value $env:JUPYTER_DATA_DIR -Scope Global

if (-not $env:PATH.ToLower().Contains(";"+ $env:WINPYDIR.ToLower()+ ";")) {
$env:PATH = "$env:WINPYDIR\\Lib\site-packages\PyQt5;$env:WINPYDIR\\;$env:WINPYDIR\\DLLs;$env:WINPYDIR\\Scripts;$env:WINPYDIR\\..\t;$env:WINPYDIR\\..\n;$env:path" }

$env:PATH = "$env:WINPYDIR\Lib\site-packages\PyQt5;$env:WINPYDIR\;$env:WINPYDIR\DLLs;$env:WINPYDIR\Scripts;$env:WINPYDIR\..\t;$env:WINPYDIR\..\n;$env:path" }

#rem force default pyqt5 kit for Spyder if PyQt5 module is there
if (Test-Path "$env:WINPYDIR\Lib\site-packages\PyQt5\__init__.py") { $env:QT_API = "pyqt5" }

# PyQt5 qt.conf creation and winpython.ini creation done via Winpythonini.py (called per env_for_icons.bat for now)
# Start-Process -FilePath $env:PYTHON -ArgumentList ($env:WINPYDIRBASE + '\scripts\WinPythonIni.py')
$output = & 'python.exe' ($env:WINPYDIRBASE + '\scripts\WinPythonIni.py')
$output = & $env:PYTHON ($env:WINPYDIRBASE + '\scripts\WinPythonIni.py')
$pairs = $output -split '&&'
$pair = $pair -replace '^(?i)set\s+',''
foreach ($pair in $pairs) {
Expand All @@ -74,11 +40,6 @@ foreach ($pair in $pairs) {
# Unquote a quoted value (single or double quotes)
if ($value -match '^(["''])(.*)\1$') { $value = $Matches[2] }

# Basic validation for variable name (optional)
if ($name -notmatch '^[a-zA-Z_][a-zA-Z0-9_]*$') {
Write-Warning "Variable name '$name' is unusual. Still setting it, but consider sanitizing."
}

# Set as a PowerShell global variable
Set-Variable -Name $name -Value $value -Scope Global -Force

Expand All @@ -96,17 +57,21 @@ foreach ($pair in $pairs) {
#Write-Host "Set `$${name} = $value"
}

### Set-WindowSize
# directory of the running script (fallback to MyInvocation for older hosts)
$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Definition }

Function Set-WindowSize {
Param([int]$x=$host.ui.rawui.windowsize.width,
[int]$y=$host.ui.rawui.windowsize.heigth,
[int]$buffer=$host.UI.RawUI.BufferSize.heigth)
$buffersize = new-object System.Management.Automation.Host.Size($x,$buffer)
$host.UI.RawUI.BufferSize = $buffersize
$size = New-Object System.Management.Automation.Host.Size($x,$y)
$host.ui.rawui.WindowSize = $size
}
# Windows10 yelling at us with 150 40 6000
# Set-WindowSize 195 40 6000
}
# emulate %__CD% and build scripts\ path
$envCD = $env:__CD__
$scriptsPath = if ($envCD) { Join-Path $envCD 'scripts' } else { $null }

# target to change into (environment variable WINPYWORKDIR1)
$target = $WINPYWORKDIR1

if ($target) {
if ($scriptsPath -and $scriptDir -and ($scriptsPath -eq $scriptDir)) {
Set-Location -LiteralPath $target
}
elseif ($envCD -and $scriptDir -and ($envCD -eq $scriptDir)) {
Set-Location -LiteralPath $target
}
}
2 changes: 1 addition & 1 deletion winpython/portable/launchers_final/scripts/cmd_ps.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
call "%~dp0env_for_icons.bat"
rem call "%~dp0env_for_icons.bat"
Powershell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -noexit -File ""%~dp0WinPython_PS_Prompt.ps1""'}"