From 83727aa444aec8fc326ccdff668df802aa84ffb8 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Thu, 3 Mar 2022 17:08:02 +0100 Subject: [PATCH] [skip ci] implement new selector style --- boa/core/jinja_support.py | 6 +++-- boa/core/render.py | 32 ++++++++++++++++++------- tests/recipes-v2/xtensor/recipe.yaml | 36 +++++++++++++++++++++------- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/boa/core/jinja_support.py b/boa/core/jinja_support.py index 461bb203..38170742 100644 --- a/boa/core/jinja_support.py +++ b/boa/core/jinja_support.py @@ -3,7 +3,9 @@ import os from functools import partial -from conda_build.jinja_context import cdt +from conda_build.jinja_context import cdt as cb_cdt + +# cdt = partial(cb_cdt, config=config, permit_undefined_jinja=False), def pin_subpackage(name, max_pin="x.x.x.x.x", exact=False): @@ -29,7 +31,7 @@ def jinja_functions(config, context_dict): return { "pin_subpackage": pin_subpackage, "pin_compatible": pin_compatible, - "cdt": partial(cdt, config=config, permit_undefined_jinja=False), + "cdt": partial(cb_cdt, config=config, permit_undefined_jinja=False), "compiler": compiler, "environ": os.environ, } diff --git a/boa/core/render.py b/boa/core/render.py index 72359ca3..9e1b8ee3 100644 --- a/boa/core/render.py +++ b/boa/core/render.py @@ -6,7 +6,7 @@ from boa.core.jinja_support import jinja_functions from conda_build.metadata import eval_selector, ns_cfg from collections.abc import Mapping, Iterable - +from boa.core.jinja_support import compiler, pin_subpackage, pin_compatible # , cdt from boa.core.config import boa_config console = boa_config.console @@ -36,20 +36,36 @@ def render_recursive(dict_or_array, context_dict, jenv): render_recursive(value, context_dict, jenv) +funcs = { + "compiler": compiler, + "pin_subpackage": pin_subpackage, + "pin_compatible": pin_compatible, + # 'cdt': cdt +} + + def flatten_selectors(ydoc, namespace): if isinstance(ydoc, str): return ydoc if isinstance(ydoc, Mapping): - has_sel = any(k.startswith("sel(") for k in ydoc.keys()) - if has_sel: - for k, v in ydoc.items(): - selected = eval_selector(k[3:], namespace, []) - if selected: - return v + if "if" in ydoc: + assert "put" in ydoc + selected = eval_selector(ydoc["if"], namespace, []) + if selected: + return ydoc["put"] return None - + else: + for k in funcs.keys(): + if k in ydoc: + if k == "compiler": + return funcs[k](ydoc[k]) + else: + # expand as keyword arguments + return funcs[k](**ydoc[k]) + # arg = ydoc[] + # return special_keys[k](ydoc) for k, v in ydoc.items(): ydoc[k] = flatten_selectors(v, namespace) diff --git a/tests/recipes-v2/xtensor/recipe.yaml b/tests/recipes-v2/xtensor/recipe.yaml index df9ee8f8..3e8c7740 100644 --- a/tests/recipes-v2/xtensor/recipe.yaml +++ b/tests/recipes-v2/xtensor/recipe.yaml @@ -1,6 +1,10 @@ context: name: xtensor version: 0.23.10 + env: + - somename: MYENV_VAR + - othername: SOMEOTHER_ENV_VAR + package: name: '{{ name|lower }}' @@ -12,28 +16,42 @@ source: build: number: 0 + run_exports: + - pin_subpackage: + name: xtensor + max_pin: 'x.x.x' requirements: build: - - '{{ compiler("cxx") }}' + - compiler: cxx - cmake - - sel(unix): make + - if: unix + put: make host: - xtl >=0.7,<0.8 run: - xtl >=0.7,<0.8 + - pin_compatible: + name: xtl + max_pin: 'x.x' + run_constrained: - xsimd >=7.4.8,<8 test: commands: - - sel(unix): test -d ${PREFIX}/include/xtensor - - sel(unix): test -f ${PREFIX}/include/xtensor/xarray.hpp - - sel(unix): test -f ${PREFIX}/lib/cmake/xtensor/xtensorConfig.cmake - - sel(unix): test -f ${PREFIX}/lib/cmake/xtensor/xtensorConfigVersion.cmake - - sel(win): if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1) - - sel(win): if not exist %LIBRARY_PREFIX%\lib\cmake\xtensor\xtensorConfig.cmake (exit 1) - - sel(win): if not exist %LIBRARY_PREFIX%\lib\cmake\xtensor\xtensorConfigVersion.cmake (exit 1) + - if: unix + put: + - test -d ${PREFIX}/include/xtensor + - test -f ${PREFIX}/include/xtensor/xarray.hpp + - test -f ${PREFIX}/lib/cmake/xtensor/xtensorConfig.cmake + - test -f ${PREFIX}/lib/cmake/xtensor/xtensorConfigVersion.cmake + - if: win + put: + - if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1) + - if not exist %LIBRARY_PREFIX%\lib\cmake\xtensor\xtensorConfig.cmake (exit 1) + - if not exist %LIBRARY_PREFIX%\lib\cmake\xtensor\xtensorConfigVersion.cmake (exit 1) + exists: include: - xtensor