Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/pip/_vendor/resolvelib/providers.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 class AbstractProvider(object): | |
2 """Delegate class to provide requirement interface for the resolver.""" | |
3 | |
4 def identify(self, requirement_or_candidate): | |
5 """Given a requirement or candidate, return an identifier for it. | |
6 | |
7 This is used in many places to identify a requirement or candidate, | |
8 e.g. whether two requirements should have their specifier parts merged, | |
9 whether two candidates would conflict with each other (because they | |
10 have same name but different versions). | |
11 """ | |
12 raise NotImplementedError | |
13 | |
14 def get_preference(self, resolution, candidates, information): | |
15 """Produce a sort key for given requirement based on preference. | |
16 | |
17 The preference is defined as "I think this requirement should be | |
18 resolved first". The lower the return value is, the more preferred | |
19 this group of arguments is. | |
20 | |
21 :param resolution: Currently pinned candidate, or `None`. | |
22 :param candidates: An iterable of possible candidates. | |
23 :param information: A list of requirement information. | |
24 | |
25 The `candidates` iterable's exact type depends on the return type of | |
26 `find_matches()`. A sequence is passed-in as-is if possible. If it | |
27 returns a callble, the iterator returned by that callable is passed | |
28 in here. | |
29 | |
30 Each element in `information` is a named tuple with two entries: | |
31 | |
32 * `requirement` specifies a requirement contributing to the current | |
33 candidate list. | |
34 * `parent` specifies the candidate that provides (dependend on) the | |
35 requirement, or `None` to indicate a root requirement. | |
36 | |
37 The preference could depend on a various of issues, including (not | |
38 necessarily in this order): | |
39 | |
40 * Is this package pinned in the current resolution result? | |
41 * How relaxed is the requirement? Stricter ones should probably be | |
42 worked on first? (I don't know, actually.) | |
43 * How many possibilities are there to satisfy this requirement? Those | |
44 with few left should likely be worked on first, I guess? | |
45 * Are there any known conflicts for this requirement? We should | |
46 probably work on those with the most known conflicts. | |
47 | |
48 A sortable value should be returned (this will be used as the `key` | |
49 parameter of the built-in sorting function). The smaller the value is, | |
50 the more preferred this requirement is (i.e. the sorting function | |
51 is called with `reverse=False`). | |
52 """ | |
53 raise NotImplementedError | |
54 | |
55 def find_matches(self, requirements): | |
56 """Find all possible candidates that satisfy the given requirements. | |
57 | |
58 This should try to get candidates based on the requirements' types. | |
59 For VCS, local, and archive requirements, the one-and-only match is | |
60 returned, and for a "named" requirement, the index(es) should be | |
61 consulted to find concrete candidates for this requirement. | |
62 | |
63 The return value should produce candidates ordered by preference; the | |
64 most preferred candidate should come first. The return type may be one | |
65 of the following: | |
66 | |
67 * A callable that returns an iterator that yields candidates. | |
68 * An collection of candidates. | |
69 * An iterable of candidates. This will be consumed immediately into a | |
70 list of candidates. | |
71 | |
72 :param requirements: A collection of requirements which all of the | |
73 returned candidates must match. All requirements are guaranteed to | |
74 have the same identifier. The collection is never empty. | |
75 """ | |
76 raise NotImplementedError | |
77 | |
78 def is_satisfied_by(self, requirement, candidate): | |
79 """Whether the given requirement can be satisfied by a candidate. | |
80 | |
81 The candidate is guarenteed to have been generated from the | |
82 requirement. | |
83 | |
84 A boolean should be returned to indicate whether `candidate` is a | |
85 viable solution to the requirement. | |
86 """ | |
87 raise NotImplementedError | |
88 | |
89 def get_dependencies(self, candidate): | |
90 """Get dependencies of a candidate. | |
91 | |
92 This should return a collection of requirements that `candidate` | |
93 specifies as its dependencies. | |
94 """ | |
95 raise NotImplementedError | |
96 | |
97 | |
98 class AbstractResolver(object): | |
99 """The thing that performs the actual resolution work.""" | |
100 | |
101 base_exception = Exception | |
102 | |
103 def __init__(self, provider, reporter): | |
104 self.provider = provider | |
105 self.reporter = reporter | |
106 | |
107 def resolve(self, requirements, **kwargs): | |
108 """Take a collection of constraints, spit out the resolution result. | |
109 | |
110 This returns a representation of the final resolution state, with one | |
111 guarenteed attribute ``mapping`` that contains resolved candidates as | |
112 values. The keys are their respective identifiers. | |
113 | |
114 :param requirements: A collection of constraints. | |
115 :param kwargs: Additional keyword arguments that subclasses may accept. | |
116 | |
117 :raises: ``self.base_exception`` or its subclass. | |
118 """ | |
119 raise NotImplementedError |