def main(args): cmd_impl_support.init_model_path() formatted = [_format_op(op, model) for op, model in _iter_ops(args.path)] filtered = [op for op in formatted if _filter_op(op, args)] cli.table(sorted(filtered, key=lambda m: m["fullname"]), cols=["fullname", "description"], detail=(["main", "flags", "details"] if args.verbose else []))
def main(args): cmd_impl_support.init_resource_path(args) formatted = [_format_resource(r) for r in resource.iter_resources()] filtered = [r for r in formatted if _filter_resource(r, args)] cli.table(sorted(filtered, key=lambda r: r["name"]), cols=["name", "description"], detail=(["sources"] if args.verbose else []))
def _runs_op(args, ctx, force_deleted, preview_msg, confirm_prompt, no_runs_help, op_callback, default_runs_arg=None, confirm_default=False, runs_callback=None): get_selected = runs_callback or _runs_op_selected selected = get_selected(args, ctx, default_runs_arg, force_deleted) if not selected: _no_selected_runs_exit(no_runs_help) formatted = [run_util.format_run(run) for run in selected] if not args.yes: cli.out(preview_msg) cols = [ "short_index", "operation_with_marked", "started", "status_with_remote", "label" ] cli.table(formatted, cols=cols, indent=2) formatted_confirm_prompt = confirm_prompt.format(count=len(formatted)) if args.yes or cli.confirm(formatted_confirm_prompt, confirm_default): if len(inspect.getargspec(op_callback).args) == 2: op_callback(selected, formatted) else: op_callback(selected)
def runs_op(args, ctx, force_deleted, preview_msg, confirm_prompt, no_runs_help, op_callback, default_runs_arg=None, confirm_default=False, runs_callback=None): get_selected = runs_callback or runs_op_selected selected = get_selected(args, ctx, default_runs_arg, force_deleted) if not selected: _no_selected_runs_exit(no_runs_help) formatted = None # expensive, lazily init as needed if not args.yes: formatted = formatted = format_runs(selected) cli.out(preview_msg) cols = [ "short_index", "op_desc", "started", "status_with_remote", "label" ] cli.table(formatted, cols=cols, indent=2) fmt_confirm_prompt = confirm_prompt.format(count=len(selected)) if args.yes or cli.confirm(fmt_confirm_prompt, confirm_default): # pylint: disable=deprecated-method if len(inspect.getargspec(op_callback).args) == 2: formatted = formatted = format_runs(selected) op_callback(selected, formatted) else: op_callback(selected)
def list_runs(args): runs = runs_for_args(args) formatted = [format_run(run, i) for i, run in enumerate(runs)] filtered = _filter_runs(formatted, args.filters) cols = ["index", "operation", "started", "status", "label"] detail = RUN_DETAIL if args.verbose else None cli.table(filtered, cols=cols, detail=detail)
def _print_matching_runs(runs): formatted = [run_util.format_run(run) for run in runs] cols = [ "index", "operation", "started", "status_with_remote", "label" ] cli.table(formatted, cols=cols, indent=2)
def main(args): cmd_impl_support.init_model_path() formatted = [_format_model(m) for m in iter_models(args.path)] filtered = [m for m in formatted if _filter_model(m, args)] cli.table( sorted(filtered, key=lambda m: m["fullname"]), cols=["fullname", "description"], detail=(["source", "operations", "details"] if args.verbose else []))
def _list_formatted_runs(runs, args): formatted = format_runs(_limit_runs(runs, args)) cols = ["index", "op_desc", "started", "status_with_remote", "label"] detail = RUN_DETAIL if args.verbose else None cli.table(formatted, cols=cols, detail=detail, max_width_adj=STYLE_TABLE_WIDTH_ADJ)
def main(): remotes = config.user_config().get("remotes", {}) data = [{ "name": name, "type": r.get("type", ""), "desc": r.get("description", ""), } for name, r in sorted(remotes.items())] cli.table(data, ["name", "type", "desc"])
def main(args): cmd_impl_support.init_model_path() filtered = filtered_ops(args) cli.table( sorted(filtered, key=_op_sort_key), cols=["fullname", "description"], detail=(["main", "flags", "details"] if args.verbose else []), )
def main(args): results = pip_util.search(list(args.terms)) filtered = _filter_packages(results, args) formatted = [_format_package(pkg) for pkg in filtered] cli.table( formatted, cols=["name", "version", "description"], sort=["name"])
def print_runs(self, runs=None, flags=False, labels=False, status=False): if runs is None: runs = self.list_runs() cols = self._cols_for_print_runs(flags, labels, status) rows = [] with Chdir(self.cwd): for run in runs: rows.append(self._row_for_print_run(run, flags, labels, status)) cli.table(rows, cols)
def _missing_required_flags_error(e): cli.out("Operation requires the following missing flags:\n", err=True) cli.table( [{"name": flag.name, "desc": flag.description} for flag in e.missing], ["name", "desc"], indent=2, err=True, ) cli.out( "\nRun the command again with these flags specified " "as NAME=VAL.", err=True ) cli.error()
def _invalid_flag_choice_error(e): cli.out("Unsupported value for '%s' - supported values are:\n" % e.flag.name, err=True) cli.table([{ "val": choice.value, "desc": choice.description } for choice in e.flag.choices], ["val", "desc"], indent=2, err=True) cli.out("\nRun the command again using one of these options.", err=True) cli.error()
def _format_runs_for_comment_msg(runs): out = six.StringIO() formatted = format_runs(runs) cols = [ "short_index", "op_desc", "started", "status_with_remote", "label", ] cli.table(formatted, cols=cols, indent=2, file=out) return out.getvalue().strip()
def _print_table(args): data = get_data(args, skip_header_if_empty=True) if not data: return cols = data[0] col_indexes = list(zip(cols, range(len(cols)))) def format_row(row): return {col_name: row[i] for col_name, i in col_indexes} heading = {col_name: col_name for col_name in cols} data = [heading] + [format_row(row) for row in data[1:]] cli.table(data, cols, max_width_adj=NO_TABLE_CLIP_WIDTH)
def print_runs( self, runs=None, flags=False, labels=False, status=False, cwd=None, limit=None): cwd = os.path.join(self.cwd, cwd) if cwd else self.cwd if runs is None: runs = self.list_runs(limit=limit) cols = self._cols_for_print_runs(flags, labels, status) rows = [] with Chdir(cwd): for run in runs: rows.append(self._row_for_print_run( run, flags, labels, status)) cli.table(rows, cols)
def _runs_op(args, ctx, force_delete, preview_msg, confirm_prompt, no_runs_help, op_callback): runs = runs_for_args(args, force_delete) runs_arg = args.runs or ALL_RUNS_ARG selected = selected_runs(runs, runs_arg, ctx) if not selected: _no_selected_runs_error(no_runs_help) preview = [format_run(run) for run in selected] if not args.yes: cli.out(preview_msg) cols = ["short_index", "operation", "started", "status"] cli.table(preview, cols=cols, indent=2) if args.yes or cli.confirm(confirm_prompt): op_callback(selected)
def _list_formatted_runs(runs, args): formatted = [] for i, run in enumerate(runs): try: formatted_run = run_util.format_run(run, i + 1) except Exception: log.exception("formatting run in %s", run.path) else: formatted.append(formatted_run) limited_formatted = _limit_runs(formatted, args) cols = [ "index", "operation_with_marked", "started", "status_with_remote", "label" ] detail = RUN_DETAIL if args.verbose else None cli.table(limited_formatted, cols=cols, detail=detail)
def _list_runs_comments(runs, comment_index_format=True): formatted_runs = format_runs(runs) cols = [ _col1_for_comments_header(comment_index_format), "op_desc", "started", "status_with_remote", "label", ] cli.table( formatted_runs, cols, detail=["_run"], detail_cb=_run_comments_detail_cb(comment_index_format), max_width_adj=STYLE_TABLE_WIDTH_ADJ, fg=_fg_for_comments_header(comment_index_format), )
def _validate_opdef_flags(opdef): vals = opdef.flag_values() missing = [] for flag in opdef.flags: if flag.required and not vals.get(flag.name): missing.append(flag) if missing: cli.out("Operation '%s' requires the following missing flags:\n" % opdef.fullname, err=True) cli.table([{ "name": flag.name, "desc": flag.description } for flag in missing], ["name", "desc"], indent=2, err=True) cli.out( "\nRun the command again with missing flags specified as NAME=VAL.", err=True) cli.error()
def list_packages(args): installed = pip_util.get_installed() packages = [pkg for pkg in installed if args.all or _is_gpkg(pkg)] formatted = [_format_pkg(pkg) for pkg in packages] filtered = [pkg for pkg in formatted if _filter_model(pkg, args)] cli.table(filtered, cols=["name", "version", "summary"], sort=["name"])
def _skip_needed_matches_info(matching_runs): cli.out("Skipping because the following runs match " "this operation (--needed specified):") formatted = [run_util.format_run(run) for run in matching_runs] cols = ["index", "operation", "started", "status_with_remote", "label"] cli.table(formatted, cols=cols, indent=2)
def _print_trials(trials): if trials: data, cols = _trials_table_data(trials) cli.table(data, cols)
def list_packages(args): pkgs = packages(args.all) formatted = [_format_pkg(pkg) for pkg in pkgs] filtered = [pkg for pkg in formatted if _filter_model(pkg, args)] cli.table(filtered, cols=["name", "version", "summary"], sort=["name"])
def _print_trials(trials): if trials: data, cols = _trials_table_data(trials, format=True) cli.table(data, cols)
def print_trials(trials): from guild import cli data, cols = _trials_table_data(trials) cli.table(data, cols)
def main(args): formatted = [_format_package(pkg) for pkg in _search(args)] cli.table(formatted, cols=["name", "version", "description"], sort=["name"])