示例#1
0
    def find_best_match(self, ireq, prereleases=False):
        if ireq.editable:
            return ireq

        versions = ireq.specifier.filter(self.index[key_from_req(ireq.req)], prereleases=prereleases)
        best_version = max(versions, key=Version)
        return make_install_requirement(key_from_req(ireq.req), best_version, ireq.extras)
示例#2
0
    def find_best_match(self, ireq, prereleases=False):
        if ireq.editable:
            return ireq

        versions = ireq.specifier.filter(self.index[key_from_req(ireq.req)],
                                         prereleases=prereleases)
        best_version = max(versions, key=Version)
        return make_install_requirement(key_from_req(ireq.req), best_version,
                                        ireq.extras)
示例#3
0
    def find_best_match(self, ireq, prereleases=False):
        if ireq.editable:
            return ireq

        versions = list(ireq.specifier.filter(self.index[key_from_req(ireq.req)],
                                              prereleases=prereleases))
        if not versions:
            raise NoCandidateFound(ireq, self.index[key_from_req(ireq.req)])
        best_version = max(versions, key=Version)
        return make_install_requirement(key_from_req(ireq.req), best_version, ireq.extras, constraint=ireq.constraint)
示例#4
0
    def find_best_match(self, ireq, prereleases=False):
        if ireq.editable:
            return ireq

        versions = list(ireq.specifier.filter(self.index[key_from_req(ireq.req)],
                                              prereleases=prereleases))
        if not versions:
            raise NoCandidateFound(ireq, self.index[key_from_req(ireq.req)], ['https://fake.url.foo'])
        best_version = max(versions, key=Version)
        return make_install_requirement(key_from_req(ireq.req), best_version, ireq.extras, constraint=ireq.constraint)
示例#5
0
 def find_best_match(self, ireq, prereleases=None):
     key = key_from_req(ireq.req)
     existing_pin = self.existing_pins.get(key)
     if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
         return existing_pin
     else:
         return self.repository.find_best_match(ireq, prereleases)
示例#6
0
 def find_best_match(self, ireq, prereleases=None):
     key = key_from_req(ireq.req)
     existing_pin = self.existing_pins.get(key)
     if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
         project, version, _ = as_tuple(existing_pin)
         return make_install_requirement(project, version, ireq.extras)
     else:
         return self.repository.find_best_match(ireq, prereleases)
示例#7
0
 def find_best_match(self, ireq, prereleases=None):
     key = key_from_req(ireq.req)
     existing_pin = self.existing_pins.get(key)
     if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
         project, version, _ = as_tuple(existing_pin)
         return make_install_requirement(
             project, version, ireq.extras, constraint=ireq.constraint, markers=ireq.markers
         )
     else:
         return self.repository.find_best_match(ireq, prereleases)
示例#8
0
    def __init__(self, line, deps=None):
        if deps is None:
            deps = []
        self.deps = [Requirement.parse(d) for d in deps]

        self.req = Requirement.parse(line)

        self.key = key_from_req(self.req)
        self.specifier = self.req.specifier

        self.version = line.split("==")[1]
示例#9
0
    def __init__(self, line, deps=None):
        if deps is None:
            deps = []
        self.deps = [Requirement.parse(d) for d in deps]

        self.req = Requirement.parse(line)

        self.key = key_from_req(self.req)
        self.specifier = self.req.specifier

        self.version = line.split("==")[1]
示例#10
0
 def get_hashes(self, ireq):
     key = key_from_req(ireq.req)
     existing_pin = self.existing_pins.get(key)
     if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
         hashes = existing_pin.options.get("hashes", {})
         hexdigests = hashes.get(FAVORITE_HASH)
         if hexdigests:
             return {
                 ":".join([FAVORITE_HASH, hexdigest]) for hexdigest in hexdigests
             }
     return self.repository.get_hashes(ireq)
示例#11
0
 def get_hashes(self, ireq):
     key = key_from_req(ireq.req)
     existing_pin = self.existing_pins.get(key)
     if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
         hashes = existing_pin.options.get("hashes", {})
         hexdigests = hashes.get(FAVORITE_HASH)
         if hexdigests:
             return {
                 ":".join([FAVORITE_HASH, hexdigest]) for hexdigest in hexdigests
             }
     return self.repository.get_hashes(ireq)
