Skip to content

Commit b379e4f

Browse files
glenn20dpgeorge
authored andcommitted
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 micropython/micropython#12477. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
1 parent 7a32df3 commit b379e4f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

micropython/mip/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.3.0", description="On-device package installer for network-capable boards")
1+
metadata(version="0.4.0", description="On-device package installer for network-capable boards")
22

33
require("requests")
44

micropython/mip/mip/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
_PACKAGE_INDEX = const("https://micropython.org/pi/v2")
1010
_CHUNK_SIZE = 128
1111

12+
allowed_mip_url_prefixes = ("http://", "https://", "github:", "gitlab:")
13+
1214

1315
# This implements os.makedirs(os.dirname(path))
1416
def _ensure_path_exists(path):
@@ -124,8 +126,12 @@ def _install_json(package_json_url, index, target, version, mpy):
124126
if not _download_file(file_url, fs_target_path):
125127
print("File not found: {} {}".format(target_path, short_hash))
126128
return False
129+
base_url = package_json_url.rpartition("/")[0]
127130
for target_path, url in package_json.get("urls", ()):
128131
fs_target_path = target + "/" + target_path
132+
is_full_url = any(url.startswith(p) for p in allowed_mip_url_prefixes)
133+
if base_url and not is_full_url:
134+
url = f"{base_url}/{url}" # Relative URLs
129135
if not _download_file(_rewrite_url(url, version), fs_target_path):
130136
print("File not found: {} {}".format(target_path, url))
131137
return False
@@ -136,12 +142,7 @@ def _install_json(package_json_url, index, target, version, mpy):
136142

137143

138144
def _install_package(package, index, target, version, mpy):
139-
if (
140-
package.startswith("http://")
141-
or package.startswith("https://")
142-
or package.startswith("github:")
143-
or package.startswith("gitlab:")
144-
):
145+
if any(package.startswith(p) for p in allowed_mip_url_prefixes):
145146
if package.endswith(".py") or package.endswith(".mpy"):
146147
print("Downloading {} to {}".format(package, target))
147148
return _download_file(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy