| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Note to rebase on #346 which should be merged first. |
Sorry, something went wrong.
There was a problem hiding this comment.
I would prefer a --compact option which use indent=None but also separators without spaces: http://bugs.python.org/issue29540
It's not the same than what you propose.
Sorry, something went wrong.
There was a problem hiding this comment.
@Haypo I agree the most compact representation would be useful.
One option would be add a third argument (--compact) to the mutually exclusive group. This would provide access to three options:
Alternatively, are you proposing to only support options 1 & 3?
I'm happy to implement this. Let's get a second opinion, so I don't go down the wrong track. Tagging @serhiy-storchaka, @berkerpeksag, @methane.
Sorry, something went wrong.
There was a problem hiding this comment.
Is --no-indent differen than --indent=0?
Would it be possible to use a default of 4 spaces when using --indent with no argument?
Sorry, something went wrong.
There was a problem hiding this comment.
Is --no-indent differen than --indent=0?
Yes, it is. --indent=0 adds new lines, --no-indent writes all in one line.
Would it be possible to use a default of 4 spaces when using --indent with no argument?
This is the default behavior.
Sorry, something went wrong.
There was a problem hiding this comment.
@Haypo the following illustrates the three options
import json
obj = [1, 2]
print('--indent=4')
print(json.dumps(obj, indent=4))
print('--no-indent')
print(json.dumps(obj, indent=None))
print('--compact')
print(json.dumps(obj, separators=(',', ':')))which produces the following output
--indent=4
[
1,
2
]
--no-indent
[1, 2]
--compact
[1,2]
Sorry, something went wrong.
There was a problem hiding this comment.
Spaces after comma and semicolon are not just for readability. They make JSON compatible with YAML 1.0.
@serhiy-storchaka great point. I think this is a strong argument for not replacing --no-indent with --compact. However, should we add --compact as a third option? I can see the utility for users who wan't the smallest file sizes.
Sorry, something went wrong.
|
Spaces after comma and semicolon are not just for readability. They make JSON compatible with YAML 1.0. |
Sorry, something went wrong.
|
Yes, it is. --indent=0 adds new lines, --no-indent writes all in one line.
"write all in one line": it sounds like the use case is to produce
smaller file, so it seems redundant and less efficient than --compact.
I expect that --compact removes all spaces and newlines to produce the
smallest file.
|
Sorry, something went wrong.
|
This is not the right place for the design discussion. Lets continue it on the bug tracker. |
Sorry, something went wrong.
@serhiy-storchaka and @Haypo I updated bpo-29636 with a summary of the design discussion thus far. I propose continuing this pull request with only --indent and --no-indent. If we end up reaching consensus to add --compact, that can be added in the future. I think it would fit in nicely alongside --indent and --no-indent. In other words, it's not pressing to decide on --compact right now. |
Sorry, something went wrong.
|
#346 has been merged and this PR rebased. @serhiy-storchaka, @berkerpeksag, @methane and @Haypo: open for review. No more outstanding changes on my end. |
Sorry, something went wrong.
Originall from python#2720 Set default option for infile and outfile as per python#2720 (review) Use --sort-keys help message based on the json.tool docs at https://docs.python.org/3.6/library/json.html#basic-usage: Remove commens as per https://bugs.python.org/msg298692. Code was descriptive without the comments.
From python#201 which is being split into two pull requests. See http://bugs.python.org/issue29636
|
Thanks @methane for ba16891 which merges in the changes from #5315 (dict order guaranteed as of Python 3.7). I'll get working on the NEWS entry. |
Sorry, something went wrong.
Use `blurb add` command to assist with adding the NEWS entry.
|
Ready from my end. As of b8fee34, --help prints the following message: usage: python -m json.tool [-h] [--sort-keys]
[--indent INDENT | --tab | --no-indent | --compact]
[infile] [outfile]
A simple command line interface for json module to validate and pretty-print
JSON objects.
positional arguments:
infile a JSON file to be validated or pretty-printed
outfile write the output of infile to outfile
optional arguments:
-h, --help show this help message and exit
--sort-keys sort the output of dictionaries by key
--indent INDENT separate items with newlines and use this number of spaces
for indentation
--tab separate items with newlines and use tabs for indentation
--no-indent separate items with spaces rather than newlines
--compact suppress all whitespace separation (most compact)
|
Sorry, something went wrong.
|
What if pass conflicting options? --indent=4 and --tab? --indent=4 and --compact? |
Sorry, something went wrong.
| 'to validate and pretty-print JSON objects.') | ||
| parser = argparse.ArgumentParser(prog=prog, description=description) | ||
| parser.add_argument('infile', nargs='?', type=argparse.FileType(), | ||
| default=sys.stdin, |
There was a problem hiding this comment.
What is the benefit of setting default to sys.stdin instead of keeping it None?
Sorry, something went wrong.
There was a problem hiding this comment.
This way a suggestion from another contributor at #2720 (comment):
it is easier to read when we process all options in one place, and then use the process options.
By adding default=sys.stdin, we remove the following line later on:
infile = options.infile or sys.stdin
Sorry, something went wrong.
| parser.add_argument('--sort-keys', action='store_true', default=False, | ||
| help='sort the output of dictionaries alphabetically by key') | ||
| parser.add_argument('--sort-keys', action='store_true', | ||
| help='sort the output of dictionaries by key') |
There was a problem hiding this comment.
Why removed "alphabetically"?
Sorry, something went wrong.
There was a problem hiding this comment.
I believe my intention was to make the help message more closely mirror the json.dump documentation:
Lines 157 to 158 in cfa797c
Happy to re-add "alphabetically" if that was helpful.
Sorry, something went wrong.
The intention is to disallow users from passing multiple whitespace options with argparse's add_mutually_exclusive_group. The implementation will, in most cases, detect and raise an error if multiple whitespace arguments are provided. However, there is an argparse issue (bpo-18943) where mutual exclusivity is not enforced when --indent=4 is specified (since 4 is default). For example, --compact --tab or --indent=3 --compact or --indent=4 --compact --tab will all throw errors of the form: python -m json.tool: error: argument --tab: not allowed with argument --compact --indent=4 --compact (or --indent=4 --tab) does not throw an error. In the case that --indent=4 is specified with --compact, --tab, or no-indent, the later will take precedent. |
Sorry, something went wrong.
|
I hope this feature can be merged ASAP, it's really helpful as a cross-platform command line utility. |
Sorry, something went wrong.
@mya12321 the most effective way for you to support this PR would be to chime in on the issue. At present, I think there is some hesitancy to add additional arguments, so if you explain your use case that may be helpful. But as far as I understand, this discussion should go on the bug tracker and not on GitHub. |
Sorry, something went wrong.
|
Would you resolve the conflict? |
Sorry, something went wrong.
|
Well done @dhimmel and thanks for your tenacity! |
Sorry, something went wrong.
Bumps [gidgethub](https://github.com/brettcannon/gidgethub) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/brettcannon/gidgethub/releases) - [Changelog](https://github.com/brettcannon/gidgethub/blob/master/docs/changelog.rst) - [Commits](gidgethub/gidgethub@v4.1.0...v4.1.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
From #201 which is being split into two pull requests.
Tagging @serhiy-storchaka, @berkerpeksag, @methane who helped review #201.
Closes http://bugs.python.org/issue29636.
https://bugs.python.org/issue29636