Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _eval_marker(marker, extras=(None,)):
if not marker:
return True
if not isinstance(marker, packaging.markers.Marker):
marker = packaging.markers.Marker(marker)
return any(marker.evaluate({"extra": extra}) for extra in extras)
def _iter_resolved(data):
for k, v in data.items():
if not isinstance(v, dict):
v = {"version": v}
yield k, v
class PythonInputProvider(AbstractProvider):
def __init__(self, filename):
with open(filename) as f:
case_data = json.load(f)
index_name = os.path.normpath(
os.path.join(
filename, "..", "..", "index", case_data["index"] + ".json"
),
)
with open(index_name) as f:
self.index = json.load(f)
self.root_requirements = [
packaging.requirements.Requirement(r)
for r in case_data["requested"]
]
0,
-parsed_version[1],
parsed_version[2],
-len(parsed_version[3][:1]),
parsed_version[3],
)
return (
-parsed_version[0],
parsed_version[1],
parsed_version[2],
-len(parsed_version[3][:1]),
parsed_version[3],
)
class SwiftInputProvider(AbstractProvider):
def __init__(self, filename):
with open(filename) as f:
input_data = json.load(f)
self.containers = {
container["identifier"]: container
for container in input_data["containers"]
}
self.root_requirements = [
Requirement(self.containers[constraint["identifier"]], constraint)
for constraint in input_data["constraints"]
]
self.expectation = input_data["result"]
def identify(self, requirement_or_candidate):
return requirement_or_candidate.container["identifier"]
graph which needs to be static - the edges (dependencies) from a node
(candidate) must be fixed. Extras break this assumption.
To model projects with extras, we define a candidate as being a project with a
specific set of dependencies. This introduces a problem, as the resolver could
produce a solution that demands version 1.0 of X[foo] and version 2.0 of
X[bar]. This is impossible, as there is actually only one project X to be
installed. To address this, we inject an additional dependency for every
candidate with an extra - X[foo] version v depends on X version v. By doing
this, we constrain the solution to require a unique version of X.
"""
from resolvelib.providers import AbstractProvider
class ExtrasProvider(AbstractProvider):
"""A provider that handles extras.
"""
def get_extras_for(self, requirement_or_candidate):
"""Given a requirement or candidate, return its extras.
The extras should be a hashable value.
"""
raise NotImplementedError
def get_base_requirement(self, candidate):
"""Given a candidate, return a requirement that specifies that
project/version.
"""
raise NotImplementedError