Creating Conda recipes on Windows - dstronczek/ilastik_py3win GitHub Wiki

Creating (or modifying) a conda recipe on Windows

0. Prerequisites

To create the recipe you only need a text editor. The process of building a packages is described here

1. Creating a new recipe

A conda recipe folder consists of the following files:

  • meta.yaml -- This file contains the necessary metadata for the conda package, like name, version, (git-)source and the prerequisite packages for building and running.
  • bld.bat -- This batch file contains the steps needed to compile the code in the package on Windows systems. It will be run during the build and usually calls python or cmake for the actual creation of the binaries.
  • build.sh-- This shell script is the Unix variant of the bld.bat. It usually contains the same steps and differs only in syntax and OS-specific flags.
  • (optionally) patch files -- These text files contain patches for the package's source code which are needed for the code to compile successfully. More info on patches can be found here.
  • (optionally) test files -- These files contain specific scripts for running tests (run_test.[py,pl,sh,bat]) or data needed for testing. Tests can be enabled in the meta.yaml.

You can either create a recipe from scratch by creating these files yourself or copy and modify an existing recipe.

2. The meta.yaml file

This file contains the metadata required by conda-build. An example file looks like this:

package:
  name: name_of_the_package
  version: "1.2.345.XYZ"

source:
  git_url: git://github.com/some_git_project/
  git_tag: Version-1-2-345
  # or using full hash code:
  # git_tag: 12c49b97db6b6c4f1944b36b5d6e15e626eae550 # master 2017/09/01
patches:
  - some_patch_only_for_windows.patch  # [win]

# this is a comment
requirements:
  build:
    - python                  3.5
    - other_package           1.2*
    - only_for_build                  # this is a second comment
    - only_on_unix            8b      # [not win]
    - different_for_windows   7x      # [win]
#   - no_longer_needed        0.123
  run:
    - python                  3.5
    - other_package           1.2*
    - only_on_unix            8b      # [not win]
    - different_for_windows   7x      # [win]
    - only_for_run            4.3.2

test:
  imports:
    - this_package
    - a_different_package

about:
  home: http://some.website.org
  license: XXX
  summary: A short description of the package

Most sections are self-explanatory, they are explained in more detail here. Using # [win] at the end of a line means that it will only be used if the recipe is built or installed on windows. Multiple variables exist that can be used to configure the recipe differently for different systems, a full list can be found here.

In some cases, the tests described in the meta.yaml file can fail even though the installation was successful. In other cases, conda-build sometimes builds the same packages twice, if the recipe is included in the source code. See here for possible solutions to this problem.

3. The bld.bat file

  • The content of the build file depends on the type of package. If it is a python-only package, the project should add the setuptools package as requirement and the file may simply look like this:

python setup.py install

  • If the package contains C code, a compiler, e.g. Microsoft Visual Studio, must be installed and cmake should be added to the required packages. The build file may then look like this:

mkdir build cd build

set CONFIGURATION=Release

cmake .. -G "%CMAKE_GENERATOR%" -DCMAKE_PREFIX_PATH="%LIBRARY_PREFIX%" -DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" if errorlevel 1 exit 1

cmake --build . --target ALL_BUILD --config %CONFIGURATION% if errorlevel 1 exit 1

cmake --build . --target INSTALL --config %CONFIGURATION% if errorlevel 1 exit 1

4. Running and Debugging the recipe

  • This page describes how to run conda-build with the created recipe.
  • This page describes how to debug the build and troubleshoot common errors in the recipe.