Skip to content

Commit

Permalink
improve windows install scripts (microsoft#2470)
Browse files Browse the repository at this point in the history
1. Reduce error message if deleted folder not exists.
2. Reduce unneccessary messages.
3. Organize logic better for reinstall scenario.
  • Loading branch information
squirrelsc authored Jun 10, 2020
1 parent 345684d commit 74e5ea9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
54 changes: 28 additions & 26 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else {
$PIP_INSTALL = """$NNI_PYTHON3\python"" -m pip install "

if (!(Test-Path $NNI_DEPENDENCY_FOLDER)) {
New-Item $NNI_DEPENDENCY_FOLDER -ItemType Directory
$null = New-Item $NNI_DEPENDENCY_FOLDER -ItemType Directory
}
$NNI_NODE_ZIP = $NNI_DEPENDENCY_FOLDER + "\nni-node.zip"
$NNI_NODE_FOLDER = $NNI_DEPENDENCY_FOLDER + "\nni-node"
Expand Down Expand Up @@ -112,17 +112,16 @@ if ($install_yarn) {

if ($Development) {
$PYTHON_BUILD = "build"
if (Test-Path $PYTHON_BUILD) {
# To compat with file and links.
cmd /c rmdir /s /q $PYTHON_BUILD
}
New-Item $PYTHON_BUILD -ItemType Directory
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni" -Target "src\sdk\pynni\nni"
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nnicli" -Target "src\sdk\pycli\nnicli"
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_annotation" -Target "tools\nni_annotation"
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_cmd" -Target "tools\nni_cmd"
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_trial_tool" -Target "tools\nni_trial_tool"
New-Item -ItemType Junction -Path "$($PYTHON_BUILD)\nni_gpu_tool" -Target "tools\nni_gpu_tool"
# 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"

Copy-Item setup.py $PYTHON_BUILD
Copy-Item README.md $PYTHON_BUILD
Expand Down Expand Up @@ -160,31 +159,34 @@ cmd /c $NNI_YARN build
cd ..\..

## install-node-modules
if (Test-Path $NNI_PKG_FOLDER) {
# it needs to remove the whole folder for following copy.
cmd /c rmdir /s /q $NNI_PKG_FOLDER
}

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

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

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

if ($Development) {
New-Item -ItemType Junction -Path $($NNI_PKG_FOLDER) -Target "src\nni_manager\dist"
New-Item -ItemType Junction -Path "$($NNI_PKG_FOLDER)\node_modules" -Target "src\nni_manager\node_modules"
New-Item -ItemType Junction -Path $($NNI_PKG_FOLDER_STATIC) -Target "src\webui\build"
New-Item -ItemType Junction -Path $($NASUI_PKG_FOLDER) -Target "src\nasui\build"
$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"
}
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
}

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
Copy-Item "src\nasui\server.js" $NASUI_PKG_FOLDER -Recurse
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

if (!$Development) {
cmd /c $NNI_YARN --prod --cwd $NNI_PKG_FOLDER
}

Copy-Item "src\nasui\server.js" $NASUI_PKG_FOLDER
24 changes: 12 additions & 12 deletions uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ $env:PYTHONIOENCODING = "UTF-8"
if($env:VIRTUAL_ENV){
$NNI_PYTHON3 = $env:VIRTUAL_ENV + "\Scripts"
$NNI_PKG_FOLDER = $env:VIRTUAL_ENV + "\nni"
cmd /c del "$NNI_PYTHON3\node.exe"
cmd /c if exist "$NNI_PYTHON3\node.exe" del "$NNI_PYTHON3\node.exe"
}
else{
$NNI_PYTHON3 = $(python -c 'import site; from pathlib import Path; print(Path(site.getsitepackages()[0]))')
$NNI_PKG_FOLDER = $NNI_PYTHON3 + "\nni"
cmd /c del "$NNI_PYTHON3\Scripts\node.exe"
cmd /c if exist "$NNI_PYTHON3\Scripts\node.exe" del "$NNI_PYTHON3\Scripts\node.exe"
}

$PIP_UNINSTALL = """$NNI_PYTHON3\python"" -m pip uninstall -y "
$NNI_NODE_FOLDER = $NNI_DEPENDENCY_FOLDER+"\nni-node"
$NNI_YARN_FOLDER = $NNI_DEPENDENCY_FOLDER+"\nni-yarn"

# uninstall
cmd /c rmdir /s /q $NNI_PKG_FOLDER
cmd /c if exist "$NNI_PKG_FOLDER" rmdir /s /q $NNI_PKG_FOLDER
cmd /c $PIP_UNINSTALL "nni"

# clean up
cmd /c rmdir /s /q "build"
cmd /c rmdir /s /q "src\nni_manager\dist"
cmd /c rmdir /s /q "src\nni_manager\node_modules"
cmd /c rmdir /s /q "src\webui\build"
cmd /c rmdir /s /q "src\webui\node_modules"
cmd /c rmdir /s /q "src\nasui\build"
cmd /c rmdir /s /q "src\nasui\node_modules"
cmd /c rmdir /s /q $NNI_YARN_FOLDER
cmd /c rmdir /s /q $NNI_NODE_FOLDER
cmd /c if exist "build" rmdir /s /q "build"
cmd /c if exist "src\nni_manager\dist" rmdir /s /q "src\nni_manager\dist"
cmd /c if exist "src\nni_manager\node_modules" rmdir /s /q "src\nni_manager\node_modules"
cmd /c if exist "src\webui\build" rmdir /s /q "src\webui\build"
cmd /c if exist "src\webui\node_modules" rmdir /s /q "src\webui\node_modules"
cmd /c if exist "src\nasui\build" rmdir /s /q "src\nasui\build"
cmd /c if exist "src\nasui\node_modules" rmdir /s /q "src\nasui\node_modules"
cmd /c if exist "$NNI_YARN_FOLDER" rmdir /s /q $NNI_YARN_FOLDER
cmd /c if exist "$NNI_NODE_FOLDER" rmdir /s /q $NNI_NODE_FOLDER

0 comments on commit 74e5ea9

Please sign in to comment.