-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathbehave.ps1
More file actions
62 lines (53 loc) · 1.29 KB
/
behave.ps1
File metadata and controls
62 lines (53 loc) · 1.29 KB
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
62
$BaseDir = $PSScriptRoot
$ReInitFlag = "reinit"
$OldPath = $Env:Path
function Find-Python {
$candidates = @("python3", "python", "py")
foreach ($cmd in $candidates) {
try {
$python = & $cmd -c "import sys; print(sys.executable)" 2>$null
if ($python) { return $cmd }
}
catch {}
}
throw "Python 3 not found on system."
}
function Command-Available {
param($Command)
try {
Get-Command $Command -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
function Env-Exists {
param($PythonCmd)
& $PythonCmd -m pipenv --venv 2>&1 | Out-Null
return $?
}
$PythonCmd = Find-Python
# Ensure pipenv is installed
if (-not (Command-Available pipenv)) {
Write-Host "Installing pipenv"
& $PythonCmd -m pip install pipenv --user
}
try {
Push-Location $BaseDir
if (Test-Path $ReInitFlag) {
Write-Host "Reinitializing"
& $PythonCmd -m pipenv --rm
Remove-Item $ReInitFlag
}
if (-not (Env-Exists $PythonCmd)) {
Write-Host "Creating pipenv with $PythonCmd"
& $PythonCmd -m pipenv --python $PythonCmd
& $PythonCmd -m pipenv sync
}
& $PythonCmd -m pipenv run behave @Args
}
finally {
Pop-Location
$Env:Path = $OldPath
}