aboutsummaryrefslogtreecommitdiff
path: root/vars/conda.groovy
blob: 7bb274f2b82c2026ee83ba74b52e041f0be16ef3 (plain) (blame)
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
// Shared functionality for managing conda installation.

def install(version="4.3.31", py_maj_version=3, install_dir="miniconda") {

    def CONDA_BASE_URL = "https://repo.continuum.io/miniconda"
    def conda_installers  = ["Linux-py2":"Miniconda2-4.5.4-Linux-x86_64.sh",
                             "Linux-py3":"Miniconda3-4.5.4-Linux-x86_64.sh",
                             "MacOSX-py2":"Miniconda2-4.5.4-MacOSX-x86_64.sh",
                             "MacOSX-py3":"Miniconda3-4.5.4-MacOSX-x86_64.sh"]
    def OSname = null
    def uname = sh(script: "uname", returnStdout: true).trim()
    if (uname == "Darwin") {
        OSname = "MacOSX"
        println("OSname=${OSname}")
    }
    if (uname == "Linux") {
        OSname = uname
        println("OSname=${OSname}")
    }
    assert uname != null

    // Check for the availability of a download tool and then use it
    // to get the conda installer.
    def dl_cmds = ["curl -OSs",
                   "wget --no-verbose --server-response --no-check-certificate"]
    def dl_cmd = null
    def stat1 = 999
    for (cmd in dl_cmds) {
        stat1 = sh(script: "which ${cmd.tokenize()[0]}", returnStatus: true)
        if( stat1 == 0 ) {
            dl_cmd = cmd
            break
        }
    }
    if (stat1 != 0) {
        println("Could not find a download tool. Unable to proceed.")
        return false
    }

    def WORKDIR = pwd()
    def conda_install_dir = "${WORKDIR}/${install_dir}"
    def conda_installer =
        conda_installers["${OSname}-py${py_maj_version}"]
    dl_cmd = dl_cmd + " ${CONDA_BASE_URL}/${conda_installer}"
    sh dl_cmd

    // Install specific version of miniconda
    sh "bash ./${conda_installer} -b -p ${conda_install_dir}"
    return true
}