install.ps1 6.85 KB
Newer Older
1
param ([Switch] $Development)
2
3
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

4

5
6
7
$install_node = $true
$install_yarn = $true

8
if ([Environment]::Is64BitOperatingSystem) {
9
    $OS_VERSION = 'win64'
Yuge Zhang's avatar
Yuge Zhang committed
10
    $nodeUrl = "https://nodejs.org/download/release/v10.22.1/node-v10.22.1-win-x64.zip"
11
}
12
else {
13
    $OS_VERSION = 'win32'
Yuge Zhang's avatar
Yuge Zhang committed
14
    $nodeUrl = "https://nodejs.org/download/release/v10.22.1/node-v10.22.1-win-x86.zip"
15
}
16
# nodejs
Yuge Zhang's avatar
Yuge Zhang committed
17
$yarnUrl = "https://github.com/yarnpkg/yarn/releases/download/v1.22.5/yarn-v1.22.5.tar.gz"
18
19
20
$unzipNodeDir = "node-v*"
$unzipYarnDir = "yarn-v*"

21
$NNI_DEPENDENCY_FOLDER = [System.IO.Path]::GetTempPath() + $env:USERNAME
22
23

$WHICH_PYTHON = where.exe python
24
if ($WHICH_PYTHON -eq $null) {
25
26
    throw "Can not find python"
}
27
else {
28
    $pyVersion = & python -V 2>&1
29
30
    $pyVersion = ([string]$pyVersion).substring(7, 3)
    if ([double]$pyVersion -lt 3.5) {
31
32
33
34
35
        throw "python version should >= 3.5"
    }
}

$WHICH_PIP = where.exe pip
36
if ($WHICH_PIP -eq $null) {
37
38
39
40
    throw "Can not find pip"
}

$env:PYTHONIOENCODING = "UTF-8"
41
if ($env:VIRTUAL_ENV) {
42
43
44
45
    $NNI_PYTHON3 = $env:VIRTUAL_ENV + "\Scripts"
    $NNI_PKG_FOLDER = $env:VIRTUAL_ENV + "\nni"
    $NNI_PYTHON_SCRIPTS = $NNI_PYTHON3
}
46
else {
47
48
    $NNI_PYTHON3 = $(python -c 'import site; from pathlib import Path; print(Path(site.getsitepackages()[0]))')
    $NNI_PKG_FOLDER = $NNI_PYTHON3 + "\nni"
49
    $NNI_PYTHON_SCRIPTS = $NNI_PYTHON3 + "\Scripts"
50
51
}

