tools/mpremote: Add an alias for codeberg repos.
Check code formatting / code-formatting (push) Has been cancelled
Build docs / build (push) Has been cancelled
Check examples / embedding (push) Has been cancelled
.mpy file format and tools / test (push) Has been cancelled
Build ports metadata / build (push) Has been cancelled
alif port / build_alif (alif_ae3_build) (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / build_idf (esp32_build_c2_c5_c6, v5.5.1) (push) Has been cancelled
esp32 port / build_idf (esp32_build_cmod_spiram_s2, v5.3) (push) Has been cancelled
esp32 port / build_idf (esp32_build_cmod_spiram_s2, v5.5.1) (push) Has been cancelled
esp32 port / build_idf (esp32_build_p4, v5.5.1) (push) Has been cancelled
esp32 port / build_idf (esp32_build_s3_c3, v5.3) (push) Has been cancelled
esp32 port / build_idf (esp32_build_s3_c3, v5.5.1) (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
mimxrt port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu port / build_and_test_arm (bigendian) (push) Has been cancelled
qemu port / build_and_test_arm (sabrelite) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_hardfp) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_softfp) (push) Has been cancelled
qemu port / build_and_test_rv32 (push) Has been cancelled
qemu port / build_and_test_rv64 (push) Has been cancelled
renesas-ra port / build_renesas_ra_board (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_stm32 (stm32_misc_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_nucleo_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_pyb_build) (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / standard_v2 (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / longlong (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / gil_enabled (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / repr_b (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
unix port / sanitize_address (push) Has been cancelled
unix port / sanitize_undefined (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, x64, v143, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, v143, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, v142, dev, 2019, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, v142, standard, 2019, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, v143, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, v143, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, v142, dev, 2019, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, v142, standard, 2019, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, v143, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, v143, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
JavaScript code lint and formatting with Biome / eslint (push) Has been cancelled
Check spelling with codespell / codespell (push) Has been cancelled
Package mpremote / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled

This commit introduces an alias to access codeberg repos from within
mpremote's package manager.

Right now packages hosted on codeberg could only be referenced by their
full URL, unlike other packages hosted on either GitHub or GitLab.  To
make access those packages easier, now they can be referenced as
"codeberg:org/repo@branch".

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
Alessandro Gatti
2026-03-23 12:39:17 +01:00
parent 670d775365
commit a595bbba67
4 changed files with 35 additions and 34 deletions
+9 -2
View File
@@ -38,13 +38,15 @@ install third-party libraries. The simplest way is to download a file directly::
When installing a file directly, the ``target`` argument is still supported to set
the destination path, but ``mpy`` and ``version`` are ignored.
The URL can also start with ``github:`` or ``gitlab:`` as a simple way of pointing to content
hosted on GitHub or GitLab::
The URL can also start with ``github:``, ``gitlab:``, or ``codeberg:`` as a simple
way of pointing to content hosted on GitHub, GitLab, or Codeberg::
>>> mip.install("github:org/repo/path/foo.py") # Uses default branch
>>> mip.install("github:org/repo/path/foo.py", version="branch-or-tag") # Optionally specify the branch or tag
>>> mip.install("gitlab:org/repo/path/foo.py") # Uses default branch
>>> mip.install("gitlab:org/repo/path/foo.py", version="branch-or-tag") # Optionally specify the branch or tag
>>> mip.install("codeberg:org/repo/path/foo.py") # Uses default branch
>>> mip.install("codeberg:org/repo/path/foo.py", version="branch-or-tag") # Optionally specify the branch or tag
More sophisticated packages (i.e. with more than one file, or with dependencies)
can be downloaded by specifying the path to their ``package.json``.
@@ -52,6 +54,7 @@ can be downloaded by specifying the path to their ``package.json``.
>>> mip.install("http://example.com/x/package.json")
>>> mip.install("github:org/user/path/package.json")
>>> mip.install("gitlab:org/user/path/package.json")
>>> mip.install("codeberg:org/user/path/package.json")
If no json file is specified, then "package.json" is implicitly added::
@@ -60,6 +63,8 @@ If no json file is specified, then "package.json" is implicitly added::
>>> mip.install("github:org/repo", version="branch-or-tag")
>>> mip.install("gitlab:org/repo") # Uses default branch of that repo
>>> mip.install("gitlab:org/repo", version="branch-or-tag")
>>> mip.install("codeberg:org/repo") # Uses default branch of that repo
>>> mip.install("codeberg:org/repo", version="branch-or-tag")
Using ``mip`` on the Unix port
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -89,6 +94,8 @@ can be used from a host PC to install packages to a locally connected device
$ mpremote mip install github:org/repo@branch-or-tag
$ mpremote mip install gitlab:org/repo
$ mpremote mip install gitlab:org/repo@branch-or-tag
$ mpremote mip install codeberg:org/repo
$ mpremote mip install codeberg:org/repo@branch-or-tag
The ``--target=path``, ``--no-mpy``, and ``--index`` arguments can be set::
+1
View File
@@ -82,3 +82,4 @@ Examples:
mpremote mip install aioble
mpremote mip install github:org/repo@branch
mpremote mip install gitlab:org/repo@branch
mpremote mip install codeberg:org/repo@branch
+1 -1
View File
@@ -246,7 +246,7 @@ def argparse_mip():
cmd_parser.add_argument(
"packages",
nargs="+",
help="list package specifications, e.g. name, name@version, github:org/repo, github:org/repo@branch, gitlab:org/repo, gitlab:org/repo@branch",
help="list package specifications, e.g. name, name@version, github:org/repo, github:org/repo@branch, gitlab:org/repo, gitlab:org/repo@branch, codeberg:org/repo, codeberg:org/repo@branch",
)
return cmd_parser
+24 -31
View File
@@ -5,7 +5,6 @@
import urllib.error
import urllib.request
import json
import tempfile
import os
import os.path
@@ -14,7 +13,19 @@ from .commands import CommandError, show_progress_bar
_PACKAGE_INDEX = "https://micropython.org/pi/v2"
allowed_mip_url_prefixes = ("http://", "https://", "github:", "gitlab:")
# Since all URLs are accessed via HTTPS, the URL scheme is added by _rewrite_url.
# The first three format parameters are assumed to be the organisation, the
# repository names, and the branch/tag name, 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}",
}
_ALLOWED_MIP_URL_PREFIXES = ("http://", "https://", "codeberg:", "github:", "gitlab:")
# This implements os.makedirs(os.dirname(path))
@@ -44,37 +55,19 @@ def _check_exists(transport, 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 the final URL.
return _ALLOWED_MIP_URL_PREFIXES[1] + url_format.format(
components[0], components[1], branch or "HEAD", p="/".join(components[2:])
)
return url
def _download_file(transport, url, dest):
if url.startswith(allowed_mip_url_prefixes):
if url.startswith(_ALLOWED_MIP_URL_PREFIXES):
try:
with urllib.request.urlopen(url) as src:
data = src.read()
@@ -101,7 +94,7 @@ def _download_file(transport, url, dest):
def _install_json(transport, package_json_url, index, target, version, mpy):
base_url = ""
if package_json_url.startswith(allowed_mip_url_prefixes):
if package_json_url.startswith(_ALLOWED_MIP_URL_PREFIXES):
try:
with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response:
package_json = json.load(response)
@@ -131,7 +124,7 @@ def _install_json(transport, package_json_url, index, target, version, mpy):
_download_file(transport, file_url, fs_target_path)
for target_path, url in package_json.get("urls", ()):
fs_target_path = target + "/" + target_path
if base_url and not url.startswith(allowed_mip_url_prefixes):
if base_url and not url.startswith(_ALLOWED_MIP_URL_PREFIXES):
url = f"{base_url}/{url}" # Relative URLs
_download_file(transport, _rewrite_url(url, version), fs_target_path)
for dep, dep_version in package_json.get("deps", ()):
@@ -139,7 +132,7 @@ def _install_json(transport, package_json_url, index, target, version, mpy):
def _install_package(transport, package, index, target, version, mpy):
if package.startswith(allowed_mip_url_prefixes):
if package.startswith(_ALLOWED_MIP_URL_PREFIXES):
if package.endswith(".py") or package.endswith(".mpy"):
print(f"Downloading {package} to {target}")
_download_file(