Skip to content

Packaging Python code with conda

Christian Fobel edited this page Aug 22, 2017 · 18 revisions

Table of Contents generated with DocToc

Most of the custom conda packages required for MicroDrop are hosted on the wheeler-mirofluidics and sci-bots channels. Starting with MicroDrop 2.8, plugins are also conda packages and they are hosted on their own microdrop-plugins channel.

Below are a few common commands that are useful for developing/building conda packages for MicroDrop.

Add channels

conda config --add channels conda-forge &
conda config --add channels wheeler-microfluidics &
conda config --add channels sci-bots

Show channels

conda config --show-sources

Install a local package in development mode

conda develop PATH_TO_PACKAGE

This works by creating a conda.pth file in site-packages.

Install build dependencies

conda install constructor conda-build git constructor-git nsis=3.0

Build a package

conda clean --source &
conda build .conda-recipe

By default, building a package using conda build requires an internet connection. See Building offline for instructions on how to build offline.

Note 1: Built packages are cached in the %CONDA_PREFIX%\conda-bld\win-32 directory.
Note 2: Running git clean --source is necessary to delete the git cache and prevent the package from being marked as a dev build (conda checks out a new branch if the cache exists). The cache is located at %CONDA_PREFIX%\conda-bld\git_cache\C_\Users\ryan\Documents\dev\python.

Building offline

Unfortunately, conda-build does not directly provide an "offline" mode (see here and here). However, this can be accomplished by specifying --override-channels and selecting a local channel that includes all required packages as described here.

Specifically, these steps may be followed to configure a local channel:

  1. Activate Conda environment (e.g., activate).
  2. Change directory into %CONDA_PREFIX%\pkgs: cd %CONDA_PREFIX%\pkgs
  3. Index pkgs directory as Conda channel: conda index
  4. Create a directory to act as local Conda channel, e.g.: mkdir C:\pkg-cache
  5. Link pkgs directory as win-32 in new package cache directory: mklink /J C:\pkg-cache\win-32 %CONDA_PREFIX%\pkgs
  6. Create an empty noarch directory in package cache directory (see [here][i5576] for info on why): mkdir C:\pkg-cache\noarch echo {} > C:\pkg-cache\noarch\repodata.json bzip2 -k C:\pkg-cache\noarch\repodata.json

To build using the local channel, run:

conda build <recipe path> --override-channels -c file:///C:/pkg-cache

Note The following command must be run to update the package index if new packages are installed into the Conda environment:

 cd %CONDA_PREFIX%\pkgs & conda index

Install package from local cache

You could use this, e.g., when you want to install a package that you have built using conda build .conda recipe.

conda install --use-local PACKAGE_NAME

Upload a package

anaconda upload -u wheeler-microfluidics XXX.tar.bz2

Build the MicroDrop installer (uses miniconda-recipe)

paver build_installer

Clone this wiki locally