File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import argparse
3+ import os
4+ import os .path
5+
6+ argparser = argparse .ArgumentParser (description = "Compile all .py files to .mpy recursively" )
7+ argparser .add_argument ("-o" , "--out" , help = "output directory (default: input dir)" )
8+ argparser .add_argument ("--target" , help = "select MicroPython target config" )
9+ argparser .add_argument ("-mcache-lookup-bc" , action = "store_true" , help = "cache map lookups in the bytecode" )
10+ argparser .add_argument ("dir" , help = "input directory" )
11+ args = argparser .parse_args ()
12+
13+ TARGET_OPTS = {
14+ "unix" : "-mcache-lookup-bc" ,
15+ "baremetal" : "" ,
16+ }
17+
18+ args .dir = args .dir .rstrip ("/" )
19+
20+ if not args .out :
21+ args .out = args .dir
22+
23+ path_prefix_len = len (args .dir ) + 1
24+
25+ for path , subdirs , files in os .walk (args .dir ):
26+ for f in files :
27+ if f .endswith (".py" ):
28+ fpath = path + "/" + f
29+ #print(fpath)
30+ out_fpath = args .out + "/" + fpath [path_prefix_len :- 3 ] + ".mpy"
31+ out_dir = os .path .dirname (out_fpath )
32+ if not os .path .isdir (out_dir ):
33+ os .makedirs (out_dir )
34+ cmd = "mpy-cross -v -v %s -s %s %s -o %s" % (TARGET_OPTS .get (args .target , "" ),
35+ fpath [path_prefix_len :], fpath , out_fpath )
36+ #print(cmd)
37+ res = os .system (cmd )
38+ assert res == 0
You can’t perform that action at this time.
0 commit comments