-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use functions for buildscript version requirements instead of formatted strings. #3144
Conversation
mitchell-as
commented
Feb 26, 2024
•
edited by github-actions
bot
Loading
edited by github-actions
bot
DX-2601 As a user I can expect version requirements to be fully typed |
19fb393
to
0bddb6f
Compare
0bddb6f
to
b4f1c54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here all looks good to me. Just some minor stuff to clean up.
case eqFuncName: | ||
fallthrough | ||
case neFuncName: | ||
fallthrough | ||
case gtFuncName: | ||
fallthrough | ||
case gteFuncName: | ||
fallthrough | ||
case ltFuncName: | ||
fallthrough | ||
case lteFuncName: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we list all of these values for a single case rather than use fallthrough
here? So it would be something like:
case eqFuncName, neFuncName, gtFuncName, etc:
...
} | ||
err := addRequirement(a.FuncCall) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple errors in this function that need to be wrapped. May be worth skimming the changeset again to ensure we're wrapping everything.
// {"version_requirements": [{"comparator": "<op>", "version": "<version>"}]} | ||
case assignment.Key == buildexpression.RequirementVersionKey && assignment.Value.FuncCall != nil: | ||
var requirements []*Value | ||
var addRequirement func(*FuncCall) error // recursive function for adding to requirements list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clever solution!
@@ -166,7 +169,8 @@ const example = `runtime = solve( | |||
platforms = ["96b7e6f2-bebf-564c-bc1c-f04482398f38", "96b7e6f2-bebf-564c-bc1c-f04482398f38"], | |||
requirements = [ | |||
Req(name = "language/python"), | |||
Req(name = "language/python/requests", version = "3.10.10") | |||
Req(name = "language/python/requests", version = Eq("3.10.10")), | |||
Req(name = "language/python/argparse", version = And(Gt("1.0"), Lt("2.0"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this to the test.
if f.Name == reqFuncName || | ||
f.Name == eqFuncName || f.Name == neFuncName || | ||
f.Name == gtFuncName || f.Name == gteFuncName || | ||
f.Name == ltFuncName || f.Name == lteFuncName || | ||
f.Name == andFuncName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It might be nice to create a map, slice, or function that can encapsulate this for us. So this line becomes a simple map check, funk.Contains
or function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!