52
$PIP_INSTALL = """$NNI_PYTHON3\python"" -m pip install "
53

54
if (!(Test-Path $NNI_DEPENDENCY_FOLDER)) {
55
    $null = New-Item $NNI_DEPENDENCY_FOLDER -ItemType Directory
56
}
57
58
59
60
61
$NNI_NODE_ZIP = $NNI_DEPENDENCY_FOLDER + "\nni-node.zip"
$NNI_NODE_FOLDER = $NNI_DEPENDENCY_FOLDER + "\nni-node"
$NNI_YARN_TARBALL = $NNI_DEPENDENCY_FOLDER + "\nni-yarn.tar.gz"
$NNI_YARN_FOLDER = $NNI_DEPENDENCY_FOLDER + "\nni-yarn"
$NNI_YARN = $NNI_YARN_FOLDER + "\bin\yarn"
62
63
64
65
66

## Version number
$NNI_VERSION_VALUE = $(git describe --tags)
$NNI_VERSION_TEMPLATE = "999.0.0-developing"

67
if (!(Test-Path $NNI_NODE_ZIP)) {
68
69
70
71
    Write-Host "Downloading Node..."
    (New-Object Net.WebClient).DownloadFile($nodeUrl, $NNI_NODE_ZIP)
}

72
if (!(Test-Path $NNI_YARN_TARBALL)) {
73
74
75
76
77
78
79
    Write-Host "Downloading Yarn..."
    (New-Object Net.WebClient).DownloadFile($yarnUrl, $NNI_YARN_TARBALL)
}

$NNI_YARN_TARBALL = $NNI_YARN_TARBALL -split '\\' -join '\\'
$NNI_DEPENDENCY_FOLDER = $NNI_DEPENDENCY_FOLDER -split '\\' -join '\\'
$SCRIPT_PATH = $NNI_DEPENDENCY_FOLDER + '\extract.py'
80
81
82
$SCRIPT = "import tarfile",
        ("tar = tarfile.open(""{0}"")" -f $NNI_YARN_TARBALL),
        ("tar.extractall(""{0}"")" -f $NNI_DEPENDENCY_FOLDER),
83
84
85
86
        "tar.close()"
[System.IO.File]::WriteAllLines($SCRIPT_PATH, $SCRIPT)

Add-Type -AssemblyName System.IO.Compression.FileSystem
87
function Unzip {
88
89
90
91
92
    param([string]$zipfile, [string]$outpath)
    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
if ($install_node) {
    ### nodejs install
93
    if (!(Test-Path $NNI_NODE_FOLDER)) {
94
95
96
97
98
        Unzip $NNI_NODE_ZIP $NNI_DEPENDENCY_FOLDER
        $unzipNodeDir = Get-ChildItem "$NNI_DEPENDENCY_FOLDER\$unzipNodeDir"
        Rename-Item $unzipNodeDir "nni-node"
    }
    Copy-Item "$NNI_NODE_FOLDER\node.exe" $NNI_PYTHON_SCRIPTS -Recurse -Force
99
100
101
}

if ($install_yarn) {
102
    ### yarn install
103
    if (!(Test-Path $NNI_YARN_FOLDER)) {
104
105
106
107
108
109
110
111
112
        cmd /C """$NNI_PYTHON3\python""" $SCRIPT_PATH
        $unzipYarnDir = Get-ChildItem "$NNI_DEPENDENCY_FOLDER\$unzipYarnDir"
        Rename-Item $unzipYarnDir "nni-yarn"
    }
}

## install-python-modules:
### Installing Python SDK
(Get-Content setup.py).replace($NNI_VERSION_TEMPLATE, $NNI_VERSION_VALUE) | Set-Content setup.py
113
114
115

if ($Development) {
    $PYTHON_BUILD = "build"
116
117
118
119
120
121
122
123
124
125
    # To compat with file and links.
    cmd /c if exist "$PYTHON_BUILD" rmdir /s /q $PYTHON_BUILD

    $null = New-Item $PYTHON_BUILD -ItemType Directory
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni" -Target "src\sdk\pynni\nni"
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nnicli" -Target "src\sdk\pycli\nnicli"
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_annotation" -Target "tools\nni_annotation"
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_cmd" -Target "tools\nni_cmd"
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_trial_tool" -Target "tools\nni_trial_tool"
    $null = New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_gpu_tool" -Target "tools\nni_gpu_tool"
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

    Copy-Item setup.py $PYTHON_BUILD
    Copy-Item README.md $PYTHON_BUILD

    Push-Location build
    #update folders in setup file
    (Get-Content setup.py).replace("src/sdk/pynni/", "") | Set-Content setup.py
    (Get-Content setup.py).replace("src/sdk/pycli/", "") | Set-Content setup.py
    (Get-Content setup.py).replace("src/sdk/pynni", ".") | Set-Content setup.py
    (Get-Content setup.py).replace("tools/", "") | Set-Content setup.py
    # install current folder.
    cmd /c $PIP_INSTALL -e .
    Pop-Location
}
else {
    cmd /c $PIP_INSTALL .
}
143
144

# Building NNI Manager
145
$env:PATH = $NNI_PYTHON_SCRIPTS + ';' + $env:PATH
146
147
148
149
150
cd src\nni_manager
cmd /c $NNI_YARN
cmd /c $NNI_YARN build
Copy-Item config -Destination .\dist\ -Recurse -Force
# Building WebUI
151
# office-ui-fabric-react need longer time. the 180000 is in ms, mean 180 seconds, longer than default 30 seconds.
152
cd ..\webui
153
cmd /c $NNI_YARN --network-timeout 180000
154
cmd /c $NNI_YARN build
SparkSnail's avatar
SparkSnail committed
155
156
# Building NasUI
cd ..\nasui
157
cmd /c $NNI_YARN --network-timeout 180000
SparkSnail's avatar
SparkSnail committed
158
cmd /c $NNI_YARN build
159
160
161
162

cd ..\..

## install-node-modules
163
164
165

# it needs to remove the whole folder for following copy.
cmd /c if exist "$NNI_PKG_FOLDER" rmdir /s /q $NNI_PKG_FOLDER
166
167
168
169

$NNI_PKG_FOLDER_STATIC = $NNI_PKG_FOLDER + "\static"
$NASUI_PKG_FOLDER = $NNI_PKG_FOLDER + "\nasui"

170
171
172
173
cmd /c if exist "src\nni_manager\dist\node_modules" rmdir /s /q src\nni_manager\dist\node_modules
cmd /c if exist "src\nni_manager\dist\static" rmdir /s /q src\nni_manager\dist\static
cmd /c if exist "src\nni_manager\dist\nasui" rmdir /s /q src\nni_manager\dist\nasui

174
if ($Development) {
175
176
177
178
179
    $null = New-Item -ItemType Junction -Path $NNI_PKG_FOLDER -Target "src\nni_manager\dist"

    $null = New-Item -ItemType Junction -Path "$($NNI_PKG_FOLDER)\node_modules" -Target "src\nni_manager\node_modules"
    $null = New-Item -ItemType Junction -Path $NNI_PKG_FOLDER_STATIC -Target "src\webui\build"
    $null = New-Item -ItemType Junction -Path $NASUI_PKG_FOLDER -Target "src\nasui\build"
180
}
181
182
183
184
185
else {
    Copy-Item "src\nni_manager\dist" $NNI_PKG_FOLDER -Recurse
    Copy-Item "src\webui\build" $NNI_PKG_FOLDER_STATIC -Recurse
    Copy-Item "src\nasui\build" $NASUI_PKG_FOLDER -Recurse

186
187
188
    Copy-Item "src\nni_manager\package.json" $NNI_PKG_FOLDER
    $PKG_JSON = $NNI_PKG_FOLDER + "\package.json"
    (Get-Content $PKG_JSON).replace($NNI_VERSION_TEMPLATE, $NNI_VERSION_VALUE) | Set-Content $PKG_JSON
189
190
191

    cmd /c $NNI_YARN --prod --cwd $NNI_PKG_FOLDER
}
192
193

Copy-Item "src\nasui\server.js" $NASUI_PKG_FOLDER