Add MicroPython/CircuitPython compatibility layer#640
Open
gijzelaerr wants to merge 2 commits intomasterfrom
Open
Add MicroPython/CircuitPython compatibility layer#640gijzelaerr wants to merge 2 commits intomasterfrom
gijzelaerr wants to merge 2 commits intomasterfrom
Conversation
Create snap7/compat.py with runtime detection and shims: - MICROPYTHON flag for runtime detection - functools.cache fallback (no-op on MicroPython) - HAS_CTYPES flag for conditional ctypes usage Update snap7/error.py to use the compat cache shim instead of importing functools.cache directly. Add tests/test_micropython_compat.py verifying that core protocol modules (connection, s7protocol, datatypes, util) work with only struct/bytearray operations -- no ctypes dependency. Closes #624 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e018b2b to
a7a8d74
Compare
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.
Summary
snap7/compat.pywith runtime detection (MICROPYTHONflag), afunctools.cachefallback for MicroPython, and aHAS_CTYPESavailability flagsnap7/error.pyto importcachefrom the new compat module instead offunctoolsdirectlytests/test_micropython_compat.pywith 29 tests verifying that core protocol modules work using onlystruct/bytearrayoperations (no ctypes dependency)Compatibility audit results
connection.pys7protocol.pydatatypes.pyerror.pyfunctools.cachereplaced with compat shimclient.pytype.pyutil/getters.pyutil/setters.pyutil/db.pyWhat works on MicroPython today
The core protocol stack (
connection.py,s7protocol.py,datatypes.py) and the utility getters/setters can run on MicroPython as-is. Thesnap7/compat.pymodule provides theMICROPYTHONflag and shims needed byerror.py.Known blockers for full MicroPython support
type.pyusesctypes.Structureextensively -- needs pure-Python dataclass replacements for MicroPythonclient.pyasync helpers usectypes.memmoveandctypes.Array-- core sync operations work fineimportlib.metadatain__init__.py-- not available in MicroPythonTest plan
Success: no issues found in 29 source files)All checks passed!)Closes #624
🤖 Generated with Claude Code