def run(self): from pathlib import Path 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 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.") if self.args.show_vega: target = self.args.targets[0] plot_json = find_vega(self.repo, plots_data, target) if plot_json: ui.write(plot_json) return 0 rel: str = self.args.out or "dvc_plots" path: Path = (Path.cwd() / rel).resolve() index_path = render( self.repo, plots_data, path=path, html_template_path=self.args.html_template, ) ui.write(index_path.as_uri()) if self.args.open: return ui.open_browser(index_path) return 0 except DvcException: logger.exception("") return 1
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 show_experiments( all_experiments, keep=None, drop=None, pager=True, csv=False, markdown=False, pcp=False, **kwargs, ): from funcy.seqs import flatten as flatten_list metric_names, param_names, deps_names = _collect_names(all_experiments) headers = [ "Experiment", "rev", "typ", "Created", "parent", "State", "Executor", ] names = {**metric_names, **param_names} counter = Counter(flatten_list([list(a.keys()) for a in names.values()])) counter.update(headers) metric_headers = _normalize_headers(metric_names, counter) param_headers = _normalize_headers(param_names, counter) td = experiments_table( all_experiments, headers, metric_headers, metric_names, param_headers, param_names, deps_names, kwargs.get("sort_by"), kwargs.get("sort_order"), kwargs.get("precision"), kwargs.get("fill_value"), kwargs.get("iso"), ) if keep: for col in td.keys(): if re.match(keep, col): td.protect(col) for col in ("State", "Executor"): if td.is_empty(col): td.drop(col) row_styles = lmap(baseline_styler, td.column("typ")) if not csv: merge_headers = ["Experiment", "rev", "typ", "parent"] td.column("Experiment")[:] = map( prepare_exp_id, td.as_dict(merge_headers) ) td.drop(*merge_headers[1:]) headers = { "metrics": metric_headers, "params": param_headers, "deps": deps_names, } styles = { "Experiment": {"no_wrap": True, "header_style": "black on grey93"}, "Created": {"header_style": "black on grey93"}, "State": {"header_style": "black on grey93"}, "Executor": {"header_style": "black on grey93"}, } header_bg_colors = { "metrics": "cornsilk1", "params": "light_cyan1", "deps": "plum2", } styles.update( { header: { "justify": "right" if typ == "metrics" else "left", "header_style": f"black on {header_bg_colors[typ]}", "collapse": idx != 0, "no_wrap": typ == "metrics", } for typ, hs in headers.items() for idx, header in enumerate(hs) } ) if kwargs.get("only_changed", False) or pcp: td.drop_duplicates("cols", ignore_empty=False) cols_to_drop = set() if drop is not None: cols_to_drop = {col for col in td.keys() if re.match(drop, col)} if pcp: cols_to_drop.add("Created") td.drop(*cols_to_drop) if pcp: subset = {x for x in td.keys() if x != "Experiment"} td.dropna( "rows", how="all", subset=subset, ) td.drop_duplicates("rows", subset=subset) td.column("Experiment")[:] = [ # remove tree characters str(x).encode("ascii", "ignore").strip().decode() for x in td.column("Experiment") ] out = kwargs.get("out") or "dvc_plots" ui.write( td.to_parallel_coordinates( output_path=os.path.abspath(out), color_by=kwargs.get("sort_by") or "Experiment", ) ) if kwargs.get("open"): return ui.open_browser(os.path.join(out, "index.html")) else: td.render( pager=pager, borders="horizontals", rich_table=True, header_styles=styles, row_styles=row_styles, csv=csv, markdown=markdown, )
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
def webbrowser_open(url: str) -> int: from dvc.ui import ui return ui.open_browser(url)