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 packagecran(R) - generates a recipe for an R package
To generate a recipe for a Python package, you can use the following command:
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/--writewrite the recipe to a folder-m/--use-mappinguse the conda-forge PyPI name mapping (defaults to true)-t/--treegenerate recipes for all dependencies--pypi-index-urlspecify 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:
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:
The R recipe generation supports some additional flags:
-u/--universeselect an R universe to use (e.g.bioconductor)-t/--treealso generate recipes for the dependencies that are not yet available in conda-forge (or the--check-availablechannels)--alltogether 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/--maintainerGitHub handle to list underextra.recipe-maintainers; can be given multiple times (e.g.-m your-handle -m co-maintainer). A placeholder is used otherwise.--staged-recipesshape the recipe for a conda-forge staged-recipes submission: download through conda-forge'scran_mirrorvariant, leave out theskipcondition 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 theconda-forge/rteam first underextra.recipe-maintainersso that it co-maintains the feedstock, and append the package'sDESCRIPTIONfile 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 definescran_mirror,c_stdlibandm2w64_c_stdlib— conda-forge's pinning does, a plainrattler-build builddoes 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 athttps://cloud.r-project.org— the mirror conda-forge pinscran_mirrorto — with CRAN'sArchive/directory listed as a fallback for superseded versions.rattler-builditself defines nocran_mirror, so the mirror is named in the recipe unless--staged-recipesis given. - When the package declares a minimum R version (e.g.
Depends: R (>= 4.1.0)), the generator emits askipcondition using ther_basevariant key rather than pinningr-baseto a version. Such a recipe needs anr_basevariant to build (conda-forge provides one); without it theskipcondition evaluates to true and the output is skipped. - Pure-R packages are
noarch: genericand 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 undersrc/(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 toolsR CMD INSTALLruns (m2-make,m2-sed, …), as on conda-forge, so a Windows build needs a variant config that defines them2w64_*_compilerkeys. Compiled packages also getcross-r-basefor cross-compilation,rpaths, and a platform-conditional build script that passes${R_ARGS}(Unix) or%R_ARGS%(Windows) through toR CMD INSTALL. Their script calls a bareR, 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 nativehostrequirements:$(BLAS_LIBS)or$(LAPACK_LIBS)adds bothlibblasandliblapack, and R's OpenMP flags ($(SHLIB_OPENMP_CFLAGS)and the like) add the OpenMP runtime:llvm-openmpon macOS andlibgompelsewhere. Other system libraries, which a package names in its free-formSystemRequirementsfield, must be added by hand. - Packages listed under
Suggestsare added as comments to therunrequirements. If the package ships a testthat runner (tests/testthat.R), a test that runs it is generated next to ther:test that loads the library.
The generated recipe for dplyr will look something like:
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.