Пример #1
0
def _show_diff(diff, markdown=False, no_path=False, precision=None):
    from collections import OrderedDict

    from dvc.utils.diff import table

    if precision is None:
        precision = DEFAULT_PRECISION

    def _round(val):
        if isinstance(val, float):
            return round(val, precision)

        return val

    rows = []
    for fname, mdiff in diff.items():
        sorted_mdiff = OrderedDict(sorted(mdiff.items()))
        for metric, change in sorted_mdiff.items():
            row = [] if no_path else [fname]
            row.append(metric)
            row.append(_round(change.get("old")))
            row.append(_round(change["new"]))
            row.append(_round(change.get("diff")))
            rows.append(row)

    header = [] if no_path else ["Path"]
    header.append("Metric")
    header.extend(["Old", "New"])
    header.append("Change")

    return table(header, rows, markdown)
Пример #2
0
def _show_diff(
    diff,
    title="",
    markdown=False,
    no_path=False,
    old=False,
    precision=DEFAULT_PRECISION,
):
    from dvc.utils.diff import table

    rows = []
    for fname, diff_ in diff.items():
        sorted_diff = OrderedDict(sorted(diff_.items()))
        for item, change in sorted_diff.items():
            row = [] if no_path else [fname]
            row.append(item)
            if old:
                row.append(_format_field(change.get("old"), precision))
            row.append(_format_field(change["new"], precision))
            row.append(
                _format_field(change.get("diff", "diff not supported"),
                              precision))
            rows.append(row)

    header = [] if no_path else ["Path"]
    header.append(title)
    if old:
        header.extend(["Old", "New"])
    else:
        header.append("Value")
    header.append("Change")

    return table(header, rows, markdown)
Пример #3
0
def _show_diff(
    diff, title="", markdown=False, no_path=False, old=False, precision=None
):
    from dvc.utils.diff import table

    if precision is None:
        precision = DEFAULT_PRECISION

    def _round(val):
        if isinstance(val, float):
            return round(val, precision)

        return val

    rows = []
    for fname, diff_ in diff.items():
        sorted_diff = OrderedDict(sorted(diff_.items()))
        for item, change in sorted_diff.items():
            row = [] if no_path else [fname]
            row.append(item)
            if old:
                row.append(_round(change.get("old")))
            row.append(_round(change["new"]))
            row.append(_round(change.get("diff", "diff not supported")))
            rows.append(row)

    header = [] if no_path else ["Path"]
    header.append(title)
    if old:
        header.extend(["Old", "New"])
    else:
        header.append("Value")
    header.append("Change")

    return table(header, rows, markdown)
Пример #4
0
def _show_diff(diff, markdown=False, no_path=False, old=False):
    from collections import OrderedDict

    from dvc.utils.diff import table

    rows = []
    for fname, mdiff in diff.items():
        sorted_mdiff = OrderedDict(sorted(mdiff.items()))
        for metric, change in sorted_mdiff.items():
            row = [] if no_path else [fname]
            row.append(metric)
            if old:
                row.append(change.get("old"))
            row.append(change["new"])
            row.append(change.get("diff", "diff not supported"))
            rows.append(row)

    header = [] if no_path else ["Path"]
    header.append("Metric")
    if old:
        header.extend(["Old", "New"])
    else:
        header.append("Value")
    header.append("Change")

    return table(header, rows, markdown)
Пример #5
0
def _show_metrics(
    metrics,
    markdown=False,
    all_branches=False,
    all_tags=False,
    all_commits=False,
    precision=None,
):
    from dvc.utils.diff import format_dict, table
    from dvc.utils.flatten import flatten

    # When `metrics` contains a `None` key, it means that some files
    # specified as `targets` in `repo.metrics.show` didn't contain any metrics.
    missing = metrics.pop(None, None)
    with_rev = any([all_branches, all_tags, all_commits])
    header_set = set()
    rows = []

    if precision is None:
        precision = DEFAULT_PRECISION

    def _round(val):
        if isinstance(val, float):
            return round(val, precision)
        return val

    for _branch, val in metrics.items():
        for _fname, metric in val.items():
            if not isinstance(metric, dict):
                header_set.add("")
                continue
            for key, _val in flatten(format_dict(metric)).items():
                header_set.add(key)
    header = sorted(header_set)
    for branch, val in metrics.items():
        for fname, metric in val.items():
            row = []
            if with_rev:
                row.append(branch)
            row.append(fname)
            if not isinstance(metric, dict):
                row.append(str(metric))
                rows.append(row)
                continue
            flattened_val = flatten(format_dict(metric))

            for i in header:
                row.append(_round(flattened_val.get(i)))
            rows.append(row)
    header.insert(0, "Path")
    if with_rev:
        header.insert(0, "Revision")

    if missing:
        raise BadMetricError(missing)
    return table(header, rows, markdown)
