Repository navigation
Importing modules, take 2 - #33
Closed
laurensvalk wants to merge 2 commits into
Closed
laurensvalk wants to merge 2 commits into
laurensvalk wants to merge 2 commits into
Conversation
This takes the files as-is from MicroPython 1.18. Maybe this could be turned into a published package one day.
Member
Author
|
Closing in favor of real imports in #37 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is not quite ready to be merged, but it is too much fun to not share. It provides an interesting exploration for what we can do now that Pybricks Code supports multiple files.
This PR lets us do multi-file projects of the following kind:
It relies on MicroPython's existing
mpy-toolto merge.mpyfiles and run them all one by one. Because of this, no changes to the firmware are required.To make it work, it looks for import statement of the form:
In both cases, everything gets "imported", as if substituted in-place. Except without altering the line numbers. Not perfect, but still very useful.
This has similarities with #20, but it is simpler to implement.
I have not implemented any recursive imports in this demo yet. So right now, you can only use imports from the main script that you are running. I also limited it to the import variants shown above. But this is fine for the flat file structure we have in Pybricks Code right now (no folders/projects, just one directory with files.).