Skip to content

Commit

Permalink
Add package.json for MIP package manager
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wnienhaus committed Sep 4, 2023
1 parent 25bf34e commit b284091
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"v":1,
"urls":[
["esp32_ulp/__init__.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/__init__.py"],
["esp32_ulp/__main__.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/__main__.py"],
["esp32_ulp/assemble.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/assemble.py"],
["esp32_ulp/definesdb.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/definesdb.py"],
["esp32_ulp/link.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/link.py"],
["esp32_ulp/nocomment.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/nocomment.py"],
["esp32_ulp/opcodes.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/opcodes.py"],
["esp32_ulp/opcodes_s2.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/opcodes_s2.py"],
["esp32_ulp/parse_to_db.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/parse_to_db.py"],
["esp32_ulp/preprocess.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/preprocess.py"],
["esp32_ulp/soc.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc.py"],
["esp32_ulp/soc_s2.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc_s2.py"],
["esp32_ulp/soc_s3.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/soc_s3.py"],
["esp32_ulp/util.py", "github:micropython/micropython-esp32-ulp/esp32_ulp/util.py"]
]
}
50 changes: 50 additions & 0 deletions tools/genpkgjson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)

0 comments on commit b284091

Please sign in to comment.