Skip to content

Commit b284091

Browse files
committed
Add package.json for MIP package manager
Also add a tool for generating package.json, so it doesn't have to be handcrafted when files are added/removed. To generate/update package.json, run from repo root as follows: python3 tools/genpkgjson.py > package.json (instead of python3, micropython can also be used) Note: at present MIP does not support any way to specify repo-relative urls, so at present the generated json will point to gituhub:micropython/micropython-esp32-ulp, which would need to be adapted in any forks of this repo.
1 parent 25bf34e commit b284091

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"v":1,
3+
"urls":[
4+
["esp32_ulp/__init__.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/__init__.py"],
5+
["esp32_ulp/__main__.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/__main__.py"],
6+
["esp32_ulp/assemble.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/assemble.py"],
7+
["esp32_ulp/definesdb.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/definesdb.py"],
8+
["esp32_ulp/link.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/link.py"],
9+
["esp32_ulp/nocomment.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/nocomment.py"],
10+
["esp32_ulp/opcodes.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/opcodes.py"],
11+
["esp32_ulp/opcodes_s2.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/opcodes_s2.py"],
12+
["esp32_ulp/parse_to_db.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/parse_to_db.py"],
13+
["esp32_ulp/preprocess.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/preprocess.py"],
14+
["esp32_ulp/soc.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc.py"],
15+
["esp32_ulp/soc_s2.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc_s2.py"],
16+
["esp32_ulp/soc_s3.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc_s3.py"],
17+
["esp32_ulp/util.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/util.py"]
18+
]
19+
}

tools/genpkgjson.py

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

0 commit comments

Comments
 (0)