Pip require venv script

This commit is contained in:
Isaac Shoebottom 2023-11-10 23:28:14 -04:00
parent 3e94eac0cf
commit 52a1d99dae

View File

@ -0,0 +1,38 @@
# Pip config location: C:\Users\{username}\AppData\Roaming\pip\pip.ini
$location = "$env:APPDATA\pip\pip.ini"
# Check if pip.ini exists
if (Test-Path $location) {
# If it exists, read it
$pipConfig = Get-Content $location
# Content for pip.ini
$newPipConfig = foreach ($line in $pipConfig) {
# If the line starts with "require-virtualenv"
if ($line.StartsWith("require-virtualenv")) {
# If it exists, toggle it
if($line.EndsWith("True")) {
$line.Replace("True", "False")
} else {
$line.Replace("False", "True")
}
} else {
# If it doesn't exist, just write the line
$line
}
}
Write-Host $pipConfig
Write-Host "-----------------"
Write-Host $newPipConfig
# Write the new content to the file
$newPipConfig | Out-File $location -Force
} else {
# If it doesn't exist, create it
New-Item -Path $location -ItemType File
Add-Content -Path $location -Value "[global]"
Add-Content -Path $location -Value "require-virtualenv = True"
}
# Command using python
# python -m pip config set global.require-virtualenv True