Skip to content

mip: Avoid str.rpartition for limited builds. - #1174

Open
mattytrentini wants to merge 1 commit into
micropython:masterfrom
mattytrentini:mip-no-rpartition
Open

mattytrentini wants to merge 1 commit into
micropython:masterfrom
mattytrentini:mip-no-rpartition

Conversation

@mattytrentini

Copy link
Copy Markdown
Contributor

Summary

The ESP8266 port disables str.partition and str.rpartition (with MICROPY_PY_BUILTINS_STR_PARTITION) to save flash. mip uses str.rpartition so mip fails when running on an ESP8266. This PR uses rfind and slicing instead of rpartition so mip operates on the ESP8266.

Bump mip to version 0.5.1 (from 0.5.0).

Testing

Tested on the unix port to ensure mip continues to work correctly.

Not tested on the ESP8266 yet.

Trade-offs and Alternatives

The initial workaround was to remove onboard mip from the ESP8266 port. See #19844.

Generative AI

I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.

ESP8266 disables str.partition and str.rpartition to save flash, so
installing a package manifest currently fails when deriving its base URL.
Use rfind and slicing instead, preserving the empty prefix when no slash
is present. This avoids requiring partition support on limited builds
without removing the on-device package installer.

Bump mip to version 0.5.1.

See micropython/micropython#19844

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
return False
base_url = package_json_url.rpartition("/")[0]
# str.rpartition is not available on all builds.
slash = package_json_url.rfind("/")

@Josverl Josverl Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a reason not to use package_json_url.split("/",1)[0] ?
That would leave the code simpler and I assume the memory fragmentation is not that much worse

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants