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

Backtrack on inconsistent candidate #63

Closed
uranusjr opened this issue Dec 3, 2020 · 3 comments
Closed

Backtrack on inconsistent candidate #63

uranusjr opened this issue Dec 3, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@uranusjr
Copy link
Member

uranusjr commented Dec 3, 2020

Currently the resolver only allow one way for the provider to trigger backtracking, by supplying requirements (dependencies) that would empty a criterion’s candidate list. This prevents some oppertunities for applications to reject candidates in later stages. pip, for example, wants to reject a candidate with invalid/inconsistent metadata, but there’s currently no way for it to do this.

Except there is already a hook for that: is_satisfied_by(). This hook is already checked during pinning:

for candidate in criterion.candidates:
try:
criteria = self._get_criteria_to_update(candidate)
except RequirementsConflicted as e:
causes.append(e.criterion)
continue
# Check the newly-pinned candidate actually works. This should
# always pass under normal circumstances, but in the case of a
# faulty provider, we will raise an error to notify the implementer
# to fix find_matches() and/or is_satisfied_by().
satisfied = all(
self._p.is_satisfied_by(r, candidate)
for r in criterion.iter_requirement()
)
if not satisfied:
raise InconsistentCandidate(candidate, criterion)

The first block catches RequirementsConflicted, which would be used to trigger backtracking. The second calls is_satisfied_by(), but expects it to always return True (otherwise raises InconsistentCandidate). If we modify the block to instead continue (i.e. give up on the candidate) when is_satisfied() returns false, the provider can then use it to validate the candidate and signal any latent issues that cannot be found previously.

This would help issues such as pypa/pip#9203, and provide the companion fix needed for pypa/pip#9199.

@uranusjr uranusjr added the enhancement New feature or request label Dec 3, 2020
@uranusjr
Copy link
Member Author

uranusjr commented Dec 8, 2020

This may also help pypa/pip#9246.

@pradyunsg
Copy link
Contributor

We ended up implementing this in pip's logic for this stuff.

@pradyunsg
Copy link
Contributor

See pypa/pip#9289 for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants