Skip to content

Commit 2ec3daa

Browse files
earlephilhowerdevyte
authored andcommitted
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.
1 parent f68362e commit 2ec3daa

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package/package_esp8266com_index.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,4 @@
292292
"name": "esp8266"
293293
}
294294
]
295-
}
295+
}

tools/boards.txt.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import collections
3838
import getopt
3939
import re
40+
import json
4041

4142
# serial upload speed order in menu
4243
# default is 115 for every board unless specified with 'serial' in board
@@ -1416,9 +1417,11 @@ def package ():
14161417

14171418
newfilestr = re.sub(r'"boards":[^\]]*\],', substitution, filestr, re.MULTILINE)
14181419

1420+
# To get consistent indent/formatting read the JSON and write it out programattically
14191421
if packagegen:
14201422
with open(pkgfname, 'w') as package_file:
1421-
package_file.write(newfilestr)
1423+
filejson = json.loads(filestr, object_pairs_hook=collections.OrderedDict)
1424+
package_file.write(json.dumps(filejson, indent=3, separators=(',',': ')))
14221425
print("updated: %s" % pkgfname)
14231426
else:
14241427
sys.stdout.write(newfilestr)

0 commit comments

Comments
 (0)