Skip to content

Commit 99ff831

Browse files
committed
simplify WinPython_PS_Prompt.ps1
1 parent e639d17 commit 99ff831

File tree

1 file changed

+2
-56
lines changed

1 file changed

+2
-56
lines changed
Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,22 @@
11
### WinPython_PS_Prompt.ps1 ###
2-
$0 = $myInvocation.MyCommand.Definition
3-
$dp0 = [System.IO.Path]::GetDirectoryName($0)
42

5-
# default if env.cfg fails
6-
$env:WINPYthon_subdirectory_name = "python"
7-
$env:WINPYthon_exe = "python.exe"
8-
# Define the path to the config file
9-
Get-Content (${PSScriptRoot} +"\env.ini") | ForEach-Object {
10-
$parts = $_ -split '=', 2
11-
if ($parts.Count -eq 2) {
12-
Set-Variable -Name ($parts[0]).Trim() -Value $parts[1].Trim() -Scope Global
13-
}
14-
}
15-
16-
# $env:PYTHONUTF8 = 1 would create issues in "movable" patching
17-
$env:WINPYDIRBASE = "$dp0\.."
3+
$env:WINPYDIRBASE = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) + "\.."
184
# get a normalize path
19-
# http://stackoverflow.com/questions/1645843/resolve-absolute-path-from-relative-path-and-or-file-name
205
$env:WINPYDIRBASE = [System.IO.Path]::GetFullPath( $env:WINPYDIRBASE )
216

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

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

33-
$env:HOME = "$env:WINPYDIRBASE\settings"
34-
35-
$env:JUPYTER_DATA_DIR = "$env:HOME"
36-
37-
# keep Variables alive !
38-
Set-Variable -Name "WINPYDIRBASE" -Value $env:WINPYDIRBASE -Scope Global
39-
Set-Variable -Name "WINPYDIR" -Value $env:WINPYDIR -Scope Global
40-
Set-Variable -Name "PYTHON" -Value $env:PYTHON -Scope Global
41-
Set-Variable -Name "PYTHONIOENCODING" -Value $env:PYTHONIOENCODING -Scope Global
42-
#Set-Variable -Name "HOME" -Value $env:HOME -Scope Global
43-
Set-Variable -Name "JUPYTER_DATA_DIR" -Value $env:JUPYTER_DATA_DIR -Scope Global
44-
4514
if (-not $env:PATH.ToLower().Contains(";"+ $env:WINPYDIR.ToLower()+ ";")) {
4615
$env:PATH = "$env:WINPYDIR\\Lib\site-packages\PyQt5;$env:WINPYDIR\\;$env:WINPYDIR\\DLLs;$env:WINPYDIR\\Scripts;$env:WINPYDIR\\..\t;$env:WINPYDIR\\..\n;$env:path" }
4716

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

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

77-
# Basic validation for variable name (optional)
78-
if ($name -notmatch '^[a-zA-Z_][a-zA-Z0-9_]*$') {
79-
Write-Warning "Variable name '$name' is unusual. Still setting it, but consider sanitizing."
80-
}
81-
8243
# Set as a PowerShell global variable
8344
Set-Variable -Name $name -Value $value -Scope Global -Force
8445

@@ -95,18 +56,3 @@ foreach ($pair in $pairs) {
9556

9657
#Write-Host "Set `$${name} = $value"
9758
}
98-
99-
### Set-WindowSize
100-
101-
Function Set-WindowSize {
102-
Param([int]$x=$host.ui.rawui.windowsize.width,
103-
[int]$y=$host.ui.rawui.windowsize.heigth,
104-
[int]$buffer=$host.UI.RawUI.BufferSize.heigth)
105-
$buffersize = new-object System.Management.Automation.Host.Size($x,$buffer)
106-
$host.UI.RawUI.BufferSize = $buffersize
107-
$size = New-Object System.Management.Automation.Host.Size($x,$y)
108-
$host.ui.rawui.WindowSize = $size
109-
}
110-
# Windows10 yelling at us with 150 40 6000
111-
# Set-WindowSize 195 40 6000
112-
}

0 commit comments

Comments
 (0)