From 96036f07a3c86cc34d00616998c41dcaf3f9945a Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Tue, 20 Feb 2018 20:10:38 -0330 Subject: [PATCH] api_code_example: Use json instead of ujson; specify separators. The Markdown extension that lives inside zerver/lib/bugdown/api_code_example.py previously used ujson. ujson's `dumps` function doesn't accept a `separators` argument, which means we have no control over how the JSON is pretty-printed. This resulted in JSON fixtures with no spaces after the colon, which looks unnecessarily convoluted. So now, we use the built-in `json` module to get around this. For further reading, this issue opened on ujson's repo explains why they are reluctant to support such formatting due to performance considerations. --- zerver/lib/bugdown/api_code_examples.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zerver/lib/bugdown/api_code_examples.py b/zerver/lib/bugdown/api_code_examples.py index 58aae23eaf..6d56787c34 100644 --- a/zerver/lib/bugdown/api_code_examples.py +++ b/zerver/lib/bugdown/api_code_examples.py @@ -1,7 +1,7 @@ import re import os import sys -import ujson +import json import inspect from markdown.extensions import Extension @@ -143,7 +143,8 @@ class APICodeExamplesPreprocessor(Preprocessor): else: fixture_dict = zerver.lib.api_test_helpers.FIXTURES[function] - fixture_json = ujson.dumps(fixture_dict, indent=4, sort_keys=True) + fixture_json = json.dumps(fixture_dict, indent=4, sort_keys=True, + separators=(',', ': ')) fixture.append('```') fixture.extend(fixture_json.splitlines())