-
Notifications
You must be signed in to change notification settings - Fork 6
ls: add --sort-by FIELDS option #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,13 @@ def _create_ls_parser() -> argparse.ArgumentParser: | |
| action="store_true", | ||
| help="List entries in reverse order (most recent first).", | ||
| ) | ||
| parser.add_argument( | ||
| "--sort-by", | ||
| nargs="+", | ||
| metavar="FIELD", | ||
| choices=LS_FIELD_CHOICES, | ||
| help=f"Sort results by one or more fields. Available choices: {', '.join(sorted(LS_FIELD_CHOICES))}.", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just refer to |
||
| ) | ||
| return parser | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,6 +231,21 @@ def ls(args: argparse.Namespace) -> int: | |
| ) | ||
| info_files = [path for path in args.paths if is_info_file(path)] | ||
| run_data_raw = load_duct_runs(info_files, args.eval_filter) | ||
|
|
||
| sort_by = getattr(args, "sort_by", None) | ||
| if sort_by: | ||
|
yarikoptic marked this conversation as resolved.
Outdated
|
||
| flat_data = [_flatten_dict(d) for d in run_data_raw] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think no need for temp store -- just do |
||
| run_data_raw = [ | ||
| item | ||
| for _, item in sorted( | ||
| zip(flat_data, run_data_raw), | ||
| key=lambda x: tuple( | ||
| (x[0].get(k) is None, x[0].get(k) if x[0].get(k) is not None else "") | ||
| for k in sort_by | ||
| ), | ||
| ) | ||
|
Comment on lines
+235
to
+247
|
||
| ] | ||
|
|
||
| output_rows = process_run_data(run_data_raw, args.fields, formatter) | ||
|
|
||
|
Comment on lines
+234
to
251
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does look much cleaner but would it still have all the fields at that point or only what is to be displayed etc? (not looking at the code ATM)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot this does look much cleaner but would it still have all the fields at that point or only what is to be displayed etc? (not looking at the code ATM -- do code analysis and try to sort by fields which are not to be displayed... add test for that)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes — the sort operates on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot please clarify if this would work given the question I gave above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it works for non-displayed fields. The sort (lines 235–248) runs on |
||
| if args.reverse: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this 'recent' should be removed here since apparently recency seems might be not corresponding.