Skip to content

feat: add JSON output format#6

Open
entrity wants to merge 1 commit into
eoinnoble:mainfrom
entrity:add-json-output-format
Open

feat: add JSON output format#6
entrity wants to merge 1 commit into
eoinnoble:mainfrom
entrity:add-json-output-format

Conversation

@entrity

@entrity entrity commented May 26, 2026

Copy link
Copy Markdown

🎯 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

Closes #5

🎯 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.
@entrity

entrity commented Jun 3, 2026

Copy link
Copy Markdown
Author

@eoinnoble , could I request a code review?

1 similar comment
@entrity

entrity commented Jun 16, 2026

Copy link
Copy Markdown
Author

@eoinnoble , could I request a code review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON output

1 participant