rattler-build icon indicating copy to clipboard operation
rattler-build copied to clipboard

Think about the `cmp` function

Open wolfv opened this issue 2 years ago • 3 comments

We've added a cmp function that can be used to compare the resolved variant version against a versionspec.

Example uses:

cmp(python, "3.7")
cmp(python, ">3")
cmp(python, "<=3.1")

This can then be used for example in an if statement:

if: cmp(python, ">3.7")
then:
- attrs

The nice thing about this is that it's a generalization of something that existed in conda (selectors like py2k, py>3, etc). and works with any variant (e.g. ruby, openssl, ...).

However, when had this in the CEP, people where not sure about the name & semantics, and we removed it from the initial CEP.

So now we're here and looking for more feedback.

wolfv avatar Nov 17 '23 13:11 wolfv

Suggestions from @baszalmstra:

  • use matches(python, "3.7") instead of cmp because it's more clear that it's a matchspec / versionspec
  • instead of a implicit variable like python, use explicitly variant["python"], so that it becomes something like matches(variant["python"], "3.7").
  • Or we could make it similar to the env object that we recently introduced and make it read matches(variant.python, "3.7") or matches(variant.get("python"), "3.7")

wolfv avatar Nov 17 '23 13:11 wolfv

I would prefer the last item ofc. I think it has some nice benefits:

  • We only have to teach the user about some top-level objects (variant, env, more?).
  • The variable python or libfoobar is not some magical value.
  • We can easily deal with package names that are not valid variable names (e.g. py-rattler is not a valid variable name, but variant.get("py-rattler") just works).
  • It's easy to provide contextual error messages (e.g. variant.bla, bla is not a valid variant, read more here and here and here).
  • Its more similar to github syntax (see https://docs.github.com/en/actions/learn-github-actions/contexts)

That being said: would it make sense to add the context variables to the context object as well?

baszalmstra avatar Nov 17 '23 13:11 baszalmstra

We thought about it and are calling it match now. Although we didn't revisit the idea of creating a variant object. Do you want to revisit that, @baszalmstra ?

wolfv avatar Jun 04 '24 17:06 wolfv

For now, we have fixed these and match is already being used by a bunch of recipes in conda-forge! :)

wolfv avatar Oct 16 '24 06:10 wolfv