feat(ui): add rich as an opt-in output format - #1152
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@googlebot I signed it! |
|
/gcbrun |
|
@latiefdole Looks like you need to update the formatting of three files. Just to be clear, we have not yet decided if we want this feature, but are considering it. |
stevemessick
left a comment
There was a problem hiding this comment.
After taking a close look at this PR we have found a number of problems:
- Introduces behavioral regressions.
- Causes failure of automated checks.
- Fails unit tests.
- Adds dead code.
- Doesn't follow repro coding practices.
- Provides no escape mechanism to obtain legacy formatting (contrary to claims).
Addresses the review feedback on Kaggle#1152. The previous approach intercepted print_table and rendered every table through rich, which changed the default output for all list commands. Because rich was a hard dependency, the RICH_AVAILABLE guard was always true and the documented "falls back when piped" behavior never triggered: there was no isatty() check, so piped output still got box borders, long values were truncated with an ellipsis, empty results started printing a "No data found" panel, and values containing square brackets were parsed as console markup. Instead, add rich as a new OutputFormat alongside csv/table/json: - `--format rich` (and `KAGGLE_OUTPUT_FORMAT=rich` for a persistent default) opt into the bordered output; the default table output is unchanged. - rich moves to an optional extra; `--format rich` without it installed prints an install hint to stderr and falls back to print_table. - Values render via Text() so API content is never treated as markup, and columns use overflow="fold" so no data is dropped on narrow terminals. - Column alignment and the empty-items behavior match print_table. - Drop the unused print_info/print_error/print_success helpers. Replace the mock-only tests with tests that assert on rendered output, and document the format in docs/output_format.md next to the existing formats.
465a6d2 to
b704138
Compare
|
Thanks for the detailed review - all six points were correct, and I've reworked the PR rather than patching around them. I want to specifically own the worst one: the claim that output fell back to plain text when piped was false. There was no Design change: instead of intercepting Point by point:
The branch is rebased onto current On whether you want the feature at all: understood, and no pressure either way. The point of the opt-in design is that it costs nothing in default behaviour if you're undecided - but if you'd rather not carry it, I'm happy to close this. Just say which. Separately, this PR previously also carried some unrelated CLI usability fixes (error message hints, a |
|
/gcbrun |
stevemessick
left a comment
There was a problem hiding this comment.
Almost there! I think the lint dependencies need to be updated to allow the checks to pass:
Step #3 - "lint": src/kaggle/ui.py:20: error: Cannot find implementation or library stub for module named "rich" [import-not-found]
Otherwise, this looks really good and I look forward to getting it merged!
| kaggle competitions list --format csv | ||
| kaggle competitions list --format table | ||
| kaggle competitions list --format json | ||
| kaggle competitions list --format rich |
|
/gcbrun |
Description
Adds
richas a fourth value of the existingOutputFormatenum, alongsidecsv,tableandjson. It renders list output as a bordered, colorized table.This is opt-in only. The default
tableoutput is byte-for-byte unchanged, so no existing command, script or piped invocation changes behaviour unless the format is explicitly requested.Usage
Or set a persistent default for an interactive shell:
export KAGGLE_OUTPUT_FORMAT=richKAGGLE_OUTPUT_FORMATonly applies when neither--csvnor--formatis passed; an explicit flag always wins, and unrecognized values fall back totable. Projections work as with the other formats, e.g.--format "rich(ref,reward)".Dependency
richis an optional extra, not a runtime dependency:If
--format richis requested without the package installed, the CLI prints an install hint to stderr and falls back toprint_tablerather than failing.Behaviour notes
rich.text.Text, so API content containing square brackets is never interpreted as console markup.overflow="fold", so long values wrap instead of being truncated.print_table(an empty list prints nothing).Docs and tests
docs/output_format.mdnext to the existing formats.Testing
1268 passed, 0 failedblack --check .cleanmypyclean on the changed filesNote
This PR previously also contained unrelated CLI usability fixes. Those have been split out into #1171 so this one stays scoped to the output format.