| 
 | 1 | +<#  | 
 | 2 | +.SYNOPSIS  | 
 | 3 | +Bootstrap Windows development environment for Kubernetes Python client.  | 
 | 4 | +
  | 
 | 5 | +.DESCRIPTION  | 
 | 6 | +Creates virtual environment (if missing), installs dependencies, and ensures  | 
 | 7 | +shim modules (config/dynamic/watch/stream/leaderelection) contain re-export  | 
 | 8 | +code replacing symlinks for Windows portability.  | 
 | 9 | +
  | 
 | 10 | +#>  | 
 | 11 | +param(  | 
 | 12 | +    [string]$Python = "py",  | 
 | 13 | +    [string]$Venv = ".venv"  | 
 | 14 | +)  | 
 | 15 | + | 
 | 16 | +$ErrorActionPreference = 'Stop'  | 
 | 17 | + | 
 | 18 | +function Write-Step($m){ Write-Host "[setup] $m" -ForegroundColor Cyan }  | 
 | 19 | + | 
 | 20 | +Write-Step "Python version"  | 
 | 21 | +& $Python -3 -c "import sys; print(sys.version)" | Write-Host  | 
 | 22 | + | 
 | 23 | +if(!(Test-Path $Venv)){  | 
 | 24 | +  Write-Step "Creating venv $Venv"  | 
 | 25 | +  & $Python -3 -m venv $Venv  | 
 | 26 | +}  | 
 | 27 | +Write-Step "Activating venv"  | 
 | 28 | +$activate = Join-Path $Venv 'Scripts/Activate.ps1'  | 
 | 29 | +. $activate  | 
 | 30 | + | 
 | 31 | +Write-Step "Upgrading pip"  | 
 | 32 | +python -m pip install --upgrade pip > $null  | 
 | 33 | + | 
 | 34 | +Write-Step "Installing requirements"  | 
 | 35 | +if(Test-Path requirements.txt){ pip install -r requirements.txt }  | 
 | 36 | +if(Test-Path test-requirements.txt){ pip install -r test-requirements.txt }  | 
 | 37 | + | 
 | 38 | +$shimMap = @{   | 
 | 39 | +  'kubernetes/config' = 'from kubernetes.base.config import *  # noqa: F401,F403';  | 
 | 40 | +  'kubernetes/dynamic' = 'from kubernetes.base.dynamic import *  # noqa: F401,F403';  | 
 | 41 | +  'kubernetes/watch' = 'from kubernetes.base.watch import *  # noqa: F401,F403';  | 
 | 42 | +  'kubernetes/stream' = 'from kubernetes.base.stream import *  # noqa: F401,F403';  | 
 | 43 | +  'kubernetes/leaderelection' = 'from kubernetes.base.leaderelection import *  # noqa: F401,F403'  | 
 | 44 | +}  | 
 | 45 | + | 
 | 46 | +foreach($path in $shimMap.Keys){  | 
 | 47 | +  if(Test-Path $path){  | 
 | 48 | +    $item = Get-Item $path  | 
 | 49 | +    if($item.PSIsContainer){ continue }  | 
 | 50 | +    $content = Get-Content $path -Raw  | 
 | 51 | +    if($content -notmatch 'kubernetes.base'){  | 
 | 52 | +      Write-Step "Updating shim $path"  | 
 | 53 | +      """Windows shim auto-generated`n$($shimMap[$path])""" | Out-File -FilePath $path -Encoding UTF8  | 
 | 54 | +    }  | 
 | 55 | +  } else {  | 
 | 56 | +    Write-Step "Creating shim file $path"  | 
 | 57 | +    """Windows shim auto-generated`n$($shimMap[$path])""" | Out-File -FilePath $path -Encoding UTF8  | 
 | 58 | +  }  | 
 | 59 | +}  | 
 | 60 | + | 
 | 61 | +Write-Step "Smoke import"  | 
 | 62 | +python - <<'PY'  | 
 | 63 | +from kubernetes import config, dynamic, watch, stream, leaderelection  | 
 | 64 | +print('Shim import success')  | 
 | 65 | +PY  | 
 | 66 | + | 
 | 67 | +Write-Step "Done"  | 
0 commit comments