-
Notifications
You must be signed in to change notification settings - Fork 10
/
FP_Windows_Install.ps1
127 lines (99 loc) · 4 KB
/
FP_Windows_Install.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$ErrorActionPreference = "Stop"
# Name of application to install
$AppName="FastProject"
# Set your project's install directory name here
$InstallDir="FastProject"
# Dependencies installed by Conda
# Commend out the next line if no Conda dependencies
$CondaDeps="numpy=1.11","scipy=0.18","scikit-learn=0.18.1","pandas=0.19"
# Dependencies installed with pip instead
# Comment out the next line if no PyPi dependencies
$PyPiPackage="FastProject"
# Local packages to install
# Useful if your application is not in PyPi
# Distribute this with a .tar.gz and use this variable
# Comment out the next line if no local package to install
# $LocalPackage="FastProject-0.9.2.tar.gz"
# Entry points to add to the path
# Comment out the next line of no entry point
# (Though not sure why this script would be useful otherwise)
$EntryPoint="fastproject"
Write-Host ("`nInstalling $AppName to "+(get-location).path+"\$InstallDir")
# Download Latest Miniconda Installer
Write-Host "`nDownloading Miniconda Installer...`n"
(New-Object System.Net.WebClient).DownloadFile("https://repo.continuum.io/miniconda/Miniconda-latest-Windows-x86_64.exe", "$pwd\Miniconda_Install.exe")
# Install Python environment through Miniconda
Write-Host "Installing Miniconda...`n"
Start-Process Miniconda_Install.exe "/S /AddToPath=0 /D=$pwd\$InstallDir" -Wait
# Install Dependences to the new Python environment
$env:Path = "$pwd\$InstallDir\Scripts;" + $env:Path
# Make the new python environment completely independent
# Modify the site.py file so that USER_SITE is not imported
$site_program = @"
import site
site_file = site.__file__.replace('.pyc', '.py');
with open(site_file) as fin:
lines = fin.readlines();
for i,line in enumerate(lines):
if(line.find('ENABLE_USER_SITE = None') > -1):
user_site_line = i;
break;
lines[user_site_line] = 'ENABLE_USER_SITE = False\n'
with open(site_file,'w') as fout:
fout.writelines(lines)
"@
python -c $site_program
if(Test-Path variable:CondaDeps)
{
Write-Host "Installing Conda dependencies...`n"
conda install $CondaDeps -y -c defaults --override-channels
}
if(Test-Path variable:PyPiPackage)
{
Write-Host "Installing PyPi dependencies...`n"
pip install $PyPiPackage
}
if(Test-Path variable:LocalPackage)
{
Write-Host "Installing Local package...`n"
pip install $LocalPackage
}
# Cleanup
Remove-Item "Miniconda_Install.exe"
conda clean -iltp --yes
# Add Entry Point to path
if(Test-Path variable:EntryPoint)
{
# Move entry-point executable to an isolated folder
$script_folder = "$pwd\$InstallDir\PathScripts"
New-Item $script_folder -type directory | Out-Null
Move-Item $pwd\$InstallDir\Scripts\$EntryPoint.exe $script_folder
# Ask user if they want to update path
$title = "Update Path"
$message = "`nDo you want to add the $EntryPoint script to your User PATH?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Prepends the User PATH variable with the location of the $EntryPoint script"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"User PATH is not modified"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
if($result -eq 0)
{
# Update the user's path
$old_path = (Get-ItemProperty -Path HKCU:\Environment).Path
$new_path = $script_folder + ";" + $old_path
cmd /c "setx PATH $new_path"
Set-ItemProperty -Path HKCU:\Environment -Name PATH -Value $new_path
Write-Host "User PATH has been updated"
Write-Host "Open a new command prompt to see the change"
}
else
{
Write-Host "User PATH was not modified.`n"
Write-Host "You may want to add the $EntryPoint script to your path."
Write-Host "It is located in: $script_folder`n"
}
}
Write-Host "`n$AppName Successfully Installed"
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")