Esempio n. 1
0
def _remove_commited_exps(repo, remote: Optional[str],
                          exp_names: List[str]) -> List[str]:
    remain_list = []
    remove_list = []
    for exp_name in exp_names:
        ref_info = resolve_exp_ref(repo.scm, exp_name, remote)

        if ref_info:
            remove_list.append(ref_info)
        else:
            remain_list.append(exp_name)
    if remove_list:
        if not remote:
            remove_exp_refs(repo.scm, remove_list)
        else:
            from dvc.scm import TqdmGit

            for ref_info in remove_list:
                with TqdmGit(desc="Pushing git refs") as pbar:
                    push_refspec(
                        repo.scm,
                        remote,
                        None,
                        str(ref_info),
                        progress=pbar.update_git,
                    )
    return remain_list
Esempio n. 2
0
def pull(
    repo, git_remote, exp_name, *args, force=False, pull_cache=False, **kwargs
):
    exp_ref_dict = resolve_name(repo.scm, exp_name, git_remote)
    exp_ref = exp_ref_dict[exp_name]
    if not exp_ref:
        raise InvalidArgumentError(
            f"Experiment '{exp_name}' does not exist in '{git_remote}'"
        )

    def on_diverged(refname: str, rev: str) -> bool:
        if repo.scm.get_ref(refname) == rev:
            return True
        raise DvcException(
            f"Local experiment '{exp_name}' has diverged from remote "
            "experiment with the same name. To override the local experiment "
            "re-run with '--force'."
        )

    refspec = f"{exp_ref}:{exp_ref}"
    logger.debug("git pull experiment '%s' -> '%s'", git_remote, refspec)

    from dvc.scm import TqdmGit

    with TqdmGit(desc="Fetching git refs") as pbar:
        repo.scm.fetch_refspecs(
            git_remote,
            [refspec],
            force=force,
            on_diverged=on_diverged,
            progress=pbar.update_git,
        )

    if pull_cache:
        _pull_cache(repo, exp_ref, **kwargs)
Esempio n. 3
0
File: push.py Progetto: pmrowla/dvc
def _push(
    repo,
    git_remote: str,
    refs: Iterable["ExpRefInfo"],
    force: bool,
) -> Mapping[SyncStatus, List["ExpRefInfo"]]:
    from scmrepo.exceptions import AuthError

    from ...scm import GitAuthError

    refspec_list = [f"{exp_ref}:{exp_ref}" for exp_ref in refs]
    logger.debug(f"git push experiment '{refs}' -> '{git_remote}'")

    with TqdmGit(desc="Pushing git refs") as pbar:
        try:
            results: Mapping[str, SyncStatus] = repo.scm.push_refspecs(
                git_remote,
                refspec_list,
                force=force,
                progress=pbar.update_git,
            )
        except AuthError as exc:
            raise GitAuthError(str(exc))

    def group_result(refspec):
        return results[str(refspec)]

    pull_result: Mapping[SyncStatus, List["ExpRefInfo"]] = group_by(
        group_result, refs
    )

    return pull_result
Esempio n. 4
0
def _push(
    repo,
    git_remote: str,
    refs: Iterable["ExpRefInfo"],
    force: bool,
):
    def on_diverged(refname: str, rev: str) -> bool:
        if repo.scm.get_ref(refname) == rev:
            return True
        exp_name = refname.split("/")[-1]
        raise DvcException(
            f"Local experiment '{exp_name}' has diverged from remote "
            "experiment with the same name. To override the remote experiment "
            "re-run with '--force'.")

    logger.debug(f"git push experiment '{refs}' -> '{git_remote}'")

    for exp_ref in refs:
        with TqdmGit(desc="Pushing git refs") as pbar:
            push_refspec(
                repo.scm,
                git_remote,
                str(exp_ref),
                str(exp_ref),
                force=force,
                on_diverged=on_diverged,
                progress=pbar.update_git,
            )
Esempio n. 5
0
def _pull(
    repo,
    git_remote: str,
    exp_refs,
    force: bool,
    pull_cache: bool,
    **kwargs,
):
    def on_diverged(refname: str, rev: str) -> bool:
        if repo.scm.get_ref(refname) == rev:
            return True
        exp_name = refname.split("/")[-1]
        raise DvcException(
            f"Local experiment '{exp_name}' has diverged from remote "
            "experiment with the same name. To override the local experiment "
            "re-run with '--force'.")

    refspec_list = [f"{exp_ref}:{exp_ref}" for exp_ref in exp_refs]
    logger.debug(f"git pull experiment '{git_remote}' -> '{refspec_list}'")

    with TqdmGit(desc="Fetching git refs") as pbar:
        repo.scm.fetch_refspecs(
            git_remote,
            refspec_list,
            force=force,
            on_diverged=on_diverged,
            progress=pbar.update_git,
        )

    if pull_cache:
        _pull_cache(repo, exp_refs, **kwargs)
Esempio n. 6
0
def _remove_commited_exps(scm: "Git", exp_ref_dict: Mapping["ExpRefInfo", str],
                          remote: Optional[str]) -> List[str]:
    if remote:
        from dvc.scm import TqdmGit

        for ref_info in exp_ref_dict:
            with TqdmGit(desc="Pushing git refs") as pbar:
                push_refspec(
                    scm,
                    remote,
                    None,
                    str(ref_info),
                    progress=pbar.update_git,
                )
    else:
        remove_exp_refs(scm, exp_ref_dict)
    return list(exp_ref_dict.values())
Esempio n. 7
0
def push(
    repo,
    git_remote,
    exp_name: str,
    *args,
    force=False,
    push_cache=False,
    **kwargs,
):
    exp_ref = resolve_exp_ref(repo.scm, exp_name)
    if not exp_ref:
        raise InvalidArgumentError(
            f"'{exp_name}' is not a valid experiment name"
        )

    def on_diverged(refname: str, rev: str) -> bool:
        if repo.scm.get_ref(refname) == rev:
            return True
        raise DvcException(
            f"Local experiment '{exp_name}' has diverged from remote "
            "experiment with the same name. To override the remote experiment "
            "re-run with '--force'."
        )

    refname = str(exp_ref)
    logger.debug("git push experiment '%s' -> '%s'", exp_ref, git_remote)

    from dvc.scm import TqdmGit

    with TqdmGit(desc="Pushing git refs") as pbar:
        push_refspec(
            repo.scm,
            git_remote,
            refname,
            refname,
            force=force,
            on_diverged=on_diverged,
            progress=pbar.update_git,
        )

    if push_cache:
        _push_cache(repo, exp_ref, **kwargs)
Esempio n. 8
0
File: pull.py Progetto: pmrowla/dvc
def _pull(
    repo,
    git_remote: str,
    refs: Iterable["ExpRefInfo"],
    force: bool,
) -> Mapping[SyncStatus, List["ExpRefInfo"]]:
    refspec_list = [f"{exp_ref}:{exp_ref}" for exp_ref in refs]
    logger.debug(f"git pull experiment '{git_remote}' -> '{refspec_list}'")

    with TqdmGit(desc="Fetching git refs") as pbar:
        results: Mapping[str, SyncStatus] = repo.scm.fetch_refspecs(
            git_remote,
            refspec_list,
            force=force,
            progress=pbar.update_git,
        )

    def group_result(refspec):
        return results[str(refspec)]

    pull_result: Mapping[SyncStatus,
                         List["ExpRefInfo"]] = group_by(group_result, refs)

    return pull_result