kopia lustrzana https://github.com/micropython/micropython-lib
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 <jim.mussared@gmail.com>pull/571/head
rodzic
81c1408a07
commit
a363ac6b21
|
@ -0,0 +1,6 @@
|
|||
metadata(version="0.1.0", description="Optional support for running `micropython -m mip`")
|
||||
|
||||
require("argparse")
|
||||
require("mip")
|
||||
|
||||
package("mip")
|
|
@ -0,0 +1,46 @@
|
|||
# MicroPython package installer command line
|
||||
# MIT license; Copyright (c) 2022 Jim Mussared
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
def do_install():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--target",
|
||||
help="Directory to start discovery",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--index",
|
||||
help="Pattern to match test files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--mpy",
|
||||
action="store_true",
|
||||
help="download as compiled .mpy files (default)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-mpy",
|
||||
action="store_true",
|
||||
help="download as .py source files",
|
||||
)
|
||||
parser.add_argument("package", nargs="+")
|
||||
args = parser.parse_args(args=sys.argv[2:])
|
||||
|
||||
from . import install
|
||||
|
||||
for package in args.package:
|
||||
version = None
|
||||
if "@" in package:
|
||||
package, version = package.split("@")
|
||||
install(package, args.index, args.target, version, not args.no_mpy)
|
||||
|
||||
|
||||
if len(sys.argv) >= 2:
|
||||
if sys.argv[1] == "install":
|
||||
do_install()
|
||||
else:
|
||||
print('mip: Unknown command "{}"'.format(sys.argv[1]))
|
|
@ -1,5 +1,5 @@
|
|||
metadata(version="0.1.0", description="On-device package installer for network-capable boards")
|
||||
metadata(version="0.2.0", description="On-device package installer for network-capable boards")
|
||||
|
||||
require("urequests")
|
||||
|
||||
module("mip.py")
|
||||
package("mip")
|
||||
|
|
|
@ -153,7 +153,7 @@ def _install_package(package, index, target, version, mpy):
|
|||
return _install_json(package, index, target, version, mpy)
|
||||
|
||||
|
||||
def install(package, index=_PACKAGE_INDEX, target=None, version=None, mpy=True):
|
||||
def install(package, index=None, target=None, version=None, mpy=True):
|
||||
if not target:
|
||||
for p in sys.path:
|
||||
if p.endswith("/lib"):
|
||||
|
@ -163,6 +163,9 @@ def install(package, index=_PACKAGE_INDEX, target=None, version=None, mpy=True):
|
|||
print("Unable to find lib dir in sys.path")
|
||||
return
|
||||
|
||||
if not index:
|
||||
index = _PACKAGE_INDEX
|
||||
|
||||
if _install_package(package, index.rstrip("/"), target, version, mpy):
|
||||
print("Done")
|
||||
else:
|
Ładowanie…
Reference in New Issue