-
-
Notifications
You must be signed in to change notification settings - Fork 591
[DRAFT] #708 - Make pretty formatter output prettier #712
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
Closed
sloanlance
wants to merge
23
commits into
python-jsonschema:master
from
sloanlance:708-prettier-pretty
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
96ee573
#708 - improve pretty output format
sloanlance d3c2c03
Merge branch 'master' of https://github.com/Julian/jsonschema into 70…
sloanlance 46a5828
#708 - limit JSON formatting
sloanlance 917f384
#708 - flexible exception formatter; test updates
sloanlance bff4f00
#708 - satisfy flake8 style CI checks - attempt 1
sloanlance e0719d5
#708 - satisfy Python2 unicode tests - attempt 1
sloanlance e4089a8
#708 - satisfy Python2 unicode tests - attempt 2
sloanlance b16582d
#708 - add "coding" line to resolve pypy2 problems
sloanlance 39c6a47
#708 - add "coding" to fix pypy2 test problems
sloanlance 62fd301
#708 - removing Unicode marker
sloanlance f584741
#708 - attempted fix for old Python interpreters
sloanlance 55998e6
#708 - varying length fix
sloanlance f618b7f
#708 - conditional message code for old Python
sloanlance 7b8c802
#708 - Resolve CI style issues
sloanlance ef9c2b8
Merge branch 'master' of https://github.com/Julian/jsonschema into 70…
sloanlance fb33196
#708 - code review response; Py2 support removal
sloanlance e64acd7
#708 - move _json_formatter from _PrettyFormatter
sloanlance 6ce8ae8
Merge upstream master into 708-prettier-pretty
sloanlance 14e1e09
Merge remote-tracking branch 'origin/master' into 708-prettier-pretty
Julian 86d8a79
Fix imports.
Julian 6b53a7b
Remove the Py2 coding declarations.
Julian dd62088
Run pre-commit in CI.
Julian 5185d44
Update jsonschema/tests/test_cli.py
sloanlance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/[email protected] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
Validation errors, and some surrounding helpers. | ||
""" | ||
from collections import defaultdict, deque | ||
Julian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from functools import partial | ||
from pprint import pformat | ||
import itertools | ||
import pprint | ||
import textwrap | ||
|
||
import attr | ||
|
@@ -60,14 +61,18 @@ def __repr__(self): | |
return "<%s: %r>" % (self.__class__.__name__, self.message) | ||
|
||
def __str__(self): | ||
return self._formatted_message() | ||
|
||
def _formatted_message(self, formatter=partial(pformat, width=72)): | ||
essential_for_verbose = ( | ||
self.validator, self.validator_value, self.instance, self.schema, | ||
) | ||
if any(m is _unset for m in essential_for_verbose): | ||
return self.message | ||
|
||
pschema = pprint.pformat(self.schema, width=72) | ||
pinstance = pprint.pformat(self.instance, width=72) | ||
pschema = formatter(self.schema) | ||
|
||
pinstance = pformat(self.instance, width=72) | ||
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. We're only using the formatter for the schema, not the instance here, so there's going to be inconsistency in the output. Can we add a test that covers the instance too and then fix this to make sure the formatter is used for both? |
||
return self.message + textwrap.dedent(""" | ||
|
||
Failed validating %r in %s%s: | ||
|
@@ -186,8 +191,8 @@ def __init__(self, type, instance, schema): | |
self.schema = schema | ||
|
||
def __str__(self): | ||
pschema = pprint.pformat(self.schema, width=72) | ||
pinstance = pprint.pformat(self.instance, width=72) | ||
pschema = pformat(self.schema, width=72) | ||
pinstance = pformat(self.instance, width=72) | ||
return textwrap.dedent(""" | ||
Unknown type %r for validator with schema: | ||
%s | ||
|
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
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.
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.
Minor style: jsonschema follows PEP8 / generally avoids using backslashes for continuation. Can you switch these to use parentheses instead?
Though, I think this will be a lot clearer if we split it into
_header_line
and_non_header_line
-- can you give that a shot? It should remove a bunch of the conditional behavior here.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 usually don't like backslashes, either. I got in the habit of using it because my coworkers do like them. I'll change this code.