示例#1
0
    def install(  # pylint: disable=arguments-differ
        self,
        name,
        requirements=None,
        silent=False,
        after_update=False,
        interactive=False,
        force=False,
    ):
        _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
        if not _url:
            name = "id=%d" % self.search_lib_id(
                {
                    "name": _name,
                    "requirements": _requirements
                },
                silent=silent,
                interactive=interactive,
            )
            requirements = _requirements
        pkg_dir = BasePkgManager.install(
            self,
            name,
            requirements,
            silent=silent,
            after_update=after_update,
            force=force,
        )

        if not pkg_dir:
            return None

        manifest = None
        try:
            manifest = ManifestParserFactory.new_from_dir(pkg_dir).as_dict()
        except ManifestException:
            pass
        if not manifest or not manifest.get("dependencies"):
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        builtin_lib_storages = None
        for filters in manifest["dependencies"]:
            assert "name" in filters

            # avoid circle dependencies
            if not self.INSTALL_HISTORY:
                self.INSTALL_HISTORY = []
            history_key = str(filters)
            if history_key in self.INSTALL_HISTORY:
                continue
            self.INSTALL_HISTORY.append(history_key)

            if any(s in filters.get("version", "") for s in ("\\", "/")):
                self.install(
                    "{name}={version}".format(**filters),
                    silent=silent,
                    after_update=after_update,
                    interactive=interactive,
                    force=force,
                )
            else:
                try:
                    lib_id = self.search_lib_id(filters, silent, interactive)
                except exception.LibNotFound as e:
                    if builtin_lib_storages is None:
                        builtin_lib_storages = get_builtin_libs()
                    if not silent or is_builtin_lib(builtin_lib_storages,
                                                    filters["name"]):
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_id,
                        filters.get("version"),
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
                else:
                    self.install(
                        lib_id,
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
        return pkg_dir
示例#2
0
 def load_manifest(src):
     mp = ManifestParserFactory.new_from_dir(src)
     return ManifestSchema().load_manifest(mp.as_dict())