Skip to content

Commit 01f1023

Browse files
jsmolicjaimergp
andauthored
docs: Document CBC.yaml variable type differences in selectors vs Jinja2 (#5887)
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
1 parent 85ef2f5 commit 01f1023

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

docs/source/resources/variants.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,40 @@ Jinja is not allowed in ``conda_build_config.yaml``, though. It is the source of
398398
information to feed into other Jinja templates, and the buck has to stop
399399
somewhere.
400400

401+
Variable type behavior in selectors and Jinja2 expressions
402+
----------------------------------------------------------
403+
404+
Variables defined in the ``conda_build_config.yaml`` file are treated differently depending
405+
on where they are used in the recipe.
406+
407+
In selector expressions, variables from ``conda_build_config.yaml`` are converted into specific Python types.
408+
Conda build converts numerical-like expressions into ``int`` type for easier relational operations.
409+
Additionally, ``true`` / ``false`` strings are converted to booleans.
410+
411+
In Jinja2 expressions, the variables are treated as strings even if they are defined as integers in ``conda_build_config.yaml``.
412+
This is the default Jinja2 behavior as its original use-case was generating text-based outputs.
413+
Variables must be explicitly casted to ``int`` type in the Jinja expression if they need to be used as such.
414+
415+
Consider two different variable definitions in ``conda_build_config.yaml``:
416+
417+
a)
418+
419+
.. code-block:: yaml
420+
421+
foo:
422+
- 1
423+
424+
b)
425+
426+
.. code-block:: yaml
427+
428+
foo:
429+
- "1"
430+
431+
Due to this type-handling discrepancy, a Jinja2 expression such as ``{{ foo == 1 }}`` will evaluate to ``False``
432+
regardless of whether ``foo`` was defined as an integer or string in ``conda_build_config.yaml``.
433+
Similarly, selector expressions such as ``# [foo == 1]`` will always evaluate to ``True``.
434+
401435

402436
About reproducibility
403437
---------------------

news/5852-cbc-variables.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* <news item>
4+
5+
### Bug fixes
6+
7+
* <news item>
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* Document `conda_build_config.yaml` variable type differences in selectors vs Jinja2 expressions (#5852 via #5887)
16+
17+
### Other
18+
19+
* <news item>

0 commit comments

Comments
 (0)