From 30fb7c1049104c0d36b9c1259c364ec8ec303c84 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 13 Feb 2019 11:55:14 +0800 Subject: [PATCH] conda: add installation script for Hydra packages --- conda/install-artiq.py | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 conda/install-artiq.py diff --git a/conda/install-artiq.py b/conda/install-artiq.py new file mode 100644 index 000000000..00ac529c1 --- /dev/null +++ b/conda/install-artiq.py @@ -0,0 +1,63 @@ +# This script installs ARTIQ using the conda packages built by the new Nix/Hydra system. +# It needs to be run in the root (base) conda environment with "python install-artiq.py" +# It supports Linux and Windows, but it really is just an ugly collection of workarounds +# and conda is awful; if you are running Linux, you're better off using Nix which is not +# buggy and needs none of this mess. + +# EDIT THIS: +# The name of the conda environment to create +CONDA_ENV_NAME = "artiq" +# The conda packages to download from hydra and install. +# Each entry is ("hydra build name", "conda package name"). Hydra builds are: +# * main: core ARTIQ packages +# * sinara-systems: firmware and gateware builds for generic Sinara systems +CONDA_PACKAGES = [ + ("main", "artiq"), + ("main", "artiq-board-kc705-nist_clock"), + ("main", "artiq-board-kasli-tester"), + ("sinara-systems", "artiq-board-kasli-mitll") +] +# Set to False if you have already set up conda channels +ADD_CHANNELS = True + +# You should not need to modify the rest of the script below. + +import os +import tempfile + +def run(command): + r = os.system(command) + if r != 0: + raise SystemExit("command '{}' returned non-zero exit status: {}".format(command, r)) + +if ADD_CHANNELS: + run("conda config --add channels m-labs") + run("conda config --add channels conda-forge") +run("conda install -y conda-build curl") + +# Another silly conda decision is to ignore dependencies when installing .tar.bz2's directly. +# Work around it by creating a channel for our packages. +with tempfile.TemporaryDirectory() as channel_dir: + print("Creating conda channel in {channel_dir}...".format(channel_dir=channel_dir)) + previous_dir = os.getcwd() + os.chdir(channel_dir) + try: + os.mkdir("noarch") + # curl -OJL won't take the correct filename and it will save the output as "conda". + # wget --content-disposition is better-behaved but wget cannot be used on Windows. + # Amazingly, conda doesn't do something stupid when package files are renamed, + # so we can get away by generating our own names that don't contain the version number. + for hydra_build, package in CONDA_PACKAGES: + run("curl https://nixbld.m-labs.hk/job/artiq/{hydra_build}/conda-{package}/latest/download-by-type/file/conda -L -o noarch/{package}.tar.bz2" + .format(hydra_build=hydra_build, package=package)) + run("conda index") + + # Creating the environment first with python 3.5 hits fewer bugs in conda's broken dependency solver. + run("conda create -y -n {CONDA_ENV_NAME} python=3.5".format(CONDA_ENV_NAME=CONDA_ENV_NAME)) + for _, package in CONDA_PACKAGES: + # Do not activate the environment yet - otherwise "conda install" may not find the SSL module anymore on Windows. + # Installing into the environment from the outside works around this conda bug. + run("conda install -y -n {CONDA_ENV_NAME} -c {channel_dir} {package}" + .format(CONDA_ENV_NAME=CONDA_ENV_NAME, channel_dir=channel_dir, package=package)) + finally: + os.chdir(previous_dir)