Skip to content

Commit e9f8128

Browse files
committed
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.
1 parent 65a1411 commit e9f8128

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

micropython/mip/mip/__init__.py

Lines changed: 6 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,11 @@ 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+
if base_url and not url.startswith(allowed_mip_url_prefixes):
133+
url = f"{base_url}/{url}" # Relative URLs
129134
if not _download_file(_rewrite_url(url, version), fs_target_path):
130135
print("File not found: {} {}".format(target_path, url))
131136
return False
@@ -136,12 +141,7 @@ def _install_json(package_json_url, index, target, version, mpy):
136141

137142

138143
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-
):
144+
if package.startswith(allowed_mip_url_prefixes):
145145
if package.endswith(".py") or package.endswith(".mpy"):
146146
print("Downloading {} to {}".format(package, target))
147147
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