def run(self): try: diff = self.repo.metrics.diff( a_rev=self.args.a_rev, b_rev=self.args.b_rev, targets=self.args.targets, recursive=self.args.recursive, all=self.args.all, ) except DvcException: logger.exception("failed to show metrics diff") return 1 if self.args.json: ui.write_json(diff) else: from dvc.compare import show_diff show_diff( diff, title="Metric", markdown=self.args.markdown, no_path=self.args.no_path, precision=self.args.precision or DEFAULT_PRECISION, round_digits=True, a_rev=self.args.a_rev, b_rev=self.args.b_rev, ) return 0
def run(self): from dvc.exceptions import DvcException try: diff = self.repo.diff( self.args.a_rev, self.args.b_rev, self.args.targets ) show_hash = self.args.show_hash hide_missing = self.args.b_rev or self.args.hide_missing if hide_missing: del diff["not in cache"] for key, entries in diff.items(): entries = sorted( entries, key=lambda entry: entry["path"]["old"] if isinstance(entry["path"], dict) else entry["path"], ) if not show_hash: for entry in entries: del entry["hash"] diff[key] = entries if self.args.json: ui.write_json(diff) elif self.args.markdown: _show_markdown(diff, show_hash, hide_missing) elif diff: self._show_diff(diff, hide_missing) except DvcException: logger.exception("failed to get diff") return 1 return 0
def run(self): try: diff = self.repo.params.diff( a_rev=self.args.a_rev, b_rev=self.args.b_rev, targets=self.args.targets, all=self.args.all, deps=self.args.deps, ) except DvcException: logger.exception("failed to show params diff") return 1 if self.args.json: ui.write_json(diff) else: from dvc.compare import show_diff show_diff( diff, title="Param", markdown=self.args.markdown, no_path=self.args.no_path, show_changes=False, ) return 0
def _show_json(renderers, split=False): from dvc.render.convert import to_json result = { renderer.name: to_json(renderer, split) for renderer in renderers } ui.write_json(result)
def run(self): try: metrics = self.repo.metrics.show( self.args.targets, all_branches=self.args.all_branches, all_tags=self.args.all_tags, all_commits=self.args.all_commits, recursive=self.args.recursive, ) except DvcException: logger.exception("") return 1 if self.args.json: ui.write_json(metrics, default=encode_exception) else: from dvc.compare import show_metrics show_metrics( metrics, markdown=self.args.markdown, all_branches=self.args.all_branches, all_tags=self.args.all_tags, all_commits=self.args.all_commits, precision=self.args.precision or DEFAULT_PRECISION, round_digits=True, ) return 0
def _show_json(renderers, path: None): if any(lambda r: r.needs_output_path for r in renderers) and not path: raise DvcException("Output path ('-o') is required!") result = { renderer.filename: json.loads(renderer.as_json(path=path)) for renderer in renderers } if result: ui.write_json(result)
def run(self): try: all_experiments = self.repo.experiments.show( all_branches=self.args.all_branches, all_tags=self.args.all_tags, all_commits=self.args.all_commits, revs=self.args.rev, num=self.args.num, sha_only=self.args.sha, param_deps=self.args.param_deps, fetch_running=self.args.fetch_running, ) except DvcException: logger.exception("failed to show experiments") return 1 if self.args.json: ui.write_json(all_experiments, default=_format_json) else: precision = ( self.args.precision or None if self.args.csv else DEFAULT_PRECISION ) fill_value = "" if self.args.csv else FILL_VALUE iso = True if self.args.csv else False show_experiments( all_experiments, keep=self.args.keep, drop=self.args.drop, sort_by=self.args.sort_by, sort_order=self.args.sort_order, precision=precision, fill_value=fill_value, iso=iso, pager=not self.args.no_pager, csv=self.args.csv, markdown=self.args.markdown, only_changed=self.args.only_changed, pcp=self.args.pcp, out=self.args.out, open=self.args.open, ) return 0
def run(self): from dvc.repo import lock_repo indent = 1 if self.args.cloud else 0 with lock_repo(self.repo): try: st = self.repo.status( targets=self.args.targets, jobs=self.args.jobs, cloud=self.args.cloud, remote=self.args.remote, all_branches=self.args.all_branches, all_tags=self.args.all_tags, all_commits=self.args.all_commits, with_deps=self.args.with_deps, recursive=self.args.recursive, ) except DvcException: logger.exception("") return 1 if self.args.quiet: return bool(st) if self.args.json: ui.write_json(st) return 0 if st: self._show(st, indent) return 0 # additional hints for the user if not self.repo.index.stages: ui.write(self.EMPTY_PROJECT_MSG) elif self.args.cloud or self.args.remote: remote = self.args.remote or self.repo.config["core"].get( "remote" ) ui.write(self.IN_SYNC_MSG.format(remote=remote)) else: ui.write(self.UP_TO_DATE_MSG) return 0
def run(self): try: all_experiments = self.repo.experiments.show( all_branches=self.args.all_branches, all_tags=self.args.all_tags, all_commits=self.args.all_commits, sha_only=self.args.sha, num=self.args.num, param_deps=self.args.param_deps, ) except DvcException: logger.exception("failed to show experiments") return 1 if self.args.json: ui.write_json(all_experiments, default=_format_json) else: precision = ( self.args.precision or None if self.args.csv else DEFAULT_PRECISION ) fill_value = "" if self.args.csv else FILL_VALUE iso = True if self.args.csv else False show_experiments( all_experiments, include_metrics=self.args.include_metrics, exclude_metrics=self.args.exclude_metrics, include_params=self.args.include_params, exclude_params=self.args.exclude_params, no_timestamp=self.args.no_timestamp, sort_by=self.args.sort_by, sort_order=self.args.sort_order, precision=precision, fill_value=fill_value, iso=iso, pager=not self.args.no_pager, csv=self.args.csv, markdown=self.args.markdown, only_changed=self.args.only_changed, ) return 0
def run(self): from dvc.repo import Repo try: entries = Repo.ls( self.args.url, self.args.path, rev=self.args.rev, recursive=self.args.recursive, dvc_only=self.args.dvc_only, ) if self.args.json: ui.write_json(entries) elif entries: entries = _prettify(entries, with_color=True) ui.write("\n".join(entries)) return 0 except DvcException: logger.exception(f"failed to list '{self.args.url}'") return 1
def run(self): try: diff = self.repo.experiments.diff( a_rev=self.args.a_rev, b_rev=self.args.b_rev, all=self.args.all, param_deps=self.args.param_deps, ) except DvcException: logger.exception("failed to show experiments diff") return 1 if self.args.json: ui.write_json(diff) else: from dvc.compare import show_diff precision = self.args.precision or DEFAULT_PRECISION diffs = [("metrics", "Metric"), ("params", "Param")] for idx, (key, title) in enumerate(diffs): if idx: # we are printing tables even in `--quiet` mode # so we should also be printing the "table" separator ui.write(force=True) show_diff( diff[key], title=title, markdown=self.args.markdown, no_path=self.args.no_path, old=self.args.old, on_empty_diff="diff not supported", precision=precision if key == "metrics" else None, a_rev=self.args.a_rev, b_rev=self.args.b_rev, ) return 0
def run(self): from pathlib import Path from dvc.render.utils import match_renderers, render from dvc.render.vega import VegaRenderer if self.args.show_vega: if not self.args.targets: logger.error("please specify a target for `--show-vega`") return 1 if len(self.args.targets) > 1: logger.error( "you can only specify one target for `--show-vega`") return 1 if self.args.json: logger.error( "'--show-vega' and '--json' are mutually exclusive " "options.") return 1 try: plots_data = self._func(targets=self.args.targets, props=self._props()) if not plots_data: ui.error_write("No plots were loaded, " "visualization file will not be created.") renderers = match_renderers(plots_data=plots_data, templates=self.repo.plots.templates) if self.args.show_vega: renderer = first( filter(lambda r: isinstance(r, VegaRenderer), renderers)) if renderer: ui.write_json(renderer.asdict()) return 0 if self.args.json: _show_json(renderers, self.args.out) return 0 rel: str = self.args.out or "dvc_plots" path: Path = (Path.cwd() / rel).resolve() index_path = render( self.repo, renderers, path=path, html_template_path=self.args.html_template, ) ui.write(index_path.as_uri()) auto_open = self.repo.config["plots"].get("auto_open", False) if self.args.open or auto_open: if not auto_open: ui.write("To enable auto opening, you can run:\n" "\n" "\tdvc config plots.auto_open true") return ui.open_browser(index_path) return 0 except DvcException: logger.exception("") return 1
def run(self): from pathlib import Path from dvc.render.match import match_renderers from dvc_render import render_html if self.args.show_vega: if not self.args.targets: logger.error("please specify a target for `--show-vega`") return 1 if len(self.args.targets) > 1: logger.error( "you can only specify one target for `--show-vega`") return 1 if self.args.json: logger.error( "'--show-vega' and '--json' are mutually exclusive " "options.") return 1 try: plots_data = self._func(targets=self.args.targets, props=self._props()) if not plots_data: ui.error_write("No plots were loaded, " "visualization file will not be created.") out: str = self.args.out or self.repo.config.get("plots", {}).get( "out_dir", "dvc_plots") renderers_out = (out if self.args.json else os.path.join( out, "static")) renderers = match_renderers( plots_data=plots_data, out=renderers_out, templates_dir=self.repo.plots.templates_dir, ) if self.args.show_vega: renderer = first(filter(lambda r: r.TYPE == "vega", renderers)) if renderer: ui.write_json(json.loads(renderer.get_filled_template())) return 0 if self.args.json: _show_json(renderers, self.args.split) return 0 html_template_path = self.args.html_template if not html_template_path: html_template_path = self.repo.config.get("plots", {}).get( "html_template", None) if html_template_path and not os.path.isabs( html_template_path): html_template_path = os.path.join(self.repo.dvc_dir, html_template_path) output_file: Path = (Path.cwd() / out).resolve() / "index.html" render_html( renderers=renderers, output_file=output_file, template_path=html_template_path, ) ui.write(output_file.as_uri()) auto_open = self.repo.config["plots"].get("auto_open", False) if self.args.open or auto_open: if not auto_open: ui.write("To enable auto opening, you can run:\n" "\n" "\tdvc config plots.auto_open true") return ui.open_browser(output_file) return 0 except DvcException: logger.exception("") return 1