Think about the `cmp` function
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.
Suggestions from @baszalmstra:
- use
matches(python, "3.7")instead ofcmpbecause it's more clear that it's a matchspec / versionspec - instead of a implicit variable like
python, use explicitlyvariant["python"], so that it becomes something likematches(variant["python"], "3.7"). - Or we could make it similar to the
envobject that we recently introduced and make it readmatches(variant.python, "3.7")ormatches(variant.get("python"), "3.7")
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
pythonorlibfoobaris not some magical value. - We can easily deal with package names that are not valid variable names (e.g.
py-rattleris not a valid variable name, butvariant.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?
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 ?
For now, we have fixed these and match is already being used by a bunch of recipes in conda-forge! :)