Debian Codegraph @

devtools/appveyor/install.ps1

raw
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 "2.7") {
11 $filename = "Miniconda2-latest-Windows-" + $platform_suffix + ".exe"
12 } else {
13 $filename = "Miniconda3-latest-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
46 function InstallMiniconda ($python_version, $architecture, $python_home) {
47 Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
48 if (Test-Path $python_home) {
49 Write-Host $python_home "already exists, skipping."
50 return $false
51 }
52 if ($architecture -match "32") {
53 $platform_suffix = "x86"
54 } else {
55 $platform_suffix = "x86_64"
56 }
57
58 $filepath = DownloadMiniconda $python_version $platform_suffix
59 Write-Host "Installing" $filepath "to" $python_home
60 $install_log = $python_home + ".log"
61 $args = "/S /D=$python_home"
62 Write-Host $filepath $args
63 Start-Process -FilePath $filepath -ArgumentList $args -Wait
64 if (Test-Path $python_home) {
65 Write-Host "Python $python_version ($architecture) installation complete"
66 } else {
67 Write-Host "Failed to install Python in $python_home"
68 Get-Content -Path $install_log
69 Exit 1
70 }
71 }
72
73
74 function InstallCondaPackages ($python_home, $spec) {
75 $conda_path = $python_home + "\Scripts\conda.exe"
76 $args = "install --yes --quiet $spec"
77 Write-Host ("conda " + $args)
78 Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait
79 }
80
81 function UpdateConda ($python_home) {
82 $conda_path = $python_home + "\Scripts\conda.exe"
83 Write-Host "Updating conda..."
84 $args = "update --yes --quiet conda"
85 Write-Host $conda_path $args
86 Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait
87 }
88
89
90 function main () {
91 InstallMiniconda $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
92 UpdateConda $env:PYTHON
93 InstallCondaPackages $env:PYTHON "conda-build pip jinja2 binstar"
94 }
95
96 main