Skip to content

Wrap convenience import of machine.PWM inside a try/except#221

Merged
BrianPugh merged 2 commits intoBrianPugh:mainfrom
kyoungmeyer:stm32-import-fix
Mar 3, 2026
Merged

Wrap convenience import of machine.PWM inside a try/except#221
BrianPugh merged 2 commits intoBrianPugh:mainfrom
kyoungmeyer:stm32-import-fix

Conversation

@kyoungmeyer
Copy link
Copy Markdown
Contributor

The stm32 port of micropython doesn't include the machine.PWM module, this will make the convenience import optional.

Without this patch, adding the device with:

import belay

device = belay.Device("/dev/ttyACM0")

produces the error:

Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    device = belay.Device("/dev/ttyACM0")
  File "/home/kyoungmeyer/Code/IoT-pyboard/belay/belay/device.py", line 267, in __init__
    self._exec_snippet("convenience_imports_micropython")
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kyoungmeyer/Code/IoT-pyboard/belay/belay/device.py", line 339, in _exec_snippet
    return self("\n".join(snippets), **kwargs)
  File "/home/kyoungmeyer/Code/IoT-pyboard/belay/belay/device.py", line 562, in __call__
    self._board.exec(cmd, data_consumer=data_consumer)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kyoungmeyer/Code/IoT-pyboard/belay/belay/pyboard.py", line 601, in exec
    raise PyboardException(ret_err.decode())
belay.pyboard.PyboardException:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ImportError: can't import name PWM

This patch fixes the error. Tested on a Pyboard v1.1 with MicroPython 1.27.0.

…32 port of micropython doesn't include machine.PWM
@BrianPugh
Copy link
Copy Markdown
Owner

thanks! i'll merge this in and cut a patch release shortly!

@BrianPugh BrianPugh merged commit 20af4b8 into BrianPugh:main Mar 3, 2026
11 checks passed
@kyoungmeyer kyoungmeyer deleted the stm32-import-fix branch March 3, 2026 22:57
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.58%. Comparing base (acbc18f) to head (645351e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #221      +/-   ##
==========================================
- Coverage   71.62%   71.58%   -0.04%     
==========================================
  Files          48       48              
  Lines        3027     3027              
  Branches      479      479              
==========================================
- Hits         2168     2167       -1     
- Misses        744      745       +1     
  Partials      115      115              
Flag Coverage Δ
unittests 71.55% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

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