Skip to content

Generating recipes for different ecosystems#

Rattler-Build has some builtin functionality to generate recipes for different (existing) ecosystems.

Currently we support the following ecosystems:

  • pypi (Python) - generates a recipe for a Python package
  • cran (R) - generates a recipe for an R package

To generate a recipe for a Python package, you can use the following command:

rattler-build generate-recipe pypi jinja2

This will generate a recipe for the jinja2 package from PyPI and print it to the console. To turn it into a recipe, you can either pipe the stdout to a file or use the -w flag. The -w flag will create a new folder with the recipe in it.

The PyPI recipe generation supports additional flags:

  • -w/--write write the recipe to a folder
  • -m/--use-mapping use the conda-forge PyPI name mapping (defaults to true)
  • -t/--tree generate recipes for all dependencies
  • --pypi-index-url specify one or more PyPI index URLs to use for recipe generation (comma-separated)

The --pypi-index-url option allows you to use alternative PyPI mirrors or private PyPI repositories. You can specify multiple URLs, and the system will try each in order until one succeeds. This is especially useful for organizations with private packages or in environments with limited internet access. You can also set the RATTLER_BUILD_PYPI_INDEX_URL environment variable.

# Use a custom PyPI index
rattler-build generate-recipe pypi --pypi-index-url https://my-custom-pypi.example.com/pypi my-package

# Use multiple PyPI indexes (will try each in order)
rattler-build generate-recipe pypi --pypi-index-url https://my-custom-pypi.example.com/pypi,https://pypi.org/pypi my-package

The generated recipe for jinja2 will look something like:

recipe.yaml
package:
  name: jinja2
  version: 3.1.4

source:
  - url: https://files.pythonhosted.org/packages/ed/55/39036716d19cab0747a5020fc7e907f362fbf48c984b14e62127f7e68e5d/jinja2-3.1.4.tar.gz
    sha256: 4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369

build:
  script: python -m pip install .

requirements:
  host:
    - flit_core <4
    - python >=3.7
    - pip
  run:
    - python >=3.7
    - markupsafe >=2.0
  # - babel >=2.7  # extra == 'i18n'

tests: []

about:
  summary: A very fast and expressive template engine.
  documentation: https://jinja.palletsprojects.com/

Generating recipes for R packages#

To generate a recipe for an R package, you can use the following command:

rattler-build generate-recipe cran dplyr

The R recipe generation supports some additional flags:

  • -u/--universe select an R universe to use (e.g. bioconductor)
  • -t/--tree also generate recipes for the dependencies that are not yet available in conda-forge (or the --check-available channels)
  • --all together with --tree, generate recipes for every dependency, available or not
  • --check-available <CHANNEL> check the dependencies against a channel instead of conda-forge (can be repeated), and warn about the ones it doesn't have
  • -m/--maintainer GitHub handle to list under extra.recipe-maintainers; can be given multiple times (e.g. -m your-handle -m co-maintainer). A placeholder is used otherwise.
  • --staged-recipes shape the recipe for a conda-forge staged-recipes submission: download through conda-forge's cran_mirror variant, leave out the skip condition for a minimum R version (conda-forge only builds for R versions that satisfy it), list ${{ stdlib("c") }} (${{ stdlib("m2w64_c") }} on Windows) next to the compilers of a compiled package (conda-forge's linter requires it), list the conda-forge/r team first under extra.recipe-maintainers so that it co-maintains the feedstock, and append the package's DESCRIPTION file as a comment block at the end of the recipe, which the conda-forge R team asks for so they can review the recipe against the upstream metadata. Such a recipe needs a variant config that defines cran_mirror, c_stdlib and m2w64_c_stdlib — conda-forge's pinning does, a plain rattler-build build does not.
# dplyr, plus recipes for its dependencies that are missing from conda-forge
rattler-build generate-recipe cran --tree dplyr
# check against bioconda and conda-forge instead
rattler-build generate-recipe cran --tree --check-available conda-forge --check-available bioconda dplyr

