Skip to content

tools/mpremote: Add an alias for codeberg repos.#18989

Open
agatti wants to merge 1 commit intomicropython:masterfrom
agatti:mpremote-codeberg
Open

tools/mpremote: Add an alias for codeberg repos.#18989
agatti wants to merge 1 commit intomicropython:masterfrom
agatti:mpremote-codeberg

Conversation

@agatti
Copy link
Copy Markdown
Contributor

@agatti agatti commented Mar 24, 2026

Summary

This PR 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 to those packages easier, now they can be referenced as
"codeberg:org/repo@branch".

Testing

I've pushed a test package on codeberg myself to test the behaviour of mpremote (https://codeberg.org/agatti/micropython-package-test). The package was successfully installed on an ESP8266 board, also when referenced with a custom branch/tag name.

Trade-offs and Alternatives

Whilst this does not directly impact the interpreter, it might be seen an invitation for others to add niche Git hosting providers that few people use, or for services that may not be seen as long-lasting. Except for services that cater to a specific region (eg. Mainland China), the only other provider I reckon that may have some traction is SourceHut, but I don't really have any numbers to back my assumptions up.

I've refactored the alias lookup code a bit to make addition of a new provider easier to reason with. If adding a new alias for Codeberg is not something worth having, at least the refactoring can still be useful.

Generative AI

I did not use generative AI tools when creating this PR.

@agatti agatti added the tools Relates to tools/ directory in source, or other tooling label Mar 24, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 24, 2026

Code size report:

Reference:  esp32/boards/SEEED_XIAO_ESP32C6: Add new XIAO board definition. [2dc2e30]
Comparison: tools/mpremote: Add an alias for codeberg repos. [merge of 958c042]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (5c00edc) to head (958c042).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18989   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files         176      176           
  Lines       22784    22784           
=======================================
  Hits        22435    22435           
  Misses        349      349           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Josverl
Copy link
Copy Markdown
Contributor

Josverl commented Mar 25, 2026

The mipmodule would need a similar update to avoid creating difference between remote and local MIP install.

There will be some firmware impact, but I would support a limited list of additional shorthands for common hosting services.

@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 25, 2026

The mipmodule would need a similar update to avoid creating difference between remote and local MIP install.

Indeed! Thanks for the reminder, I've submitted the micropython-lib part of this change right now.

@yvo64
Copy link
Copy Markdown

yvo64 commented Mar 26, 2026

"codeberg:": "https://codeberg.org/{org}/{repo}/raw/branch/{branch}/{path}"

Should only a branch reference possible?
Or also a tag reference?

I think a tag reference will not work with this API.

E.g.
https://codeberg.org/yvo/micropython-ahtx/raw/branch/main/README.md works
https://codeberg.org/yvo/micropython-ahtx/raw/branch/v0.0.1/README.md results in a 404 error.

@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 26, 2026

Sigh. Yes, they have one url for tags and one for branches (if you replace /branch/ with /tag/ your link works).

I'll open an issue on codeberg itself and ask them how to proceed in this case, since you can't expect the on-device component of the package manager to handle auth tokens, and maybe they won't like being hit twice (once for /branch/ and once for /tag/) on each file download attempt.

Thanks a lot for letting me know. Marking as draft.

@agatti agatti marked this pull request as draft March 26, 2026 17:35
@yvo64
Copy link
Copy Markdown

yvo64 commented Mar 26, 2026

You could use the Forgejo API: https://codeberg.org/api/swagger#/repository/repoGetRawFile

I think if your line would look like this, it should work:
"codeberg:": "https://codeberg.org/api/v1/repos/{org}/{repo}/raw/{path}?ref={branch}"

@agatti agatti force-pushed the mpremote-codeberg branch from f11e14f to 317013a Compare March 26, 2026 17:47
@agatti agatti marked this pull request as ready for review March 26, 2026 17:49
@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 26, 2026

Turns out that if you remove /branch/ it automatically picks the right URL :) Can you please try this version?

@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 26, 2026

Nevermind, you're right - the client on the device doesn't follow redirects. I'll update using your path reference.

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>
@agatti agatti force-pushed the mpremote-codeberg branch from 317013a to 958c042 Compare March 26, 2026 18:32
@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 26, 2026

Done!

@yvo64 I've used your package for tests, it works both via mpremote mip install codeberg:yvo/micropython-ahtx@v0.0.1 and via import mip; mip.install("codeberg:yvo/micropython-ahtx", version="v0.0.1") if you update your lib/micropython-lib/micropython/mip/mip/__init__.py file with the one from micropython/micropython-lib#1101.

@Josverl
Copy link
Copy Markdown
Contributor

Josverl commented Mar 26, 2026

good catch, is there a way to create a repeatable test for the different patterns - even if that test is manual only and skipped in ci builds ?

@agatti
Copy link
Copy Markdown
Contributor Author

agatti commented Mar 26, 2026

I guess we can publish a micropython-download-test package on each provider and have a script that performs a local filesystem download along with a sha1 check on the output.

If that's acceptable I don't mind writing the test package and the script myself, after the appropriate accounts have been opened by somebody with a micropython.org email address :)

Copy link
Copy Markdown
Contributor

@Josverl Josverl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested with all source specifications I think are relevant, and they all work.

https://gist.github.com/Josverl/61cdc3c742ba1e1761d5041c8483a011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Relates to tools/ directory in source, or other tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants