File: mpy_cross_all.py

package info (click to toggle)
giac 1.9.0.93%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 117,732 kB
  • sloc: cpp: 404,272; ansic: 205,462; python: 30,548; javascript: 28,788; makefile: 17,997; yacc: 2,690; lex: 2,464; sh: 705; perl: 314; lisp: 216; asm: 62; java: 41; xml: 36; sed: 16; csh: 7; pascal: 6
file content (38 lines) | stat: -rwxr-xr-x 1,293 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
import argparse
import os
import os.path

argparser = argparse.ArgumentParser(description="Compile all .py files to .mpy recursively")
argparser.add_argument("-o", "--out", help="output directory (default: input dir)")
argparser.add_argument("--target", help="select MicroPython target config")
argparser.add_argument("-mcache-lookup-bc", action="store_true", help="cache map lookups in the bytecode")
argparser.add_argument("dir", help="input directory")
args = argparser.parse_args()

TARGET_OPTS = {
    "unix": "-mcache-lookup-bc",
    "baremetal": "",
}

args.dir = args.dir.rstrip("/")

if not args.out:
    args.out = args.dir

path_prefix_len = len(args.dir) + 1

for path, subdirs, files in os.walk(args.dir):
    for f in files:
        if f.endswith(".py"):
            fpath = path + "/" + f
            #print(fpath)
            out_fpath = args.out + "/" + fpath[path_prefix_len:-3] + ".mpy"
            out_dir = os.path.dirname(out_fpath)
            if not os.path.isdir(out_dir):
                os.makedirs(out_dir)
            cmd = "mpy-cross -v -v %s -s %s %s -o %s" % (TARGET_OPTS.get(args.target, ""),
                fpath[path_prefix_len:], fpath, out_fpath)
            #print(cmd)
            res = os.system(cmd)
            assert res == 0