-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathenv.ps1
More file actions
30 lines (29 loc) · 975 Bytes
/
env.ps1
File metadata and controls
30 lines (29 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$VENV_ROOT = "$PSScriptRoot\.venv"
# rt-env目录是否存在
if (-not (Test-Path -Path $VENV_ROOT)) {
Write-Host "Create Python venv for RT-Thread..."
python -m venv $VENV_ROOT
# 激活python venv
& "$VENV_ROOT\Scripts\Activate.ps1"
# 安装env-script
# 判断IP是否在中国大陆,若是则用清华源,否则用默认源
try {
$china = $false
$ipinfo = Invoke-RestMethod -Uri "https://ipinfo.io/json" -UseBasicParsing -TimeoutSec 3
if ($ipinfo.country -eq "CN") {
$china = $true
}
} catch {
$china = $false
}
if ($china) {
Write-Host "Detected China Mainland IP, using Tsinghua PyPI mirror."
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple "$PSScriptRoot\tools\scripts"
} else {
pip install "$PSScriptRoot\tools\scripts"
}
} else {
# 激活python venv
& "$VENV_ROOT\Scripts\Activate.ps1"
}
$env:pathext = ".PS1;$env:pathext"