simulate-circuitpython-nativesim 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
circuitpy_sim.py ADDED
@@ -0,0 +1,70 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026 Scott Shawcroft for Adafruit Industries
2
+ # SPDX-FileCopyrightText: Copyright (c) 2026 Alec Delaney
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ """Slim and simple version of the CircuitPython Zephyr test infrastructure."""
7
+
8
+ import subprocess
9
+
10
+
11
+ class Simualtor:
12
+ """Zephyr OS native sim wrapper."""
13
+
14
+ def __init__(self, timeout: int = 5) -> None:
15
+ """Intialize the simulator."""
16
+ self.simproc: subprocess.Popen | None = None
17
+ self.cmd = [
18
+ "build-native_native_sim/firmware.exe",
19
+ "--flash=build-native_native_sim/flash.bin",
20
+ "-rt",
21
+ "-uart_stdinout",
22
+ f"-stop_at={timeout}",
23
+ ]
24
+
25
+ def simulate(self) -> str:
26
+ """Simulate using the native sim firmware."""
27
+ self.simproc = subprocess.Popen(
28
+ self.cmd,
29
+ stdin=subprocess.PIPE,
30
+ stdout=subprocess.PIPE,
31
+ stderr=None,
32
+ )
33
+
34
+ if self.simproc.stdout is None:
35
+ raise RuntimeError("Failed to capture simulator output")
36
+
37
+ recording: bool | None = None
38
+ recorded = ""
39
+
40
+ while self.simproc.poll() is None:
41
+ pass
42
+
43
+ output: str = self.simproc.stdout.read().decode()
44
+ for line in output.split("\n"):
45
+ encoded = line.encode()
46
+ if not line:
47
+ continue
48
+ if (
49
+ encoded.strip() == b"\x1b[2K\x1b[0Gcode.py output:"
50
+ and recording is None
51
+ ):
52
+ recording = True
53
+ elif line.strip() == "Code done running." and recording:
54
+ recording = False
55
+ break
56
+ elif recording:
57
+ recorded += line + "\n"
58
+
59
+ return recorded.strip()
60
+
61
+
62
+ def simulate_circuitpython() -> None:
63
+ """Simulate CircuitPython using a simulator."""
64
+ simulator = Simualtor()
65
+ result = simulator.simulate()
66
+ print(result)
67
+
68
+
69
+ if __name__ == "__main__":
70
+ simulate_circuitpython()
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: simulate-circuitpython-nativesim
3
+ Version: 1.0.0
4
+ Summary: Simulate CircuitPython using Zephyr simulator
5
+ Author-email: Alec Delaney <tekktrik@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tekktrik/simulate-circuitpython
8
+ Keywords: adafruit,blinka,circuitpython,micropython,zephyr,simulate,simulator
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Libraries
11
+ Classifier: Topic :: Software Development :: Embedded Systems
12
+ Classifier: Topic :: System :: Hardware
13
+ Classifier: Programming Language :: Python :: 3
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: dev
17
+ Requires-Dist: pre-commit~=4.5; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # simulate-circuitpython
21
+ Simulate CircuitPython using Zephyr simulator
22
+
23
+ ## Inputs
24
+
25
+ | Argument Name | Description | Default | Notes |
26
+ | --- | --- | --- | --- |
27
+ | ``version`` | Version of CircuitPython to simulate | ``main`` | Must be a version that supports the Zephyr OS native sim |
28
+ | ``circuitpy`` | Filepath to file or folder of files to add to the simualted CIRCUITPY | N/A (required) | |
29
+ | ``circuitpython-folder`` | Folder name to use for the CircuitPython checkout | ``cpysim`` | Change this if it conflicts with another file/folder |
30
+
31
+ ## Outputs
32
+
33
+ | Argument Name | Description | Notes |
34
+ | --- | --- | --- |
35
+ | ``output-text`` | The text output from the simulator | |
36
+
37
+ ## License
38
+
39
+ This library is available under an MIT license.
@@ -0,0 +1,7 @@
1
+ circuitpy_sim.py,sha256=M12WYAsg-WRysRbozVgaxdTluN7pJ5PDawIbolnUnLU,2000
2
+ simulate_circuitpython_nativesim-1.0.0.dist-info/licenses/LICENSE,sha256=BymzcV7eq2KcugbuWnFGOg0q-abUWI_3FCDFSCM2Ppw,1069
3
+ simulate_circuitpython_nativesim-1.0.0.dist-info/METADATA,sha256=_YAAEJYpKZ89Dvgcb_qUtjTh0sy3NRViNLeGlFDMAhI,1493
4
+ simulate_circuitpython_nativesim-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ simulate_circuitpython_nativesim-1.0.0.dist-info/entry_points.txt,sha256=b9u5bWfqUuY2KPg6bN8UVqkL3CJf4Fdh0j7-YMCdP0M,80
6
+ simulate_circuitpython_nativesim-1.0.0.dist-info/top_level.txt,sha256=2bWMgC9nmjXSPX1VbYK-NgNmml14YbSiMrAjf_VuEnQ,14
7
+ simulate_circuitpython_nativesim-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ simulate-circuitpython = circuitpy_sim:simulate_circuitpython
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alec Delaney
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ circuitpy_sim