R packages will be prefixed with r- to avoid name conflicts with Python packages. The generated recipe follows the conventions of conda-forge's R recipes:

  • The version lives in context, and the source URLs are built from it. They point at https://cloud.r-project.org — the mirror conda-forge pins cran_mirror to — with CRAN's Archive/ directory listed as a fallback for superseded versions. rattler-build itself defines no cran_mirror, so the mirror is named in the recipe unless --staged-recipes is given.
  • When the package declares a minimum R version (e.g. Depends: R (>= 4.1.0)), the generator emits a skip condition using the r_base variant key rather than pinning r-base to a version. Such a recipe needs an r_base variant to build (conda-forge provides one); without it the skip condition evaluates to true and the output is skipped.
  • Pure-R packages are noarch: generic and built with ${{ R }} CMD INSTALL --build .. Packages with compiled code get the C compiler, plus the C++ and Fortran compilers when the source tarball has C++ or Fortran files under src/ (C++ is assumed when the tarball cannot be fetched). On Windows these are the MinGW compilers (${{ compiler("m2w64_c") }} and the like) together with the MSYS2 tools R CMD INSTALL runs (m2-make, m2-sed, …), as on conda-forge, so a Windows build needs a variant config that defines the m2w64_*_compiler keys. Compiled packages also get cross-r-base for cross-compilation, rpaths, and a platform-conditional build script that passes ${R_ARGS} (Unix) or %R_ARGS% (Windows) through to R CMD INSTALL. Their script calls a bare R, so that the shell picks the R of the build platform when cross-compiling; ${{ R }} would name the R of the host prefix, which cannot run there.
  • The src/Makevars* files of a compiled package decide its native host requirements: $(BLAS_LIBS) or $(LAPACK_LIBS) adds both libblas and liblapack, and R's OpenMP flags ($(SHLIB_OPENMP_CFLAGS) and the like) add the OpenMP runtime: llvm-openmp on macOS and libgomp elsewhere. Other system libraries, which a package names in its free-form SystemRequirements field, must be added by hand.
  • Packages listed under Suggests are added as comments to the run requirements. If the package ships a testthat runner (tests/testthat.R), a test that runs it is generated next to the r: test that loads the library.

The generated recipe for dplyr will look something like:

recipe.yaml
schema_version: 1

context:
  version: "1.2.1"

package:
  name: r-dplyr
  version: ${{ version }}

source:
  url:
    - https://cloud.r-project.org/src/contrib/dplyr_${{ version }}.tar.gz
    - https://cloud.r-project.org/src/contrib/Archive/dplyr/dplyr_${{ version }}.tar.gz
  sha256: 18d66fe2f24cda8b619c177326d39dd015229ab99695fa67d3fa31e4569390e0

build:
  number: 0
  skip: match(r_base, "<4.1")
  script:
    - if: win
      then: R CMD INSTALL --build . %R_ARGS%
      else: R CMD INSTALL --build . ${R_ARGS}
  dynamic_linking:
    rpaths:
      - lib/R/lib/
      - lib/

requirements:
  build:
    - if: build_platform != target_platform
      then:
        - cross-r-base ${{ r_base }}.*
    - ${{ compiler("c") }}
    - ${{ compiler("cxx") }}
    - make
  host:
    - r-base
    - r-cli >=3.6.2
    - r-generics
    - r-glue >=1.3.2
    - r-lifecycle >=1.0.5
    - r-magrittr >=1.5
    - r-pillar >=1.9.0
    - r-r6
    - r-rlang >=1.1.7
    - r-tibble >=3.2.0
    - r-tidyselect >=1.2.0
    - r-vctrs >=0.7.1
  run:
    - r-base
    - r-cli >=3.6.2
    - r-generics
    - r-glue >=1.3.2
    - r-lifecycle >=1.0.5
    - r-magrittr >=1.5
    - r-pillar >=1.9.0
    - r-r6
    - r-rlang >=1.1.7
    - r-tibble >=3.2.0
    - r-tidyselect >=1.2.0
    - r-vctrs >=0.7.1
    # - r-broom  # suggested
    # - r-covr  # suggested
    # - r-dbi  # suggested
    # - r-dbplyr >=2.2.1  # suggested
    # - r-ggplot2  # suggested
    # - r-knitr  # suggested
    # - r-lahman  # suggested
    # - r-lobstr  # suggested
    # - r-nycflights13  # suggested
    # - r-purrr  # suggested
    # - r-rmarkdown  # suggested
    # - r-rsqlite  # suggested
    # - r-stringi >=1.7.6  # suggested
    # - r-testthat >=3.1.5  # suggested
    # - r-tidyr >=1.3.0  # suggested
    # - r-withr  # suggested

tests:
  - r:
      libraries:
        - dplyr
  - files:
      source:
        - tests/
    requirements:
      run:
        - r-testthat >=3.1.5
    script:
      - Rscript -e "testthat::test_file('tests/testthat.R', stop_on_failure=TRUE)"

about:
  homepage: https://dplyr.tidyverse.org
  summary: A Grammar of Data Manipulation
  description: |-
    A fast, consistent tool for working with data frame like
    objects, both in memory and out of memory.
  license: MIT
  license_file:
    - ${{ PREFIX }}/lib/R/share/licenses/MIT
    - LICENSE
  repository: https://github.com/tidyverse/dplyr
  documentation: https://dplyr.tidyverse.org

extra:
  recipe-maintainers:
    - AddYourGitHubIdHere

Tip

You can use the generated recipes to build your own "forge" with Rattler-Build. Read more about it in the Building your own forge section.