From 2ec3daa225fde7d31208652116a0c461bfbb29b5 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 3 Dec 2018 19:26:18 -0800 Subject: [PATCH] Use Python JSON to format packages.json file (#5429) The packages JSON file which includes the boards, tools, etc. and needs to have consistent formatting to be reproducible. The current boards.txt.py uses a REGEX to string-replace a bit of it, but that bit has a different indent than the rest of the file. Use Python's JSON writer to format the whole file repeatably. --- package/package_esp8266com_index.template.json | 2 +- tools/boards.txt.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json index fcd05c287..0a85b00e1 100644 --- a/package/package_esp8266com_index.template.json +++ b/package/package_esp8266com_index.template.json @@ -292,4 +292,4 @@ "name": "esp8266" } ] -} +} \ No newline at end of file diff --git a/tools/boards.txt.py b/tools/boards.txt.py index 572fd91e3..c6e10ff56 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -37,6 +37,7 @@ import sys import collections import getopt import re +import json # serial upload speed order in menu # default is 115 for every board unless specified with 'serial' in board @@ -1416,9 +1417,11 @@ def package (): newfilestr = re.sub(r'"boards":[^\]]*\],', substitution, filestr, re.MULTILINE) + # To get consistent indent/formatting read the JSON and write it out programattically if packagegen: with open(pkgfname, 'w') as package_file: - package_file.write(newfilestr) + filejson = json.loads(filestr, object_pairs_hook=collections.OrderedDict) + package_file.write(json.dumps(filejson, indent=3, separators=(',',': '))) print("updated: %s" % pkgfname) else: sys.stdout.write(newfilestr)