forked from micropython/micropython-esp32-ulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenpkgjson.py
50 lines (35 loc) · 1.17 KB
/
genpkgjson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Tool for generating package.json for the MIP package manager
Run this tool from the repo root, like:
python tools/genpkgjson.py > package.json
Note:
This tool works with both python3 and micropyton.
"""
import os
import json
PACKAGE_JSON_VERSION=1
# Update the repo when working with a fork
GITHUB_REPO="micropython/micropython-esp32-ulp"
def get_files(path):
files = [f'{path}/{f}' for f in os.listdir(path)]
return files
def build_urls(repo_base, files):
return [[f, f'github:{repo_base}/{f}'] for f in files]
def print_package_json(urls):
"""
Custom-formatting JSON output for better readability
json.dumps in MicroPython cannot format the output and python3
puts each element of each urls' sub-arrays onto a new line.
Here we print each file and its source url onto the same line.
"""
print('{')
print(f' "v":{PACKAGE_JSON_VERSION},')
print(' "urls":[')
print(',\n'.join([f' {json.dumps(u)}' for u in sorted(urls)]))
print(' ]')
print('}')
if __name__ == '__main__':
library_root = 'esp32_ulp'
files = get_files(library_root)
urls = build_urls(GITHUB_REPO, files)
print_package_json(urls)