Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Collect Applicable Constraints #1480

Merged
merged 4 commits into from
Dec 29, 2017

Conversation

JackyChiu
Copy link
Contributor

@JackyChiu JackyChiu commented Dec 24, 2017

What does this do / why do we need it?

Makes the collectConstraints method collection only applicable constraints (constraints that are actually imported in the project). Does so by checking project constraints against direct deps.

What should your reviewer look out for in this PR?

Implementation improvements

  • TODO: Have a maintainer fork test project fixture and then update project root in tests

Do you need help or clarification on anything?

  • Would like some help in creating a fixture for a test case in TestCollectConstraints where the imports don't use all the constraints. Since it seems like only the maintainers should have their projects in the tests.

Which issue(s) does this PR fix?

fixes #1409

@darkowlzz
Copy link
Collaborator

darkowlzz commented Dec 24, 2017

@JackyChiu Thanks, I'll review and add some feedback soon. In the meantime, can you look at #302 and see if you can write a function that could help with that issue as well?

And for a test repo, you can create one in your account and I'll fork it from you later.

EDIT: updated the link to the other issue.

@JackyChiu
Copy link
Contributor Author

@darkowlzz Thanks! It's the holidays, so no rush at all!

@JackyChiu
Copy link
Contributor Author

codeclimate is giving a error for the test functions max lines of code and cognitive complexity. Does it make sense to have these rules applied to tests?

@@ -793,12 +793,23 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con
// Get project constraints.
pc := manifest.DependencyConstraints()

imports, err := projectImports(sm, proj)
if err != nil {
errCh <- errors.Wrapf(err, "error listing imports used in %s", proj.Ident().ProjectRoot)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we send this error to the existing error channel, we might end up overflowing the error channel. I would recommend creating another error channel for collecting these errors separately, similar to errListPkgCh and errListVerCh in runStatusAll().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably won't need to error after refactoring for the use case above 😄

@@ -793,12 +793,23 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con
// Get project constraints.
pc := manifest.DependencyConstraints()

imports, err := projectImports(sm, proj)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand this correctly, imports contains all the imports of proj right? Not the root project?
Applicable/working constraints are in respect to the root project, p. That's why getApplicableConstraints() uses rootdata to walk through all the import paths.

Correct me if I'm not seeing it the wrong way 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opps! My bad, I misunderstood. This makes it simpler though!

I also looked the issue you referred me to, and it does look like a function could be written to satisfy both issues. Which file would the best placement be for it?

lock: dep.Lock{
P: []gps.LockedProject{
gps.NewLockedProject(
gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot("github.com/JackyChiu/deptest")},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's name the test project something relevant to the test, which would help us recall and refer to it easily. Maybe use words like applicable, constraints, or anything that you think would be accurate. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

@darkowlzz
Copy link
Collaborator

codeclimate is giving a error for the test functions max lines of code and cognitive complexity. Does it make sense to have these rules applied to tests?

@JackyChiu ignore those codeclimate errors for now. Those errors started showing up a few weeks back. Refer https://twitter.com/sdboyer/status/939159860159111169 , not the exact error but I'm sure they have the same origin.

added tests for projectImports

collect applicable constraints only test

update term used in err msg

break up import functions
@JackyChiu JackyChiu force-pushed the applicable_constraints branch from 6c8a51c to cac9c6b Compare December 25, 2017 22:16
Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

This looks correct to me. But I would like to wait and ponder on it a bit and maybe have another review.

@@ -305,6 +305,7 @@ func TestCollectConstraints(t *testing.T) {
ver1, _ := gps.NewSemverConstraintIC("v1.0.0")
ver08, _ := gps.NewSemverConstraintIC("v0.8.0")
ver2, _ := gps.NewSemverConstraintIC("v2.0.0")
master := gps.NewBranch("master")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be used inline. Other's are not inline because they do not return single value.

@darkowlzz
Copy link
Collaborator

I also looked the issue you referred me to, and it does look like a function could be written to satisfy both issues. Which file would the best placement be for it?

@JackyChiu This would be kinda off-topic. So, manifest.go has ValidateProjectRoots(), where it checks if the project names are actually project root. I think applicable constraints check in manifest can go within that function. And if you want to use getDirectDependencies() there, you would have to take it out of cmd/dep package, which seems fine to me. Might need other's inputs too. So, now this PR and #302 are independent if we go with the approach of using getDirectDependencies().

@darkowlzz
Copy link
Collaborator

@JackyChiu Also, can you clean up https://github.com/JackyChiu/dep-applicable-constraints/ ? I see a lot of tags in there and that could get confusing later 😅

@JackyChiu
Copy link
Contributor Author

This would be kinda off-topic. So, manifest.go has ValidateProjectRoots(), where it checks if the project names are actually project root. I think applicable constraints check in manifest can go within that function. And if you want to use getDirectDependencies() there, you would have to take it out of cmd/dep package, which seems fine to me. Might need other's inputs too. So, now this PR and #302 are independent if we go with the approach of using getDirectDependencies().

Right that was off topic, and it turned out I didn't need to write a new function lol.

Also, can you clean up https://github.com/JackyChiu/dep-applicable-constraints/ ? I see a lot of tags in there and that could get confusing later 😅

Forgot about all those, cleaned them up

@JackyChiu JackyChiu changed the title [WIP] Collect Applicable Constraints Collect Applicable Constraints Dec 26, 2017
@darkowlzz
Copy link
Collaborator

I've cloned the test repo https://github.com/darkowlzz/dep-applicable-constraints , you can change the repo names in the tests. And we should be ready with that.

@JackyChiu
Copy link
Contributor Author

@darkowlzz done!

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

LGTM

@darkowlzz darkowlzz merged commit 8d8de2d into golang:master Dec 29, 2017
@darkowlzz
Copy link
Collaborator

Thanks for working on it 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

collectConstraints() should collect applicable constraints only
3 participants