-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.ps1
executable file
·61 lines (52 loc) · 1.85 KB
/
run.ps1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env pwsh
Set-StrictMode -Version 1.0
# Make script stop when an error happens
$ErrorActionPreference = "Stop"
$PYTHON_VENV_DIR = "venv_Md2Anki_pwsh"
$PYTHON_VENV_REQUIREMENTS_FILE = "requirements.txt"
$ACTIVATE_SCRIPT_PATH_WINDOWS = Join-Path $PSScriptRoot -ChildPath $PYTHON_VENV_DIR | Join-Path -ChildPath "Scripts" | Join-Path -ChildPath "Activate.ps1"
$ACTIVATE_SCRIPT_PATH_LINUX = Join-Path $PSScriptRoot -ChildPath $PYTHON_VENV_DIR | Join-Path -ChildPath "bin" | Join-Path -ChildPath "Activate.ps1"
# Enable usage on multiple operating systems even though the activation paths are different
if ($IsWindows) {
$ACTIVATE_SCRIPT_PATH = $ACTIVATE_SCRIPT_PATH_WINDOWS
} else {
$ACTIVATE_SCRIPT_PATH = $ACTIVATE_SCRIPT_PATH_LINUX
}
# Go to script directory even when run from another one
$CALL_DIR = $pwd
Set-Location -Path $PSScriptRoot
# (Create and) Enter virtual environment
if (-not (Test-Path -LiteralPath $PYTHON_VENV_DIR)) {
python -m venv $PYTHON_VENV_DIR
if (-not (Test-Path -LiteralPath $ACTIVATE_SCRIPT_PATH)) {
Write-Output "Activation script file not found: '$ACTIVATE_SCRIPT_PATH'"
exit 1
}
Invoke-Expression $ACTIVATE_SCRIPT_PATH
python -m pip install --upgrade pip
if (-not (Test-Path -LiteralPath $PYTHON_VENV_REQUIREMENTS_FILE)) {
Write-Output "Requirements file not found: '$PYTHON_VENV_REQUIREMENTS_FILE'"
exit 1
} else {
pip install -r $PYTHON_VENV_REQUIREMENTS_FILE
}
} else {
if (-not (Test-Path -LiteralPath $ACTIVATE_SCRIPT_PATH)) {
Write-Output "Activation script file not found: '$ACTIVATE_SCRIPT_PATH'"
exit 1
}
Invoke-Expression $ACTIVATE_SCRIPT_PATH
}
# Go back to the call directory
Set-Location -Path $CALL_DIR
# Run
try {
$PYTHON_FILE_PATH = Join-Path $PSScriptRoot -ChildPath "main.py"
python "$PYTHON_FILE_PATH" $args
}
catch {
return $LASTEXITCODE
}
finally {
deactivate
}