mip: Allow relative URLs in package.json.

This allows to specify relative URLs in package.json, which are resolved
relative to the package.json URL. This mirrors the functionality added to
mpremote in https://github.com/micropython/micropython/pull/12477.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
pull/975/head
Glenn Moloney 2025-02-18 11:05:50 +11:00 zatwierdzone przez Damien George
rodzic 7a32df3d13
commit b379e4fb4c
2 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
metadata(version="0.3.0", description="On-device package installer for network-capable boards")
metadata(version="0.4.0", description="On-device package installer for network-capable boards")
require("requests")

Wyświetl plik

@ -9,6 +9,8 @@ import sys
_PACKAGE_INDEX = const("https://micropython.org/pi/v2")
_CHUNK_SIZE = 128
allowed_mip_url_prefixes = ("http://", "https://", "github:", "gitlab:")
# This implements os.makedirs(os.dirname(path))
def _ensure_path_exists(path):
@ -124,8 +126,12 @@ def _install_json(package_json_url, index, target, version, mpy):
if not _download_file(file_url, fs_target_path):
print("File not found: {} {}".format(target_path, short_hash))
return False
base_url = package_json_url.rpartition("/")[0]
for target_path, url in package_json.get("urls", ()):
fs_target_path = target + "/" + target_path
is_full_url = any(url.startswith(p) for p in allowed_mip_url_prefixes)
if base_url and not is_full_url:
url = f"{base_url}/{url}" # Relative URLs
if not _download_file(_rewrite_url(url, version), fs_target_path):
print("File not found: {} {}".format(target_path, url))
return False
@ -136,12 +142,7 @@ def _install_json(package_json_url, index, target, version, mpy):
def _install_package(package, index, target, version, mpy):
if (
package.startswith("http://")
or package.startswith("https://")
or package.startswith("github:")
or package.startswith("gitlab:")
):
if any(package.startswith(p) for p in allowed_mip_url_prefixes):
if package.endswith(".py") or package.endswith(".mpy"):
print("Downloading {} to {}".format(package, target))
return _download_file(