Skip to content

micropython/mip: Allow relative URLs in package.json files. #975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion micropython/mip/manifest.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
13 changes: 7 additions & 6 deletions micropython/mip/mip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
_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):
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Loading