Building and Uploading Conda Packages

Conda packages are built using “recipes” that provide package metadata and build instructions. The conda recipes for the packages in the GoMSS Nowcast organization channel are stored in the project’s conda-recipes repository on Bitbucket. The sections below described two methods of creating conda recipes, building packages with them, and uploading those packages to the channel.

In order to be able to build packages and upload them to the project channel you need to install the conda-build and anaconda-client packages:

$ conda install conda-build anaconda-client

Building Conda Packages from PyPI

Reference: The Building conda packages with conda skeleton tutorial

The conda skeleton command provides a way to build package recipe files for Python packages that exist in the Python Package Index (PyPI). Here we’ll use the schedule package as an example of building a conda package based on a PyPI package and uploading it to the GoMSS Nowcast organization channel so that it can be installed via conda install.

  1. Run the conda skeleton command:

    $ cd conda-recipes/
    $ CONDA_BLD_PATH=/tmp/cbtmp conda skeleton pypi schedule
    

    After a bunch of output, the result will be a schedule directory containing 3 files:

    meta.yaml:

    Contains all the metadata in the recipe. Only the package name and package version sections are required; everything else is optional.

    bld.bat:

    Windows commands to build the package.

    build.sh:

    Linux and OS X commands to build the package.

  2. With the recipe files in place the package is built with:

    $ conda build --croot /tmp/cbtmp schedule
    

    After a lot of output, if the build is successful, it concludes with a message like:

    # If you want to upload this package to anaconda.org later, type:
    #
    # $ anaconda upload /home/doug/miniconda3/conda-bld/linux-64/schedule-0.3.2-py35_0.tar.bz2
    #
    # To have conda build upload to anaconda.org automatically, use
    # $ conda config --set anaconda_upload yes
    
  3. Upload the package to the channel use:

    $ anaconda upload -u gomss-nowcast /home/doug/miniconda3/conda-bld/linux-64/schedule-0.3.2-py35_0.tar.bz2
    
  4. Add the recipe files to the conda-recipes Mercurial repository, commit them, and push them to Bitbucket:

    $ hg add schedule
    $ hg commit -m"Add recipe for schedule-0.3.2 from PyPI."
    $ hg push
    

Building Conda Packages from Scratch

Reference: The Building conda packages from scratch tutorial

The nemo_nowcast package recipe was created from scratch. conda-recipes/nemo_nowcast contains two files:

  1. A README.md file to identify the recipe and its provenance:

    This is an artisanal, hand-crafted recipe.
    
  2. A meta.yaml file containing the recipe metadata and build instructions:

    # Conda package metadata for NEMO_Nowcast
    
    package:
      name: nemo_nowcast
      version: "0.3"
    
    build:
      number: 1
      script: python setup.py install
    
    source:
      hg_url: https://bitbucket.org/43ravens/nemo_nowcast
    
    requirements:
      build:
        - circus
        - python
        - pyyaml
    
      run:
        - python
    
    about:
      home: https://bitbucket.org/43ravens/nemo_nowcast
      license: Apache License, Version 2.0
      license_file: LICENSE
      summary: A framework for building NEMO ocean model nowcast automation systems.
    
    extra:
      maintainers:
       - Doug Latornell <doug.latornell@43ravens.ca>
    

The Building conda packages from scratch tutorial and meta.yaml file docs provide details of how to populate the sections of the meta.yaml file.

With the recipe files in place the package is built with:

$ cd conda-recipes
$ conda build --croot /tmp/cbtmp nemo-nowcast

After a lot of output, if the build is successful, it concludes with a message like:

Finished processing dependencies for NEMO-Nowcast==0.3
found egg dir: /home/doug/warehouse/conda_envs/_build/lib/python3.5/site-packages/NEMO_Nowcast-0.3-py3.5.egg
number of files: 20
Fixing permissions
Fixing permissions
BUILD END: nemo_nowcast-0.3-py35_1
Nothing to test for: nemo_nowcast-0.3-py35_1
# If you want to upload this package to anaconda.org later, type:
#
# $ anaconda upload /home/doug/miniconda3/conda-bld/linux-64/nemo_nowcast-0.3-py35_1.tar.bz2
#
# To have conda build upload to anaconda.org automatically, use
# $ conda config --set anaconda_upload yes

To upload the package to the channel use:

$ anaconda upload -u gomss-nowcast /home/doug/miniconda3/conda-bld/linux-64/nemo_nowcast-0.3-py35_1.tar.bz2

Don’t forget to add the recipe files to the conda-recipes Mercurial repository, commit them, and push them to Bitbucket:

$ hg add schedule
$ hg commit -m"Add recipe for nemo_nowcast tip from bitbucket."
$ hg push

Uploading Packages to the GoMSS-Nowcast Channel

To upload a package to the GoMSS Nowcast organization channel you need:

  • A personal anaconda.org account
  • Write access to the organization (contact Doug Latornell <doug.latornell@43ravens.ca> or another organization administrator)
  • The anaconda-client package installed (conda install anaconda-client)

Once you have built and tested a conda package, and authenticated into you personal anaconda.org account with the anaconda login command, you can upload your package with the command:

$ anaconda upload -u gomss-nowcast /path/to/package.tar

The -u gomss-nowcast option is required because anaconda upload defaults to using your personal account.