Skip to content

pixi-build-rattler-build could improve variables management #5393

@crusaderky

Description

@crusaderky

Problem description

Context

On python/cpython#142872, two engineers recently wasted several hours because they didn't notice that c_compiler is not a variable defined by rattler-build.

The problem

  • When a variable is undefined in recipe.yaml, it quietly defaults to nan, which evaluates to false.
  • When an undefined variable is compared with == to anything, the comparison quietly returns false.
  • The only documentation I could find about which variables are defined besides those that the user explicitly defines in the context section of the recipe, namely linux, osx, win, etc., was in the conda-forge documentation (e.g. # if [linux]).
  • There is no straightforward way to inspect the output of functions, e.g. compiler('c').

Example

These if conditions always return false, but it's not obvious at first glance unless you work daily with recipes:

- if: windows  # undefined so it evaluates to false (should have used `win`)
  then:
     - my_win_only_dep
- if: c_compiler == "clang":  # undefined so the comparison always evaluates to false
  then:
     - my_clang_only_dep
- if: compiler('c') == "clang":  # always evaluates to false; no idea why as I can't inspect function output
  then:
     - my_clang_only_dep

Proposed solution

  • Properly document all available variables.

  • Trigger a hard crash when the user references an undefined variable. Considering that AFAIK you can't define variables in custom scripts, it's not like in bash where you can't always use set -o nounset.
    I am aware this is a breaking change but I cannot think of anybody who would be harmed by the change, other than people that have a condition that is never true and they don't realise - and I'm fairly sure they would like to know. Maybe just issue a warning for a few versions to ease the transition?

  • It would be very useful to have a tool that dumps all available variables and their current value.
    A simple solution would be to dump them to whenever one encounters an undefined variable. Maybe just with pixi -vv?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions