Skip to content
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

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

mitchell-as
Copy link
Contributor

@mitchell-as mitchell-as commented Feb 26, 2024

StoryDX-2601 As a user I can expect version requirements to be fully typed

@mitchell-as mitchell-as force-pushed the mitchell/dx-2601 branch 5 times, most recently from 19fb393 to 0bddb6f Compare February 26, 2024 23:53
@mitchell-as mitchell-as requested a review from MDrakos March 4, 2024 19:19
@mitchell-as mitchell-as marked this pull request as ready for review March 4, 2024 19:19
Copy link
Member

@MDrakos MDrakos left a 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.

Comment on lines 109 to 119
case eqFuncName:
fallthrough
case neFuncName:
fallthrough
case gtFuncName:
fallthrough
case gteFuncName:
fallthrough
case ltFuncName:
fallthrough
case lteFuncName:
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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")))
Copy link
Member

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.

Comment on lines 297 to 301
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 {
Copy link
Member

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.

@mitchell-as mitchell-as requested a review from MDrakos March 5, 2024 15:17
Copy link
Member

@MDrakos MDrakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@mitchell-as mitchell-as merged commit 411685e into version/0-44-0-RC1 Mar 5, 2024
7 checks passed
@mitchell-as mitchell-as deleted the mitchell/dx-2601 branch March 5, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants