Skip to content
Open
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.4.2", description="On-device package installer for network-capable boards")
metadata(version="0.5.0", description="On-device package installer for network-capable boards")

require("requests")

Expand Down
45 changes: 21 additions & 24 deletions micropython/mip/mip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@
_PACKAGE_INDEX = const("https://micropython.org/pi/v2")
_CHUNK_SIZE = const(128)

allowed_mip_url_prefixes = ("http://", "https://", "github:", "gitlab:")
# Since all URLs are accessed via HTTPS, the URL scheme has to be omitted here.
# The first two format parameters are assumed to be the organisation and the
# repository names, in this order.
_HOSTS = {
# https://codeberg.org/api/v1/repos/{org}/{repo}/raw/{path}?ref={branch}
"codeberg:": "codeberg.org/api/v1/repos/{}/{}/raw/{p}?ref={}",
# https://raw.githubusercontent.com/{org}/{repo}/{branch}/{path}
"github:": "raw.githubusercontent.com/{}/{}/{}/{p}",
# https://gitlab.com/{org}/{repo}/-/raw/{branch}/{path}
"gitlab:": "gitlab.com/{}/{}/-/raw/{}/{p}",
}

# ruff: noqa: RUF005 - tuple construction with list destructuring is not supported.
allowed_mip_url_prefixes = tuple(["http://", "https://"] + list(_HOSTS.keys()))


# This implements os.makedirs(os.dirname(path))
Expand Down Expand Up @@ -64,29 +77,13 @@ def _check_exists(path, short_hash):
def _rewrite_url(url, branch=None):
if not branch:
branch = "HEAD"
if url.startswith("github:"):
url = url[7:].split("/")
url = (
"https://raw.githubusercontent.com/"
+ url[0]
+ "/"
+ url[1]
+ "/"
+ branch
+ "/"
+ "/".join(url[2:])
)
elif url.startswith("gitlab:"):
url = url[7:].split("/")
url = (
"https://gitlab.com/"
+ url[0]
+ "/"
+ url[1]
+ "/-/raw/"
+ branch
+ "/"
+ "/".join(url[2:])
for provider, url_format in _HOSTS.items():
if not url.startswith(provider):
continue
components = url[len(provider) :].split("/")
# Add https:// prefix to final URL.
return allowed_mip_url_prefixes[1] + url_format.format(
components[0], components[1], branch, p="/".join(components[2:])
)
return url

Expand Down
Loading