-
-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MicroPython compatibility #2976
Open
mhsmith
wants to merge
11
commits into
beeware:main
Choose a base branch
from
mhsmith:micropython
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9f928d
MicroPython compatibility
mhsmith 0ea1f8a
Start checking import of toga.App
mhsmith 239feec
Remove positional-only argument syntax
mhsmith 7654820
Remove nested f-string syntax
mhsmith e3b8c4b
Remove additional unpacking syntax
mhsmith 9a36239
toga.App import working
mhsmith c1b6b23
All other imports required by Invent working
mhsmith adb7fda
CI fixes
mhsmith 257cf6f
Cleanups
mhsmith 0bb610c
Merge branch 'main' into micropython
mhsmith 6c55ec3
Merge branch 'main' into micropython
mhsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,59 @@ jobs: | |
if-no-files-found: error | ||
include-hidden-files: true | ||
|
||
micropython: | ||
name: MicroPython compatibility | ||
runs-on: ubuntu-latest | ||
needs: [ pre-commit, towncrier, package ] | ||
steps: | ||
- name: Build MicroPython | ||
run: | | ||
# The following script also works on macOS, except that due to a bug, | ||
# threading must be enabled, i.e. THREAD must be omitted from the disabled | ||
# feature list. | ||
cd $RUNNER_TEMP | ||
git clone https://github.com/micropython/micropython -b v1.24.0 --depth 1 | ||
|
||
# Create a variant with the same configuration as the PyScript build. | ||
cd micropython/ports/unix | ||
cp -a variants/standard variants/pyscript | ||
grep require ../webassembly/variants/pyscript/manifest.py \ | ||
>> variants/pyscript/manifest.py | ||
for feature in BTREE FFI SOCKET SSL TERMIOS THREAD; do | ||
echo "MICROPY_PY_$feature = 0" >> variants/pyscript/mpconfigvariant.mk | ||
done | ||
|
||
export VARIANT=pyscript | ||
make submodules | ||
make -j $(nproc) | ||
|
||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- name: Set up Python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: "3.13" | ||
|
||
- name: Get Packages | ||
uses: actions/[email protected] | ||
with: | ||
name: Packages-toga-core | ||
path: dist | ||
|
||
- name: Test | ||
run: | | ||
pip install dist/toga_core-*.whl | ||
site_packages=$(python -c ' | ||
import sys | ||
print([path for path in sys.path if "site-packages" in path][0]) | ||
') | ||
|
||
cd core | ||
export MICROPYPATH="$site_packages:.frozen" | ||
$RUNNER_TEMP/micropython/ports/unix/build-pyscript/micropython \ | ||
micropython_check.py | ||
|
||
core-coverage: | ||
name: Coverage | ||
needs: core | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A subset of Toga is now compatible with MicroPython. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# This script should be run under MicroPython to check that it can import all the Toga | ||
# modules required by Invent. | ||
|
||
# The top-level Toga module must be imported first, to enable the standard library | ||
# compatibility shims. | ||
# | ||
# isort: off | ||
import toga | ||
|
||
# isort: on | ||
import sys | ||
import traceback | ||
|
||
# Access attributes to trigger lazy import. | ||
failures = 0 | ||
for name in [ | ||
"App", | ||
"Font", | ||
"Image", | ||
"Window", | ||
# | ||
"Widget", | ||
"Box", | ||
"Button", | ||
"DateInput", | ||
"Divider", | ||
"ImageView", | ||
"Label", | ||
"MultilineTextInput", | ||
"PasswordInput", | ||
"ProgressBar", | ||
"Slider", | ||
"Switch", | ||
"TextInput", | ||
"TimeInput", | ||
]: | ||
try: | ||
getattr(toga, name) | ||
except Exception: | ||
failures += 1 | ||
print(f"Failed to import toga.{name}:") | ||
traceback.print_exc() | ||
print() | ||
|
||
if failures: | ||
print(f"{failures} names failed to import") | ||
sys.exit(1) | ||
else: | ||
print("All names imported successfully") |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idle thought - should the compat module name be based on
sys.implementation.name
in some way? I don't have any idea which other implementations we'd be concerned about, but at the very least it would be clear from the namespace thattoga.compat.micropython
is a micropython compatibility shim.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there won't be any other implementations in the foreseeable future, let's cross that bridge when we come to it. I see this
compat
package as a temporary stopgap anyway – virtually all of it should eventually be upstreamed to micropython-lib.