Skip to content

Commit

Permalink
Remove MicroPython compatibility code (#3184)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith authored Feb 12, 2025
1 parent 32000af commit 13e4fa9
Show file tree
Hide file tree
Showing 22 changed files with 14 additions and 717 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,71 +141,6 @@ 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
id: 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)
echo "executable=$(pwd)/build-pyscript/micropython" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/[email protected]

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.13"

- name: Get Core Package
uses: actions/[email protected]
with:
name: Packages-toga-core
path: dist

- name: Get Travertino Package
uses: actions/[email protected]
with:
name: Packages-toga-travertino
path: dist

- name: Test
run: |
# We don't *explicitly* install the Travertino wheel; we provide the dist dir
# as a source of wheels, and rely on pip to resolve the explicit version match
# to the travertino wheel in that folder.
pip install --find-links ./dist 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"
${{ steps.micropython.outputs.executable }} micropython_check.py
core-and-travertino-coverage:
name: "Coverage: ${{ matrix.package }}"
needs: core-and-travertino
Expand Down
2 changes: 1 addition & 1 deletion changes/2976.misc.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MicroPython compatibility
Initial MicroPython compatibility code was added.
1 change: 1 addition & 0 deletions changes/3184.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MicroPython compatibility code was removed.
51 changes: 0 additions & 51 deletions core/micropython_check.py

This file was deleted.

1 change: 0 additions & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ relative_files = true
# See notes in the root pyproject.toml file.
source = ["src"]
source_pkgs = ["toga"]
omit = ["**/toga/compat/**"] # Only used by MicroPython.

[tool.coverage.paths]
source = [
Expand Down
34 changes: 9 additions & 25 deletions core/src/toga/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Enable the standard library compatibility shims before doing anything else.
#
# __future__ imports must be at the very top of the file, and MicroPython doesn't
# currently include a __future__ module, so this file can't contain any __future__
# imports. Other modules imported after `compat` can use __future__ as normal.
import sys

if sys.implementation.name != "cpython": # pragma: no cover
from . import compat # noqa: F401

import importlib
import warnings
from importlib import import_module

toga_core_imports = {
# toga.app imports
Expand Down Expand Up @@ -92,21 +82,15 @@


def __getattr__(name):
if module_name := toga_core_imports.get(name):
module = import_module(module_name)
value = getattr(module, name)
try:
module_name = toga_core_imports[name]
except KeyError:
raise AttributeError(f"module '{__name__}' has no attribute '{name}'") from None
else:
# MicroPython apparently doesn't attempt a submodule import when __getattr__
# raises AttributeError, so we need to do it manually.
try:
value = import_module(f"{__name__}.{name}")
except ImportError:
raise AttributeError(
f"module '{__name__}' has no attribute '{name}'"
) from None

globals()[name] = value
return value
module = importlib.import_module(module_name)
value = getattr(module, name)
globals()[name] = value
return value


class NotImplementedWarning(RuntimeWarning):
Expand Down
13 changes: 3 additions & 10 deletions core/src/toga/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import asyncio
import importlib.metadata
import signal
import sys
import warnings
import webbrowser
from collections.abc import Coroutine, Iterator
from pathlib import Path
from typing import TYPE_CHECKING, Any, Protocol
Expand Down Expand Up @@ -450,13 +452,7 @@ def main_loop(self) -> None:
On mobile and web platforms, it returns immediately.
"""
# Modify signal handlers to make sure Ctrl-C is caught and handled.
try:
# This module doesn't exist in MicroPython, so don't import it globally.
import signal
except ModuleNotFoundError: # pragma: no cover
pass
else:
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.SIG_DFL)

self._impl.main_loop()

Expand Down Expand Up @@ -790,9 +786,6 @@ def visit_homepage(self) -> None:
will be disabled.
"""
if self.home_page is not None:
# This module doesn't exist in MicroPython, so don't import it globally.
import webbrowser

webbrowser.open(self.home_page)

######################################################################
Expand Down
10 changes: 0 additions & 10 deletions core/src/toga/compat/__future__.py

This file was deleted.

46 changes: 0 additions & 46 deletions core/src/toga/compat/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions core/src/toga/compat/abc.py

This file was deleted.

30 changes: 0 additions & 30 deletions core/src/toga/compat/builtins.py

This file was deleted.

1 change: 0 additions & 1 deletion core/src/toga/compat/collections/__init__.py

This file was deleted.

51 changes: 0 additions & 51 deletions core/src/toga/compat/collections/abc.py

This file was deleted.

Loading

0 comments on commit 13e4fa9

Please sign in to comment.