1+ # Sample script to install Miniconda under Windows
2+ # Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner, Robert McGibbon
3+ # License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+ $MINICONDA_URL = " http://repo.continuum.io/miniconda/"
6+
7+
8+ function DownloadMiniconda ($python_version , $platform_suffix ) {
9+ $webclient = New-Object System.Net.WebClient
10+ if ($python_version -match " 3.4" ) {
11+ $filename = " Miniconda3-3.5.5-Windows-" + $platform_suffix + " .exe"
12+ } else {
13+ $filename = " Miniconda-3.5.5-Windows-" + $platform_suffix + " .exe"
14+ }
15+ $url = $MINICONDA_URL + $filename
16+
17+ $basedir = $pwd.Path + " \"
18+ $filepath = $basedir + $filename
19+ if (Test-Path $filename ) {
20+ Write-Host " Reusing" $filepath
21+ return $filepath
22+ }
23+
24+ # Download and retry up to 3 times in case of network transient errors.
25+ Write-Host " Downloading" $filename " from" $url
26+ $retry_attempts = 2
27+ for ($i = 0 ; $i -lt $retry_attempts ; $i ++ ){
28+ try {
29+ $webclient.DownloadFile ($url , $filepath )
30+ break
31+ }
32+ Catch [Exception ]{
33+ Start-Sleep 1
34+ }
35+ }
36+ if (Test-Path $filepath ) {
37+ Write-Host " File saved at" $filepath
38+ } else {
39+ # Retry once to get the error message if any at the last try
40+ $webclient.DownloadFile ($url , $filepath )
41+ }
42+ return $filepath
43+ }
44+
45+ function Start-Executable {
46+ param (
47+ [String ] $FilePath ,
48+ [String []] $ArgumentList
49+ )
50+ $OFS = " "
51+ $process = New-Object System.Diagnostics.Process
52+ $process.StartInfo.FileName = $FilePath
53+ $process.StartInfo.Arguments = $ArgumentList
54+ $process.StartInfo.UseShellExecute = $false
55+ $process.StartInfo.RedirectStandardOutput = $true
56+ if ( $process.Start () ) {
57+ $output = $process.StandardOutput.ReadToEnd () `
58+ -replace " \r\n$" , " "
59+ if ( $output ) {
60+ if ( $output.Contains (" `r`n " ) ) {
61+ $output -split " `r`n "
62+ }
63+ elseif ( $output.Contains (" `n " ) ) {
64+ $output -split " `n "
65+ }
66+ else {
67+ $output
68+ }
69+ }
70+ $process.WaitForExit ()
71+ & " $Env: SystemRoot \system32\cmd.exe" `
72+ / c exit $process.ExitCode
73+ }
74+ }
75+
76+ function InstallMiniconda ($python_version , $architecture , $python_home ) {
77+ Write-Host " Installing Python" $python_version " for" $architecture " bit architecture to" $python_home
78+ if (Test-Path $python_home ) {
79+ Write-Host $python_home " already exists, skipping."
80+ return $false
81+ }
82+ if ($architecture -match " 32" ) {
83+ $platform_suffix = " x86"
84+ } else {
85+ $platform_suffix = " x86_64"
86+ }
87+
88+ $filepath = DownloadMiniconda $python_version $platform_suffix
89+ Write-Host " Installing" $filepath " to" $python_home
90+ $install_log = $python_home + " .log"
91+ $args = " /S /D=$python_home "
92+ Write-Host $filepath $args
93+ Start-Process - FilePath $filepath - ArgumentList $args - Wait
94+ if (Test-Path $python_home ) {
95+ Write-Host " Python $python_version ($architecture ) installation complete"
96+ } else {
97+ Write-Host " Failed to install Python in $python_home "
98+ Get-Content - Path $install_log
99+ Exit 1
100+ }
101+ }
102+
103+
104+ function InstallCondaPackages ($python_home , $spec ) {
105+ $conda_path = $python_home + " \Scripts\conda.exe"
106+ $args = " install --yes --quiet " + $spec
107+ Write-Host (" conda " + $args )
108+ Start-Executable - FilePath " $conda_path " - ArgumentList $args
109+ }
110+ function InstallCondaPackagesFromFile ($python_home , $ver , $arch ) {
111+ $conda_path = $python_home + " \Scripts\conda.exe"
112+ $args = " install --yes --quiet --file C:\projects\pandas\ci\requirements-" + $ver + " _" + $arch + " .txt"
113+ Write-Host (" conda " + $args )
114+ Start-Executable - FilePath " $conda_path " - ArgumentList $args
115+ }
116+
117+ function UpdateConda ($python_home ) {
118+ $conda_path = $python_home + " \Scripts\conda.exe"
119+ Write-Host " Updating conda..."
120+ $args = " update --yes conda"
121+ Write-Host $conda_path $args
122+ Start-Process - FilePath " $conda_path " - ArgumentList $args - Wait
123+ }
124+
125+
126+ function main () {
127+ InstallMiniconda $env: PYTHON_VERSION $env: PYTHON_ARCH $env: PYTHON
128+ UpdateConda $env: PYTHON
129+ InstallCondaPackages $env: PYTHON " pip setuptools nose"
130+ InstallCondaPackagesFromFile $env: PYTHON $env: PYTHON_VERSION $env: PYTHON_ARCH
131+ }
132+
133+ main
0 commit comments