Esempio n. 1
0
    def _match_pip_requires(self, pip_req):
        def pip_use(who, there_pip):
            if there_pip.key != pip_req.key:
                return False
            if not len(pip_req.specs):
                # No version/restrictions specified
                return True
            there_version = None
            if there_pip.version is not None:
                there_version = str(there_pip.version)
            if there_version in pip_req:
                return True
            # Different possibly incompat. versions found...
            if there_version is None:
                # Assume pip will install the correct version anyway
                if who != self.name:
                    msg = "Component %r asked for package '%s'" " and '%s' is being selected from %r instead..."
                    LOG.debug(msg, self.name, pip_req, there_pip, who)
                return True
            else:
                if who != self.name:
                    msg = "Component %r provides package '%s'" " but '%s' is being asked for by %r instead..."
                    LOG.warn(msg, who, there_pip, pip_req, self.name)
                return False

        LOG.debug("Attempting to find who satisfies pip requirement '%s'", pip_req)

        # Try to find it in anyones pip -> pkg list
        all_pip_2_pkgs = {self.name: self.pips_to_packages}
        # Gather them all (but only if they activate before me)
        # since if they activate after, we can't depend on it
        # to satisfy our requirement...
        for (name, c) in self.instances.items():
            if c is self or not c.activated:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pip_2_pkgs[name] = c.pips_to_packages
        for (who, pips_2_pkgs) in all_pip_2_pkgs.items():
            for pip_info in pips_2_pkgs:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip->pkg '%s' from component %r", there_pip, who)
                return (dict(pip_info.get("package")), False)

        # Ok nobody had it in a pip->pkg mapping
        # but see if they had it in there pip collection
        all_pips = {self.name: self._base_pips()}  # Use base pips to avoid recursion...
        for (name, c) in self.instances.items():
            if not c.activated or c is self:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pips[name] = c._base_pips()  # pylint: disable=W0212
        for (who, there_pips) in all_pips.items():
            for pip_info in there_pips:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip '%s' from component %r", there_pip, who)
                return (dict(pip_info), True)
        return (None, False)
Esempio n. 2
0
    def _match_pip_requires(self, pip_req):
        def pip_use(who, there_pip):
            if there_pip.key != pip_req.key:
                return False
            if not len(pip_req.specs):
                # No version/restrictions specified
                return True
            there_version = None
            if there_pip.version is not None:
                there_version = str(there_pip.version)
            if there_version in pip_req:
                return True
            # Different possibly incompat. versions found...
            if there_version is None:
                # Assume pip will install the correct version anyway
                if who != self.name:
                    msg = "Component %r asked for package '%s'" " and '%s' is being selected from %r instead..."
                    LOG.debug(msg, self.name, pip_req, there_pip, who)
                return True
            else:
                if who != self.name:
                    msg = "Component %r provides package '%s'" " but '%s' is being asked for by %r instead..."
                    LOG.warn(msg, who, there_pip, pip_req, self.name)
                return False

        LOG.debug("Attempting to find who satisfies pip requirement '%s'", pip_req)

        # Try to find it in anyones pip -> pkg list
        all_pip_2_pkgs = {self.name: self.pips_to_packages}
        # Gather them all (but only if they activate before me)
        # since if they activate after, we can't depend on it
        # to satisfy our requirement...
        for (name, c) in self.instances.items():
            if c is self or not c.activated:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pip_2_pkgs[name] = c.pips_to_packages
        for (who, pips_2_pkgs) in all_pip_2_pkgs.items():
            for pip_info in pips_2_pkgs:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip->pkg '%s' from component %r", there_pip, who)
                return (dict(pip_info.get("package")), False)

        # Ok nobody had it in a pip->pkg mapping
        # but see if they had it in there pip collection
        all_pips = {self.name: self._base_pips()}  # Use base pips to avoid recursion...
        for (name, c) in self.instances.items():
            if not c.activated or c is self:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pips[name] = c._base_pips()  # pylint: disable=W0212
        for (who, there_pips) in all_pips.items():
            for pip_info in there_pips:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip '%s' from component %r", there_pip, who)
                return (dict(pip_info), True)

        # Ok nobody had it in there pip->pkg mapping or pip mapping
        # but now lets see if we can automatically find
        # a pip->pkg mapping for them using the good ole'
        # rpm/yum database.
        installer = make_packager({}, self.distro.package_manager_class, distro=self.distro)

        # TODO(harlowja): make this better
        if installer and hasattr(installer, "match_pip_2_package"):
            try:
                dist_pkg = installer.match_pip_2_package(pip_req)
                if dist_pkg:
                    pkg_info = {"name": str(dist_pkg.name), "version": str(dist_pkg.version), "__requirement": dist_pkg}
                    LOG.debug("Auto-matched %s -> %s", pip_req, dist_pkg)
                    return (pkg_info, False)
            except excp.DependencyException as e:
                LOG.warn("Unable to automatically map pip to package: %s", e)

        return (None, False)