示例#12
0
    def find_best_match(self, ireq, prereleases=False):
        if ireq.editable:
            return ireq

        versions = list(
            ireq.specifier.filter(self.index[key_from_req(ireq.req)],
                                  prereleases=prereleases))
        if not versions:
            tried_versions = [
                InstallationCandidate(ireq.name, version,
                                      "https://fake.url.foo")
                for version in self.index[key_from_req(ireq.req)]
            ]
            raise NoCandidateFound(ireq, tried_versions,
                                   ["https://fake.url.foo"])
        best_version = max(versions, key=Version)
        return make_install_requirement(
            key_from_req(ireq.req),
            best_version,
            ireq.extras,
            constraint=ireq.constraint,
        )
示例#13
0
    def _resolve(self, deps):
        # Checking if we should active prereleases
        prereleases = False
        for dep in deps:
            if dep.accepts_prereleases():
                prereleases = True
                break

        constraints = [dep.as_requirement() for dep in deps]

        command = get_pip_command()
        opts, _ = command.parse_args([])

        resolver = Resolver(
            constraints, PyPIRepository(opts, command._build_session(opts)),
            cache=DependencyCache(CACHE_DIR),
            prereleases=prereleases
        )
        matches = resolver.resolve()
        pinned = [m for m in matches if not m.editable and is_pinned_requirement(m)]
        unpinned = [m for m in matches if m.editable or not is_pinned_requirement(m)]
        reversed_dependencies = resolver.reverse_dependencies(matches)

        # Complete reversed dependencies with cache
        cache = resolver.dependency_cache.cache
        for m in unpinned:
            name = key_from_req(m.req)
            if name not in cache:
                continue

            dependencies = cache[name][list(cache[name].keys())[0]]
            for dep in dependencies:
                dep = canonicalize_name(dep)
                if dep not in reversed_dependencies:
                    reversed_dependencies[dep] = set()

                reversed_dependencies[dep].add(canonicalize_name(name))

        hashes = resolver.resolve_hashes(pinned)
        packages = []
        for m in matches:
            name = key_from_req(m.req)
            if name in self.UNSAFE:
                continue

            version = str(m.req.specifier)
            if m in unpinned:
                url, specifier = m.link.url.split('@')
                rev, _ = specifier.split('#')

                version = self._get_vcs_version(url, rev)
                checksum = 'sha1:{}'.format(version['rev'])
            else:
                version = version.replace('==', '')
                checksum = list(hashes[m])

            # Figuring out category and optionality
            category = None
            optional = False

            # Checking if it's a main dependency
            for dep in deps:
                if dep.name == name:
                    category = dep.category
                    optional = dep.optional
                    break

            if not category:
                def _category(child):
                    opt = False
                    cat = None
                    parents = reversed_dependencies.get(child, set())
                    for parent in parents:
                        for dep in deps:
                            if dep.name != parent:
                                continue

                            opt = dep.optional

                            if dep.category == 'main':
                                # Dependency is given by at least one main package
                                # We flag it as main
                                return 'main', opt

                            return 'dev', opt

                        cat, op = _category(parent)

                        if cat is not None:
                            return cat, opt

                    return cat, opt

                category, optional = _category(name)

            # If category is still None at this point
            # The dependency must have come from a VCS
            # dependency. To avoid missing packages
            # we assume "main" category and not optional
            if category is None:
                category = 'main'
                optional = False

            if not isinstance(checksum, list):
                checksum = [checksum]

            # Retrieving Python restriction if any
            python = self._get_pythons_for_package(
                name, reversed_dependencies, deps
            )
            python = list(python)

            if '*' in python:
                # If at least one parent gave a wildcard
                # Then it should be installed for any Python version
                python = ['*']

            package = {
                'name': name,
                'version': version,
                'checksum': checksum,
                'category': category,
                'optional': optional,
                'python': python
            }

            packages.append(package)

        return sorted(packages, key=lambda p: p['name'].lower())