Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _clean_identifier(s):
# I'm not entirely sure how identifiers in the spec work. The only fixture
# this matters (AFAICT) is swapping_changes_transitive_dependency, which
# has a '\u0001' that seems to intend to be dropped?
return "".join(c for c in s if c in string.printable)
def _iter_resolved(dependencies):
for entry in dependencies:
yield (entry["name"], packaging.version.parse(entry["version"]))
for sub in _iter_resolved(entry["dependencies"]):
yield sub
class CocoaPodsInputProvider(AbstractProvider):
def __init__(self, filename):
case_data = _safe_json_load(filename)
index_name = os.path.join(
INPUTS_DIR, "index", case_data.get("index", "awesome") + ".json",
)
self.index = _safe_json_load(index_name)
self.root_requirements = [
Requirement(_clean_identifier(key), _parse_specifier_set(spec))
for key, spec in case_data["requested"].items()
]
self.pinned_versions = {
entry["name"]: packaging.version.parse(entry["version"])
for entry in case_data["base"]
}
def test_candidate_inconsistent_error():
requirement = "foo"
candidate = "bar"
class Provider(AbstractProvider):
def identify(self, d):
assert d is requirement or d is candidate
return d
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
requirements = [Requirement.from_line(line) for line in options.packages]
if options.project:
os.chdir(options.project)
pipfile = Pipfile.load(options.project)
requirements.extend(pipfile.packages.requirements)
requirements.extend(pipfile.dev_packages.requirements)
def _filter_needed(requirement):
if not requirement.markers:
return True
return requirement.ireq.match_markers()
class RequirementsLibProvider(AbstractProvider):
"""Provider implementation to interface with `requirementslib.Requirement`.
"""
def __init__(self, root_requirements):
self.sources = None
self.invalid_candidates = set()
self.non_named_requirements = {
requirement.name: requirement
for requirement in root_requirements
if not requirement.is_named
}
def identify(self, dependency):
return dependency.normalized_name
def get_preference(self, resolution, candidates, information):
return len(candidates)
import os
import resolvelib
from ..internals.candidates import find_candidates
from ..internals.dependencies import get_dependencies
from ..internals.utils import (
filter_sources, get_allow_prereleases, identify_requirment, strip_extras,
)
PROTECTED_PACKAGE_NAMES = {"pip", "setuptools"}
class BasicProvider(resolvelib.AbstractProvider):
"""Provider implementation to interface with `requirementslib.Requirement`.
"""
def __init__(self, root_requirements, sources,
requires_python, allow_prereleases):
self.sources = sources
self.requires_python = requires_python
self.allow_prereleases = bool(allow_prereleases)
self.invalid_candidates = set()
# Remember requirements of each pinned candidate. The resolver calls
# `get_dependencies()` only when it wants to repin, so the last time
# the dependencies we got when it is last called on a package, are
# the set used by the resolver. We use this later to trace how a given
# dependency is specified by a package.
self.fetched_dependencies = {None: {
self.identify(r): r for r in root_requirements
import os
import resolvelib
from ..internals.candidates import find_candidates
from ..internals.dependencies import get_dependencies
from ..internals.utils import (
filter_sources, get_allow_prereleases, identify_requirment, strip_extras,
)
PROTECTED_PACKAGE_NAMES = {"pip", "setuptools"}
class BasicProvider(resolvelib.AbstractProvider):
"""Provider implementation to interface with `requirementslib.Requirement`.
"""
def __init__(self, root_requirements, sources,
requires_python, allow_prereleases):
self.sources = sources
self.requires_python = requires_python
self.allow_prereleases = bool(allow_prereleases)
self.invalid_candidates = set()
# Remember requirements of each pinned candidate. The resolver calls
# `get_dependencies()` only when it wants to repin, so the last time
# the dependencies we got when it is last called on a package, are
# the set used by the resolver. We use this later to trace how a given
# dependency is specified by a package.
self.fetched_dependencies = {None: {
self.identify(r): r for r in root_requirements
name, version = splitstrip(line, 2)
version = Version(version)
latest = Candidate(name, version)
candidates[latest] = set()
else:
if latest is None:
raise RuntimeError(
"Spec has dependencies before first candidate"
)
name, specifier = splitstrip(line, 2)
specifier = SpecifierSet(specifier)
candidates[latest].add(Requirement(name, specifier))
return candidates
class Provider(resolvelib.AbstractProvider):
def __init__(self, index):
self.candidates = read_spec(index)
def identify(self, requirement_or_candidate):
return requirement_or_candidate.name
def get_preference(self, resolution, candidates, information):
return len(candidates)
def find_matches(self, requirement):
deps = list(
filter(
lambda candidate: self.is_satisfied_by(requirement, candidate),
sorted(self.candidates),
)
)