Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support variant variables in sources #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rattler_build_conda_compat/recipe_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str
if isinstance(template, list):
return [cast(str, render(t, context)) for t in template]
template = env.from_string(template)
return template.render(context_variables)
return template.render(context)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was actually a bug?


if override_version is not None:
recipe["context"]["version"] = override_version
Expand All @@ -138,7 +138,7 @@ def render(template: str | list[str], context: dict[str, str]) -> str | list[str

context = recipe.get("context", {})
# render out the context section and retrieve dictionary
context_variables = load_recipe_context(context, env)
context_variables = combination | load_recipe_context(context, env)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the variant variables are passed as context to the Source object below. Is this correct?


# now evaluate the if / else statements
sources = recipe.get("source")
Expand Down
35 changes: 21 additions & 14 deletions tests/__snapshots__/test_recipe_sources.ambr
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# serializer version: 1
# name: test_conditional_source_render
set({
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-linux.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_linux_version }}-linux.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='eb1a9aa834a969a8ccbbb04061274623659a1fb273abda4413b47fe59e7ee412', md5=None),
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-macos-arm64.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_osx_version }}-macos-arm64.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='fa96331edf06dd2342cb27771367516296067e94961ec6e600add1c2eed9c41d', md5=None),
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-windows.zip', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_win_version }}-windows.zip', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='e63c0b75d50097194c425489a08cec9c0374ab7b8eafe5b015c076bb2432fa19', md5=None),
Source(url='https://blpapi.bloomberg.com/repository/releases/python/blpapi-3.24.11.tar.gz', template='https://blpapi.bloomberg.com/repository/releases/python/${{ name }}-${{ version }}.tar.gz', context={'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='94dc699df262187b3afe4f163526aac67fb5982b008efe851836e9f1cd5358c1', md5=None),
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-linux.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_linux_version }}-linux.tar.gz', context={'c_stdlib': 'sysroot', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'gxx', 'cxx_compiler_version': '12', 'docker_image': 'quay.io/condaforge/linux-anvil-cos7-x86_64', 'target_platform': 'linux-64', 'c_stdlib_version': '2.17', 'cdt_name': 'cos7', 'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='eb1a9aa834a969a8ccbbb04061274623659a1fb273abda4413b47fe59e7ee412', md5=None),
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-macos-arm64.tar.gz', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_osx_version }}-macos-arm64.tar.gz', context={'MACOSX_DEPLOYMENT_TARGET': '11.0', 'MACOSX_SDK_VERSION': '11.0', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '11.0', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-arm64', 'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='fa96331edf06dd2342cb27771367516296067e94961ec6e600add1c2eed9c41d', md5=None),
Source(url='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_3.24.11.1-windows.zip', template='https://blpapi.bloomberg.com/download/releases/raw/files/blpapi_cpp_${{ blpapicpp_win_version }}-windows.zip', context={'c_stdlib': 'vs', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'vs2019', 'target_platform': 'win-64', 'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='e63c0b75d50097194c425489a08cec9c0374ab7b8eafe5b015c076bb2432fa19', md5=None),
Source(url='https://blpapi.bloomberg.com/repository/releases/python/blpapi-3.24.11.tar.gz', template='https://blpapi.bloomberg.com/repository/releases/python/${{ name }}-${{ version }}.tar.gz', context={'MACOSX_DEPLOYMENT_TARGET': '10.13', 'MACOSX_SDK_VERSION': '10.13', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '10.13', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-64', 'name': 'blpapi', 'version': '3.24.11', 'blpapicpp_linux_version': '3.24.11.1', 'blpapicpp_win_version': '3.24.11.1', 'blpapicpp_osx_version': '3.24.11.1'}, sha256='94dc699df262187b3afe4f163526aac67fb5982b008efe851836e9f1cd5358c1', md5=None),
})
# ---
# name: test_multi_source_render
set({
Source(url='https://all.com', template='https://all.com', context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url='https://all.com/foobar/1.2.3.zip', template='https://all.com/${{ name }}/${{ version }}.zip', context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url='https://foo.com', template='https://foo.com', context={'name': 'foobar', 'version': '1.2.3'}, sha256='679d42a76b82a6dc20ffd9048ab45fb2e5557a526113aaedc7419e12f3cfab38', md5=None),
Source(url='https://osx.com/osx-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None),
Source(url='https://osx.com/win-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None),
Source(url='https://win.com', template='https://win.com', context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None),
Source(url=['https://foo.com/linux-64/zip.zip', 'https://mirror.com/linux-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/osx-64/zip.zip', 'https://mirror.com/osx-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/osx-arm64/zip.zip', 'https://mirror.com/osx-arm64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/win-64/zip.zip', 'https://mirror.com/win-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None),
Source(url='https://all.com', template='https://all.com', context={'MACOSX_DEPLOYMENT_TARGET': '10.13', 'MACOSX_SDK_VERSION': '10.13', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '10.13', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url='https://all.com/foobar/1.2.3.zip', template='https://all.com/${{ name }}/${{ version }}.zip', context={'MACOSX_DEPLOYMENT_TARGET': '10.13', 'MACOSX_SDK_VERSION': '10.13', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '10.13', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url='https://foo.com', template='https://foo.com', context={'c_stdlib': 'sysroot', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'gxx', 'cxx_compiler_version': '12', 'docker_image': 'quay.io/condaforge/linux-anvil-cos7-x86_64', 'target_platform': 'linux-64', 'c_stdlib_version': '2.17', 'cdt_name': 'cos7', 'name': 'foobar', 'version': '1.2.3'}, sha256='679d42a76b82a6dc20ffd9048ab45fb2e5557a526113aaedc7419e12f3cfab38', md5=None),
Source(url='https://osx.com/osx-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'MACOSX_DEPLOYMENT_TARGET': '10.13', 'MACOSX_SDK_VERSION': '10.13', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '10.13', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None),
Source(url='https://osx.com/win-64/foo.zip', template='https://osx.com/${{ target_platform }}/foo.zip', context={'c_stdlib': 'vs', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'vs2019', 'target_platform': 'win-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='zzz', md5=None),
Source(url='https://win.com', template='https://win.com', context={'c_stdlib': 'vs', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'vs2019', 'target_platform': 'win-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None),
Source(url=['https://foo.com/linux-64/zip.zip', 'https://mirror.com/linux-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'c_stdlib': 'sysroot', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'gxx', 'cxx_compiler_version': '12', 'docker_image': 'quay.io/condaforge/linux-anvil-cos7-x86_64', 'target_platform': 'linux-64', 'c_stdlib_version': '2.17', 'cdt_name': 'cos7', 'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/osx-64/zip.zip', 'https://mirror.com/osx-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'MACOSX_DEPLOYMENT_TARGET': '10.13', 'MACOSX_SDK_VERSION': '10.13', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '10.13', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/osx-arm64/zip.zip', 'https://mirror.com/osx-arm64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'MACOSX_DEPLOYMENT_TARGET': '11.0', 'MACOSX_SDK_VERSION': '11.0', 'c_stdlib': 'macosx_deployment_target', 'c_stdlib_version': '11.0', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '16', 'macos_machine': 'x86_64-apple-darwin13.4.0', 'target_platform': 'osx-arm64', 'name': 'foobar', 'version': '1.2.3'}, sha256='yyy', md5=None),
Source(url=['https://foo.com/win-64/zip.zip', 'https://mirror.com/win-64/zip.zip'], template=['https://foo.com/${{ target_platform }}/zip.zip', 'https://mirror.com/${{ target_platform }}/zip.zip'], context={'c_stdlib': 'vs', 'channel_sources': 'conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'vs2019', 'target_platform': 'win-64', 'name': 'foobar', 'version': '1.2.3'}, sha256='xxx', md5=None),
})
# ---
# name: test_variant_variables_source_render
set({
Source(url='https://pypi.org/packages/source/p/polars-lts-cpu/polars_lts_cpu-1.20.0.tar.gz', template="https://pypi.org/packages/source/p/${{ polars_variant }}/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz", context={'c_compiler': 'gcc', 'c_stdlib': 'sysroot', 'c_stdlib_version': '2.17', 'cdt_name': 'conda', 'channel_sources': 'conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'gxx', 'docker_image': 'quay.io/condaforge/linux-anvil-x86_64:alma9', 'pin_run_as_build': 'python', 'polars_variant': 'polars-lts-cpu', 'python': '3.13.* *_cp313', 'rust_compiler': 'rust', 'target_platform': 'linux-64', 'c_compiler_version': '13', 'cxx_compiler_version': '13', 'version': '1.20.0'}, sha256='f8770fe1a752f60828ec73e6215c7dadcb2badd1f34dcb1def7a0f4ca0ac36f8', md5=None),
Source(url='https://pypi.org/packages/source/p/polars-u64-idx/polars_u64_idx-1.20.0.tar.gz', template="https://pypi.org/packages/source/p/${{ polars_variant }}/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz", context={'c_compiler': 'gcc', 'c_stdlib': 'sysroot', 'c_stdlib_version': '2.17', 'cdt_name': 'conda', 'channel_sources': 'conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'gxx', 'docker_image': 'quay.io/condaforge/linux-anvil-x86_64:alma9', 'pin_run_as_build': 'python', 'polars_variant': 'polars-u64-idx', 'python': '3.13.* *_cp313', 'rust_compiler': 'rust', 'target_platform': 'linux-64', 'c_compiler_version': '13', 'cxx_compiler_version': '13', 'version': '1.20.0'}, sha256='a92fadacf59776bef2d777f99345c4d089cf4f8b3fd61f5728087bab27a46a75', md5=None),
Source(url='https://pypi.org/packages/source/p/polars/polars-1.20.0.tar.gz', template="https://pypi.org/packages/source/p/polars/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz", context={'c_compiler': 'clang', 'c_compiler_version': '17', 'c_stdlib': 'vs', 'channel_sources': 'conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge', 'channel_targets': 'conda-forge main', 'cxx_compiler': 'clangxx', 'cxx_compiler_version': '17', 'docker_image': 'quay.io/condaforge/linux-anvil-x86_64:alma9', 'pin_run_as_build': 'python', 'polars_variant': 'polars', 'python': '3.13.* *_cp313', 'rust_compiler': 'rust', 'target_platform': 'win-64', 'version': '1.20.0'}, sha256='e8e9e3156fae02b58e276e5f2c16a5907a79b38617a9e2d731b533d87798f451', md5=None),
})
# ---
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
c_compiler:
- gcc
c_compiler_version:
- '13'
c_stdlib:
- sysroot
c_stdlib_version:
- '2.17'
cdt_name:
- conda
channel_sources:
- conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge
channel_targets:
- conda-forge main
cxx_compiler:
- gxx
cxx_compiler_version:
- '13'
docker_image:
- quay.io/condaforge/linux-anvil-x86_64:alma9
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
polars_variant:
- polars-lts-cpu
python:
- 3.13.* *_cp313
rust_compiler:
- rust
target_platform:
- linux-64
zip_keys:
- - c_compiler_version
- cxx_compiler_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
c_compiler:
- gcc
c_compiler_version:
- '13'
c_stdlib:
- sysroot
c_stdlib_version:
- '2.17'
cdt_name:
- conda
channel_sources:
- conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge
channel_targets:
- conda-forge main
cxx_compiler:
- gxx
cxx_compiler_version:
- '13'
docker_image:
- quay.io/condaforge/linux-anvil-x86_64:alma9
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
polars_variant:
- polars-u64-idx
python:
- 3.13.* *_cp313
rust_compiler:
- rust
target_platform:
- linux-64
zip_keys:
- - c_compiler_version
- cxx_compiler_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
c_compiler:
- clang
c_compiler_version:
- '17'
c_stdlib:
- vs
channel_sources:
- conda-forge/label/rust_dev,conda-forge/label/cargo-patch-dev,conda-forge
channel_targets:
- conda-forge main
cxx_compiler:
- clangxx
cxx_compiler_version:
- '17'
docker_image:
- quay.io/condaforge/linux-anvil-x86_64:alma9
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
polars_variant:
- polars
python:
- 3.13.* *_cp313
rust_compiler:
- rust
target_platform:
- win-64
20 changes: 20 additions & 0 deletions tests/data/polars/sources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
context:
version: '1.20.0'

package:
name: ${{ polars_variant }}
version: ${{ version }}

source:
- if: polars_variant == 'polars'
then:
url: https://pypi.org/packages/source/p/polars/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz
sha256: e8e9e3156fae02b58e276e5f2c16a5907a79b38617a9e2d731b533d87798f451
- if: polars_variant == 'polars-lts-cpu'
then:
url: https://pypi.org/packages/source/p/${{ polars_variant }}/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz
sha256: f8770fe1a752f60828ec73e6215c7dadcb2badd1f34dcb1def7a0f4ca0ac36f8
- if: polars_variant == 'polars-u64-idx'
then:
url: https://pypi.org/packages/source/p/${{ polars_variant }}/${{ polars_variant | replace('-', '_') }}-${{ version }}.tar.gz
sha256: a92fadacf59776bef2d777f99345c4d089cf4f8b3fd61f5728087bab27a46a75
11 changes: 11 additions & 0 deletions tests/test_recipe_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ def test_conditional_source_render(snapshot) -> None:
sources = render_all_sources(recipe_yaml, variants)
assert len(sources) == 4
assert sources == snapshot


def test_variant_variables_source_render(snapshot) -> None:
polars = test_data / "polars" / "sources.yaml"
variants = (test_data / "polars" / "ci_support").glob("*.yaml")

recipe_yaml = load_yaml(polars.read_text())
variants = [load_yaml(variant.read_text()) for variant in variants]

sources = render_all_sources(recipe_yaml, variants)
assert sources == snapshot