Skip to content
Permalink
Browse files

write_json: Remove all indentation by default if AUGUR_MINIFY_JSON is…

… set

This is comparable to export's --minify-json flag, but applies to all
commands and is easily toggled pipeline-wide for dev vs. production.

For parity with John's choice with --minify-json, spaces are left
between and within key/value pairs.  A future enhancement might strip
those too.

It is possible we should also add --minify-json flags to all commands
for consistency with export, but it seems like export is the most useful
command to have the flag.  The files export produces are generally
expected to be longer-lived than the files produced by other commands at
intermediate steps.

Another future enhancement might be to automatically gzip JSON output
(and gunzip JSON input, which would require some more refactoring).
  • Loading branch information...
tsibley committed Apr 23, 2019
1 parent d617e00 commit 1c64ded8059d19e17045ab5f9e5b4a5b22999aec
Showing with 4 additions and 2 deletions.
  1. +4 −2 augur/utils.py
@@ -133,12 +133,14 @@ def read_node_data(fnames, tree=None):
return node_data


def write_json(data, file_name, indent=1):
def write_json(data, file_name, indent=(None if os.environ.get("AUGUR_MINIFY_JSON") else 1)):
"""
Write *data* as JSON to the given *file_name*, creating parent directories
if necessary.
By default, an *indent* of 1 is passed to :func:`json.dumps`.
By default, an *indent* of 1 is passed to :func:`json.dumps`. If the
environment variable ``AUGUR_MINIFY_JSON`` is defined with a truthy value,
the default *indent* is instead ``None``.
"""
#in case parent folder does not exist yet
parent_directory = os.path.dirname(file_name)

0 comments on commit 1c64ded

Please sign in to comment.
You can’t perform that action at this time.