Skip to content

Commit a363ac6

Browse files
committed
micropython/mip: Add command-line functionality for the Unix port.
Moves mip.py to mip/__init__.py, so that the optional (added in this commit) mip/__main__.py can exist to support: `micropython -m mip install [--target,--index,--no-mpy] package@version` "install" works by forwarding the arguments directly to mip.install. Updates mip to v0.2.0 because of the change in directory structure. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 81c1408 commit a363ac6

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

Diff for: micropython/mip-cmdline/manifest.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
metadata(version="0.1.0", description="Optional support for running `micropython -m mip`")
2+
3+
require("argparse")
4+
require("mip")
5+
6+
package("mip")

Diff for: micropython/mip-cmdline/mip/__main__.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# MicroPython package installer command line
2+
# MIT license; Copyright (c) 2022 Jim Mussared
3+
4+
import argparse
5+
import sys
6+
7+
8+
def do_install():
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"-t",
12+
"--target",
13+
help="Directory to start discovery",
14+
)
15+
parser.add_argument(
16+
"-i",
17+
"--index",
18+
help="Pattern to match test files",
19+
)
20+
parser.add_argument(
21+
"--mpy",
22+
action="store_true",
23+
help="download as compiled .mpy files (default)",
24+
)
25+
parser.add_argument(
26+
"--no-mpy",
27+
action="store_true",
28+
help="download as .py source files",
29+
)
30+
parser.add_argument("package", nargs="+")
31+
args = parser.parse_args(args=sys.argv[2:])
32+
33+
from . import install
34+
35+
for package in args.package:
36+
version = None
37+
if "@" in package:
38+
package, version = package.split("@")
39+
install(package, args.index, args.target, version, not args.no_mpy)
40+
41+
42+
if len(sys.argv) >= 2:
43+
if sys.argv[1] == "install":
44+
do_install()
45+
else:
46+
print('mip: Unknown command "{}"'.format(sys.argv[1]))

Diff for: micropython/mip/manifest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
metadata(version="0.1.0", description="On-device package installer for network-capable boards")
1+
metadata(version="0.2.0", description="On-device package installer for network-capable boards")
22

33
require("urequests")
44

5-
module("mip.py")
5+
package("mip")

Diff for: micropython/mip/mip.py renamed to micropython/mip/mip/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _install_package(package, index, target, version, mpy):
153153
return _install_json(package, index, target, version, mpy)
154154

155155

156-
def install(package, index=_PACKAGE_INDEX, target=None, version=None, mpy=True):
156+
def install(package, index=None, target=None, version=None, mpy=True):
157157
if not target:
158158
for p in sys.path:
159159
if p.endswith("/lib"):
@@ -163,6 +163,9 @@ def install(package, index=_PACKAGE_INDEX, target=None, version=None, mpy=True):
163163
print("Unable to find lib dir in sys.path")
164164
return
165165

166+
if not index:
167+
index = _PACKAGE_INDEX
168+
166169
if _install_package(package, index.rstrip("/"), target, version, mpy):
167170
print("Done")
168171
else:

0 commit comments

Comments
 (0)