feat: add JSON output format#6
Open
entrity wants to merge 1 commit into
Open
Conversation
🎯 Motivation Consumers of python-abc output currently have to parse the human-readable text format. That makes automated use brittle and couples callers to the exact CLI spacing and display string. 🦋 What's Changed Add a `--format` option with `text` and `json` modes, keeping the existing text format as the default. Move text and JSON rendering into `python_abc/output.py`. Introduce `AnalysisResult` to impose a schema on the result tuples that had been passed around heretofore. This keeps sorting, text rendering, and JSON serialization working from named fields instead of tuple positions. Emit JSON with per-file status, vector components, magnitude, errors, and a summary. The JSON payload intentionally omits a `display` field. Document the JSON output mode in the README and add renderer tests. ⛔️ Other Details `--format json` is rejected when `--debug` or `--verbose` is also provided because those modes print diagnostic output to stdout. 🧪 Testing `.venv/bin/pytest tests/test_output.py` `.venv/bin/python -m python_abc python_abc/vector.py --format json` `.venv/bin/ruff check python_abc/__main__.py python_abc/output.py tests/test_output.py` Full `.venv/bin/pytest` still has existing failures around `with ... as ...` assignment counting. 🔗 References None.
Author
|
@eoinnoble , could I request a code review? |
1 similar comment
Author
|
@eoinnoble , could I request a code review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Motivation
Consumers of python-abc output currently have to parse the human-readable text format. That makes automated use brittle and couples callers to the exact CLI spacing and display string.
🦋 What's Changed
Add a
--formatoption withtextandjsonmodes, keeping the existing text format as the default.Move text and JSON rendering into
python_abc/output.py.Introduce
AnalysisResultto impose a schema on the result tuples that had been passed around heretofore. This keeps sorting, text rendering, and JSON serialization working from named fields instead of tuple positions.Emit JSON with per-file status, vector components, magnitude, errors, and a summary. The JSON payload intentionally omits a
displayfield.Document the JSON output mode in the README and add renderer tests.
⛔️ Other Details
--format jsonis rejected when--debugor--verboseis also provided because those modes print diagnostic output to stdout.🧪 Testing
.venv/bin/pytest tests/test_output.py.venv/bin/python -m python_abc python_abc/vector.py --format json.venv/bin/ruff check python_abc/__main__.py python_abc/output.py tests/test_output.py(Full
.venv/bin/pyteststill has existing failures aroundwith ... as ...assignment counting.)🔗 References
Closes #5