Esempio n. 3
0
    def _match_pip_requires(self, pip_req):

        def pip_use(who, there_pip):
            if there_pip.key != pip_req.key:
                return False
            if not len(pip_req.specs):
                # No version/restrictions specified
                return True
            there_version = None
            if there_pip.version is not None:
                there_version = str(there_pip.version)
            if there_version in pip_req:
                return True
            # Different possibly incompat. versions found...
            if there_version is None:
                # Assume pip will install the correct version anyway
                if who != self.name:
                    msg = ("Component %r asked for package '%s'"
                           " and '%s' is being selected from %r instead...")
                    LOG.debug(msg, self.name, pip_req, there_pip, who)
                return True
            else:
                if who != self.name:
                    msg = ("Component %r provides package '%s'"
                           " but '%s' is being asked for by %r instead...")
                    LOG.warn(msg, who, there_pip, pip_req, self.name)
                return False

        LOG.debug("Attempting to find who satisfies pip requirement '%s'", pip_req)

        # Try to find it in anyones pip -> pkg list
        all_pip_2_pkgs = {
            self.name: self.pips_to_packages,
        }
        # Gather them all (but only if they activate before me)
        # since if they activate after, we can't depend on it
        # to satisfy our requirement...
        for (name, c) in self.instances.items():
            if c is self or not c.activated:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pip_2_pkgs[name] = c.pips_to_packages
        for (who, pips_2_pkgs) in all_pip_2_pkgs.items():
            for pip_info in pips_2_pkgs:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip->pkg '%s' from component %r", there_pip, who)
                return (dict(pip_info.get('package')), False)

        # Ok nobody had it in a pip->pkg mapping
        # but see if they had it in there pip collection
        all_pips = {
            self.name: self._base_pips(),  # Use base pips to avoid recursion...
        }
        for (name, c) in self.instances.items():
            if not c.activated or c is self:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pips[name] = c._base_pips()  # pylint: disable=W0212
        for (who, there_pips) in all_pips.items():
            for pip_info in there_pips:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip '%s' from component %r", there_pip, who)
                return (dict(pip_info), True)
        return (None, False)
Esempio n. 4
0
    def _match_pip_requires(self, pip_req):
        def pip_use(who, there_pip):
            if there_pip.key != pip_req.key:
                return False
            if not len(pip_req.specs):
                # No version/restrictions specified
                return True
            there_version = None
            if there_pip.version is not None:
                there_version = str(there_pip.version)
            if there_version in pip_req:
                return True
            # Different possibly incompat. versions found...
            if there_version is None:
                # Assume pip will install the correct version anyway
                if who != self.name:
                    msg = ("Component %r asked for package '%s'"
                           " and '%s' is being selected from %r instead...")
                    LOG.debug(msg, self.name, pip_req, there_pip, who)
                return True
            else:
                if who != self.name:
                    msg = ("Component %r provides package '%s'"
                           " but '%s' is being asked for by %r instead...")
                    LOG.warn(msg, who, there_pip, pip_req, self.name)
                return False

        LOG.debug("Attempting to find who satisfies pip requirement '%s'",
                  pip_req)

        # Try to find it in anyones pip -> pkg list
        all_pip_2_pkgs = {
            self.name: self.pips_to_packages,
        }
        # Gather them all (but only if they activate before me)
        # since if they activate after, we can't depend on it
        # to satisfy our requirement...
        for (name, c) in self.instances.items():
            if c is self or not c.activated:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pip_2_pkgs[name] = c.pips_to_packages
        for (who, pips_2_pkgs) in all_pip_2_pkgs.items():
            for pip_info in pips_2_pkgs:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip->pkg '%s' from component %r", there_pip,
                          who)
                return (dict(pip_info.get('package')), False)

        # Ok nobody had it in a pip->pkg mapping
        # but see if they had it in there pip collection
        all_pips = {
            self.name:
            self._base_pips(),  # Use base pips to avoid recursion...
        }
        for (name, c) in self.instances.items():
            if not c.activated or c is self:
                continue
            if isinstance(c, (PythonInstallComponent)):
                all_pips[name] = c._base_pips()  # pylint: disable=W0212
        for (who, there_pips) in all_pips.items():
            for pip_info in there_pips:
                there_pip = pip.extract_requirement(pip_info)
                if not pip_use(who, there_pip):
                    continue
                LOG.debug("Matched pip '%s' from component %r", there_pip, who)
                return (dict(pip_info), True)

        # Ok nobody had it in there pip->pkg mapping or pip mapping
        # but now lets see if we can automatically find
        # a pip->pkg mapping for them using the good ole'
        # rpm/yum database.
        installer = make_packager({},
                                  self.distro.package_manager_class,
                                  distro=self.distro)

        # TODO(harlowja): make this better
        if installer and hasattr(installer, 'match_pip_2_package'):
            try:
                dist_pkg = installer.match_pip_2_package(pip_req)
                if dist_pkg:
                    pkg_info = {
                        'name': str(dist_pkg.name),
                        'version': str(dist_pkg.version),
                        '__requirement': dist_pkg,
                    }
                    LOG.debug("Auto-matched %s -> %s", pip_req, dist_pkg)
                    return (pkg_info, False)
            except excp.DependencyException as e:
                LOG.warn("Unable to automatically map pip to package: %s", e)

        return (None, False)