-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(status): add constraint for locked projects #962
fix(status): add constraint for locked projects #962
Conversation
cmd/dep/status.go
Outdated
// Get constraint for locked project | ||
for _, lockedP := range p.Lock.P { | ||
if lockedP.Ident().ProjectRoot == proj.Ident().ProjectRoot { | ||
c.Constraint = lockedP.Version() |
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.
We can't make this jump, unfortunately - the version in the lock doesn't really tell us anything about what the constraints were that got us there. For any possible version that would be in a lock, there are at least two possible constraints that would allow it:
- An exact match for that version
- An
Any
constraint
so yeah, we've gotta do the CollectConstraints
thing in order to be able to fill this in accurately 😢
7cdb8f6
to
ea8b946
Compare
@sdboyer I have implemented |
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.
sorry i dawdled so much on this 😢
collectConstraints
implementation looks good, though let's make sure to add some tests for it. after that, shouldn't be too much more work to get this squared away!
cmd/dep/status.go
Outdated
// Create a root analyzer | ||
rootAnalyzer := newRootAnalyzer(false, ctx, directDeps, sm) | ||
|
||
// Iterate through the locked projects and collect constrains of all the projects |
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: s/constrains/constraints/
also, missing period
cmd/dep/status.go
Outdated
for pr, pp := range pc { | ||
// Check if a collection exists for a project root and append to | ||
// existing one or create a new constraint collection. | ||
if cc, exists := constraintCollection[string(pr)]; exists { |
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.
i think this can be safely shortened to a one-liner, as lookups to nonexistent keys on maps will return the zero value for the map's value type:
constraintCollection[string(pr)] = append(constraintCollection[string(pr)], pp.Constraint)
439d7f9
to
0d33290
Compare
@sdboyer I'm not sure how to write a test for this without creating new projects with the manifest file in them. Can we reuse some of your test repos for this? Or should I create repos of my own? |
0d33290
to
7bef6fc
Compare
I created https://github.com/darkowlzz/deptest-project-1 and https://github.com/darkowlzz/deptest-project-2 for testing |
3632c8c
to
8d2d1cd
Compare
Added |
Use project lock to get the constraints of projects not in manifest.
The resultant collection obtained from collectConstraints() should contain data about which project set a particular constraint on a dependency project. `projectConstraint` consists of the project and the constraint it sets on a given dependency. And `constraintsCollection` is a map to store the pair of dependency project and a collection of `projectConstraint` for different constraints. This would be used by project argument status (status for a single project), to show the importers of the project.
8d2d1cd
to
1814fc3
Compare
// Iterate through the project constraints to get individual dependency | ||
// project and constraint values. | ||
for pr, pp := range pc { | ||
constraintCollection[string(pr)] = append( |
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.
so this is overzealous right now - it pulls in constraints regardless of whether they're actually applicable or not. it's unlikely to create problems right now, but it will need to be updated in the future (please open an issue!) to do the equivalent of something like intersectConstraintsWithImports()
or getApplicableConstraints()
What does this do / why do we need it?
Uses project lock to get the constraints of projects not in manifest.
What should your reviewer look out for in this PR?
Correctness of implementation.
Do you need help or clarification on anything?
Before:
With this change:
For some reason,
LATEST
ofgo-radix
andlockfile
aren't showing up.Constraint.Matches()
seems to be failing. Some help in figuring out the reason would be great.Update: The missing
LATEST
above is because those projects don't have any release.Which issue(s) does this PR fix?
Related to #893