Пример #6
0
def _show_diff(diff):
    from dvc.utils.diff import table

    rows = []
    for fname, pdiff in diff.items():
        sorted_pdiff = OrderedDict(sorted(pdiff.items()))
        for param, change in sorted_pdiff.items():
            rows.append([fname, param, change["old"], change["new"]])

    return table(["Path", "Param", "Old", "New"], rows)
Пример #7
0
def _show_md(diff):
    from dvc.utils.diff import table

    rows = []
    for status in ["added", "deleted", "modified"]:
        entries = diff.get(status, [])
        if not entries:
            continue
        paths = sorted([entry["path"] for entry in entries])
        for path in paths:
            rows.append([status, path])

    return table(["Status", "Path"], rows, True)
Пример #8
0
def _show_diff(diff):
    from dvc.utils.diff import table

    rows = []
    for fname, mdiff in diff.items():
        for metric, change in mdiff.items():
            rows.append(
                [
                    fname,
                    metric,
                    change["new"],
                    change.get("diff", "diff not supported"),
                ]
            )

    return table(["Path", "Metric", "Value", "Change"], rows)
Пример #9
0
def _show_diff(diff):
    from collections import OrderedDict

    from dvc.utils.diff import table

    rows = []
    for fname, mdiff in diff.items():
        sorted_mdiff = OrderedDict(sorted(mdiff.items()))
        for metric, change in sorted_mdiff.items():
            rows.append([
                fname,
                metric,
                change["new"],
                change.get("diff", "diff not supported"),
            ])

    return table(["Path", "Metric", "Value", "Change"], rows)
Пример #10
0
def _show_md(diff, show_hash=False):
    from dvc.utils.diff import table

    header = ["Status", "Hash", "Path"] if show_hash else ["Status", "Path"]
    rows = []
    for status in ["added", "deleted", "modified"]:
        entries = diff.get(status, [])
        if not entries:
            continue
        for entry in entries:
            path = entry["path"]
            if show_hash:
                check_sum = _digest(entry.get("hash", ""))
                rows.append([status, check_sum, path])
            else:
                rows.append([status, path])

    return table(header, rows, True)
Пример #11
0
    def run(self):
        from dvc.utils.diff import table

        def log_error(relpath: str, exc: Exception):
            if self.args.fail:
                raise exc
            logger.debug("Stages from %s failed to load", relpath)

        # silence stage collection error by default
        self.repo.stage_collection_error_handler = log_error

        stages = self._get_stages()
        names_only = self.args.names_only

        data = prepare_stages_data(stages, description=not names_only)
        if data:
            print(table(header=(), rows=data.items()))

        return 0
Пример #12
0
def _show_diff(diff, markdown=False, no_path=False):
    from dvc.utils.diff import table

    rows = []
    for fname, pdiff in diff.items():
        sorted_pdiff = OrderedDict(sorted(pdiff.items()))
        for param, change in sorted_pdiff.items():
            row = [] if no_path else [fname]
            row.append(param)
            row.append(change["old"])
            row.append(change["new"])
            rows.append(row)

    header = [] if no_path else ["Path"]
    header.append("Param")
    header.append("Old")
    header.append("New")

    return table(header, rows, markdown)
Пример #13
0
def _show_md(diff, show_hash=False, hide_missing=False):
    from dvc.utils.diff import table

    header = ["Status", "Hash", "Path"] if show_hash else ["Status", "Path"]
    rows = []
    statuses = ["added", "deleted", "renamed", "modified"]
    if not hide_missing:
        statuses.append("not in cache")
    for status in statuses:
        entries = diff.get(status, [])
        if not entries:
            continue
        for entry in entries:
            path = entry["path"]
            if isinstance(path, dict):
                path = f"{path['old']} -> {path['new']}"
            if show_hash:
                check_sum = _digest(entry.get("hash", ""))
                rows.append([status, check_sum, path])
            else:
                rows.append([status, path])

    return table(header, rows, True)