/
check.ps1
96 lines (80 loc) · 1.73 KB
/
check.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function Check-CommandExists
{
param ($command)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try
{
if (Get-Command $command)
{
return
}
}
catch
{
Write-Host "ERROR: $command is required"
exit 1
}
finally
{
$ErrorActionPreference = $oldPreference
}
}
function Check-PythonVersion
{
$pythonVersion = &{python -V} 2>&1
$matches = [Regex]::Matches($pythonVersion, "[\d\.]+")
$isGreaterThan = [version]::Parse($matches[0].Value) -ge [version]::Parse("3.6.9")
if (-not $isGreaterThan)
{
Write-Host "ERROR: Darcy AI requires Python 3.6.9 or later"
exit 1
}
}
function Check-PythonPackage
{
param ($package)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try
{
python -c "import $package" 2>&1
return
}
catch
{
Write-Host "ERROR: Python package '$package' is required"
exit 1
}
finally
{
$ErrorActionPreference = $oldPreference
}
}
function Check-OpenCVVersion
{
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try
{
python -c 'import cv2; assert cv2.__version__ >= \"3.4.17.63\"' 2>&1
return
}
catch
{
Write-Host "ERROR: OpenCV 3.4.17.63 or later is required"
exit 1
}
finally
{
$ErrorActionPreference = $oldPreference
}
}
Check-CommandExists "python"
Check-PythonVersion
Check-CommandExists "docker"
Check-PythonPackage "cv2"
Check-OpenCVVersion
Check-PythonPackage "pycoral"
Check-PythonPackage "darcyai"
Write-Host "Darcy AI development environment is ready"