Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

[skip ci] implement new selector style #256

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
6 changes: 4 additions & 2 deletions boa/core/jinja_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
}
32 changes: 24 additions & 8 deletions boa/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
36 changes: 27 additions & 9 deletions tests/recipes-v2/xtensor/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
context:
name: xtensor
version: 0.23.10
env:
- somename: MYENV_VAR
- othername: SOMEOTHER_ENV_VAR


package:
name: '{{ name|lower }}'
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking - if/put will be the new way to do it in the next boa release?

I'm happy to keep up with the changes and don't want backward compatibility concerns to slow down development - at this stage I think it's more important to experiment to find the right api.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, yeah, I am undecided. We're having some discussions with the conda community about this and I wanted to see how it feels. I think we should also have a shorthand - if(unix): make that we can easily normalize to the longer form.

This more verbose form adds a lot of "noise" to the recipes...

Copy link
Member Author

Choose a reason for hiding this comment

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

Would love to hear your thoughts. Are you on the conda slack? There is a spec discussion room that recently saw some activity!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll check out the slack 👍

The put did seem a bit verbose, but not too terrible!

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
Expand Down