Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_preference(self, *_):
return 0
def get_dependencies(self, _):
return []
def find_matches(self, r):
assert r is requirement
return [candidate]
def is_satisfied_by(self, r, c):
assert r is requirement
assert c is candidate
return False
resolver = Resolver(Provider(), BaseReporter())
with pytest.raises(InconsistentCandidate) as ctx:
resolver.resolve([requirement])
assert str(ctx.value) == "Provided candidate 'bar' does not satisfy 'foo'"
assert ctx.value.candidate is candidate
assert list(ctx.value.criterion.iter_requirement()) == [requirement]
def main():
"""Resolve requirements as project names on PyPI.
The requirements are taken as command-line arguments
and the resolution result will be printed to stdout.
"""
if len(sys.argv) == 1:
print("Usage:", sys.argv[0], "")
return
# Things I want to resolve.
reqs = sys.argv[1:]
requirements = [Requirement(r) for r in reqs]
# Create the (reusable) resolver.
provider = PyPIProvider()
reporter = BaseReporter()
resolver = Resolver(provider, reporter)
# Kick off the resolution process, and get the final result.
print("Resolving", ", ".join(reqs))
result = resolver.resolve(requirements)
display_resolution(result)
state.graph.iter_parents(key),
key=lambda n: (-1, '') if n is None else (ord(n[0].lower()), n),
)
for i, p in enumerate(parents):
if p is None:
line = '(user)'
else:
line = state.mapping[p].as_line(include_hashes=False)
if i == 0:
padding = ' <= '
else:
padding = ' ' * 44
print('{pad}{line}'.format(pad=padding, line=line))
class StdOutReporter(resolvelib.BaseReporter):
"""Simple reporter that prints things to stdout.
"""
def __init__(self, requirements):
super(StdOutReporter, self).__init__()
self.requirements = requirements
def starting(self):
self._prev = None
print_title(' User requirements ')
for r in self.requirements:
print_requirement(r)
def ending_round(self, index, state):
print_title(' Round {} '.format(index))
mapping = state.mapping
if self._prev is None:
from collections import Counter, defaultdict
from itertools import count
from packaging.utils import canonicalize_name
from pygraphviz import AGraph
from resolvelib import BaseReporter
class GraphGeneratingReporter(BaseReporter):
def __init__(self):
self.evolution = [] # List[str]
self._evaluating = None
# Dict[Candidate, Set[Requirement]]
self._dependencies = defaultdict(set)
# Dict[Candidate.name, Counter[Requirement]]
self._active_requirements = defaultdict(Counter)
self._node_names = {}
self._counter = count()
self.graph = AGraph(
directed=True,
rankdir="LR",
labelloc="top",
state.graph.iter_parents(key),
key=lambda n: (-1, '') if n is None else (ord(n[0].lower()), n),
)
for i, p in enumerate(parents):
if p is None:
line = '(user)'
else:
line = state.mapping[p].as_line(include_hashes=False)
if i == 0:
padding = ' <= '
else:
padding = ' ' * 44
print('{pad}{line}'.format(pad=padding, line=line))
class StdOutReporter(resolvelib.BaseReporter):
"""Simple reporter that prints things to stdout.
"""
def __init__(self, requirements):
super(StdOutReporter, self).__init__()
self.requirements = requirements
def starting(self):
self._prev = None
print_title(' User requirements ')
for r in self.requirements:
print_requirement(r)
def ending_round(self, index, state):
print_title(' Round {} '.format(index))
mapping = state.mapping
if self._prev is None:
def _print_dependency(state, key):
_print_requirement(state.mapping[key], end='')
parents = sorted(state.graph.iter_parents(key), key=_key_sort)
for i, p in enumerate(parents):
if p is None:
line = '(user)'
else:
line = state.mapping[p].as_line()
if i == 0:
padding = ' <= '
else:
padding = ' ' * 44
print('{pad}{line}'.format(pad=padding, line=line))
class StdOutReporter(BaseReporter):
"""Simple reporter that prints things to stdout.
"""
def starting(self):
self._prev = None
def ending_round(self, index, state):
_print_title(' Round {} '.format(index))
mapping = state.mapping
if self._prev is None:
difference = set(mapping.keys())
changed = set()
else:
difference = set(mapping.keys()) - set(self._prev.keys())
changed = set(
k for k, v in mapping.items()
if k in self._prev and self._prev[k] != v
sorted(self.candidates),
)
)
return deps
def is_satisfied_by(self, requirement, candidate):
return (
candidate.name == requirement.name
and candidate.version in requirement.specifier
)
def get_dependencies(self, candidate):
return self.candidates[candidate]
class Reporter(resolvelib.BaseReporter):
def starting(self):
print("starting()")
def starting_round(self, index):
print(f"starting_round({index})")
def ending_round(self, index, state):
print(f"ending_round({index}, ...)")
def ending(self, state):
print("ending(...)")
def adding_requirement(self, requirement, parent):
print(f" adding_requirement({requirement}, {parent})")
def backtracking(self, candidate):