-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy-deploy.ps1
85 lines (77 loc) · 2.77 KB
/
py-deploy.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
param(
[switch] $help,
[string] $PythonInterpreterPrefix = "C:\Program Files",
[string] $venvPrefix = "",
[string[]] $CommonLibs,
[hashtable[]] $tasks
)
set usage -option constant -value @"
Usage
Deploy Python venv.
Parameters:
help
View this help.
PythonInterpreterPrefix
(Default: C:\Program Files)
If Python interpreters that are using to create venvs have a common path prefix, then you can specify it to reduce the char count when typing subsequent arguments.
venvPrefix
(Default: "")
if venv destination paths have a common path prefix, then you can specify it to reduce the char count when typing subsequent arguments.
CommonLibs
Libraries which should be installed in every venv
tasks
The format of tasks are hashtables which have the following keys:
srcdir
The directory where Python interpreter locates.
dstdir
The venv destination path.
libs
Libraries that should be installed in this venv
Examples:
[1]
./py-deploy -PythonInterpreterPrefix "C:/Program Files" -venvPrefix "out/build/x64-Release/bin/py/venv" ``
-tasks ``
@{
srcdir = "Python";
dstdir = "latest"
},
@{
srcdir = "Python3.8"
dstdir = "3.8"
libs = "jionlp"
} ``
-CommonLibs synonyms, jiagu, textrank4zh, jieba
[2]
`$BuildTypes = 'Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'
foreach (`$BuildType in `$BuildTypes) {
.\py-deploy -PythonInterpreterPrefix "C:\Program Files" -venvPrefix "out\build\x64-`$BuildType/bin/py/venv" ``
-CommonLibs synonyms, jiagu, textrank4zh, jieba ``
-tasks ``
@{
srcdir = "Python";
dstdir = "latest"
},
@{
srcdir = "Python3.8"
dstdir = "3.8"
libs = "jionlp"
}
}
"@
if (($help -eq $true) -or ($tasks.Length -eq 0)) {
echo $usage
exit
}
$cwd = $pwd
foreach ($task in $tasks) {
if ([string]::IsNullOrEmpty($PythonInterpreterPrefix) -eq $false) {
$task.srcdir = "$PythonInterpreterPrefix/$($task.srcdir)"
}
if ([string]::IsNullOrEmpty($venvPrefix) -eq -$false) {
$task.dstdir = "$venvPrefix/$($task.dstdir)"
}
&"$($task.srcdir)/python" -m venv $task.dstdir # create venv
&"$($task.dstdir)/scripts/python" -m pip install --upgrade pip # upgrade pip
&"$($task.dstdir)/scripts/python" -m pip install $CommonLibs $task.libs # pip install libraries
}
cd $cwd