Creating a pySTEPS conda package

Here we will describe the steps to create an anaconda package for pySTEPS.

What is a “conda package”?

A conda package is a compressed tarball file that may contain:

  • python or other modules
  • executables
  • other important files

The package format is the same across platforms and their advantage is that Conda understands how to install these packages into a conda environment (regardless the platform where the package is installed) so that it may be available when that environment is active.

For more information about conda package, check the conda-build documentation

Building the pysteps conda package

Building a conda package requires installing conda-build and creating a conda recipe.

Before you start, make sure you have installed:

Conda recipe

Building a conda package requires a recipe. A conda build recipe is a flat directory that contains the following files:

  • meta.yaml: A file that contains all the metadata in the recipe.
  • build.sh: The script that installs the files for the package on macOS and Linux. It is executed using the bash command.
  • bld.bat: The build script that installs the files for the package on Windows. It is executed using cmd.
  • run_test.[py,pl,sh,bat]: An optional Python test file, a test script that runs automatically if it is part of the recipe.
  • Optional patches that are applied to the source.
  • Other resources that are not included in the source and cannot be generated by the build scripts. Examples are icon files, readme files and build notes.

Conda build process

The conda package is build using the conda-build command.

conda-build performs the following steps:

  1. Reads the metadata.
  2. Downloads the source into a cache.
  3. Extracts the source into the source directory.
  4. Applies any patches.
  5. Re-evaluates the metadata, if source need to fill any metadata values.
  6. Creates a build environment, and then installs the build dependencies there.
  7. Runs the build script. The current working directory is the source directory with environment variables set. The build script installs into the build environment.
  8. Performs some necessary post-processing steps, such as shebang and rpath.
  9. Creates a conda package containing all the files in the build environment that are new from step 5, along with the necessary conda package metadata.
  10. Tests the new conda package if the recipe includes tests:
    1. Deletes the build environment.
    2. Creates a test environment with the package and its dependencies.
    3. Runs the test scripts.

Build pysteps’s recipe

The conda recipe for pysteps is defined in the pysteps/conda_recipe/meta.yaml file. Before we actually build the package, let’s specify the build root folder where the build packages will be stored. This folder should be located outside the pysteps root:

export CONDA_BLD_PATH=$HOME/localStorage/conda_builds/

On a linux distribution, from the pystep root directory we can now build the conda package for two python versions (or more if you like):

conda build --python=3.6 conda_recipe/

conda build --python=3.7 conda_recipe/

The anaconda packages for each python version are stored in the $CONDA_BLD_PATH folder.

Upload the packages to the anaconda cloud

The final step is to upload the package to the anaconda cloud using:

anaconda upload <path_to_file_package>

Credits

The description of the conda build process was adapted from the official conda-build documentation (Copyright 2012 Continuum Analytics, Inc.)