simulate-circuitpython-nativesim 1.0.0__tar.gz
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.
- simulate_circuitpython_nativesim-1.0.0/.github/workflows/publish.yml +35 -0
- simulate_circuitpython_nativesim-1.0.0/.pre-commit-config.yaml +20 -0
- simulate_circuitpython_nativesim-1.0.0/LICENSE +21 -0
- simulate_circuitpython_nativesim-1.0.0/LICENSES/MIT.txt +18 -0
- simulate_circuitpython_nativesim-1.0.0/LICENSES/Unlicense.txt +10 -0
- simulate_circuitpython_nativesim-1.0.0/PKG-INFO +39 -0
- simulate_circuitpython_nativesim-1.0.0/README.md +20 -0
- simulate_circuitpython_nativesim-1.0.0/README.md.license +2 -0
- simulate_circuitpython_nativesim-1.0.0/VERSION +1 -0
- simulate_circuitpython_nativesim-1.0.0/VERSION.license +2 -0
- simulate_circuitpython_nativesim-1.0.0/action.yml +140 -0
- simulate_circuitpython_nativesim-1.0.0/circuitpy_sim.py +70 -0
- simulate_circuitpython_nativesim-1.0.0/pyproject.toml +54 -0
- simulate_circuitpython_nativesim-1.0.0/scripts/prepare.py +32 -0
- simulate_circuitpython_nativesim-1.0.0/scripts/simulate.py +8 -0
- simulate_circuitpython_nativesim-1.0.0/setup.cfg +4 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/PKG-INFO +39 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/SOURCES.txt +20 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/dependency_links.txt +1 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/entry_points.txt +2 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/requires.txt +3 -0
- simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Alec Delaney
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
name: Run publish-specific workflows
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout the repository
|
|
17
|
+
uses: actions/checkout@v6
|
|
18
|
+
with:
|
|
19
|
+
submodules: true
|
|
20
|
+
- name: Install Python
|
|
21
|
+
uses: actions/setup-python@v6
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.X"
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install -U pip
|
|
27
|
+
pip install build
|
|
28
|
+
- name: Update package version to ${{ github.event.release.tag_name }}
|
|
29
|
+
run: |
|
|
30
|
+
echo "${{ github.event.release.tag_name }}" > VERSION
|
|
31
|
+
- name: Build the package
|
|
32
|
+
run: |
|
|
33
|
+
python -m build
|
|
34
|
+
- name: Publish to PyPI
|
|
35
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
|
|
2
|
+
# SPDX-License-Identifier: Unlicense
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v6.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
- id: check-yaml
|
|
9
|
+
- id: end-of-file-fixer
|
|
10
|
+
- id: trailing-whitespace
|
|
11
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
12
|
+
rev: v0.15.5
|
|
13
|
+
hooks:
|
|
14
|
+
- id: ruff-format
|
|
15
|
+
- id: ruff
|
|
16
|
+
args: ["--fix"]
|
|
17
|
+
- repo: https://github.com/fsfe/reuse-tool
|
|
18
|
+
rev: v6.2.0
|
|
19
|
+
hooks:
|
|
20
|
+
- id: reuse
|
|
@@ -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,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) <year> <copyright holders>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
|
|
4
|
+
|
|
5
|
+
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and
|
|
6
|
+
successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
|
|
10
|
+
For more information, please refer to <http://unlicense.org/>
|
|
@@ -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,20 @@
|
|
|
1
|
+
# simulate-circuitpython
|
|
2
|
+
Simulate CircuitPython using Zephyr simulator
|
|
3
|
+
|
|
4
|
+
## Inputs
|
|
5
|
+
|
|
6
|
+
| Argument Name | Description | Default | Notes |
|
|
7
|
+
| --- | --- | --- | --- |
|
|
8
|
+
| ``version`` | Version of CircuitPython to simulate | ``main`` | Must be a version that supports the Zephyr OS native sim |
|
|
9
|
+
| ``circuitpy`` | Filepath to file or folder of files to add to the simualted CIRCUITPY | N/A (required) | |
|
|
10
|
+
| ``circuitpython-folder`` | Folder name to use for the CircuitPython checkout | ``cpysim`` | Change this if it conflicts with another file/folder |
|
|
11
|
+
|
|
12
|
+
## Outputs
|
|
13
|
+
|
|
14
|
+
| Argument Name | Description | Notes |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| ``output-text`` | The text output from the simulator | |
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
This library is available under an MIT license.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v1.0.0
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Alec Delaney
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
name: 'Simulate CircuitPython'
|
|
5
|
+
description: 'Simulate CircuitPython using Zephyr simulator'
|
|
6
|
+
inputs:
|
|
7
|
+
version:
|
|
8
|
+
description: 'Version of CircuitPython to simulate'
|
|
9
|
+
required: true
|
|
10
|
+
default: main
|
|
11
|
+
circuitpy:
|
|
12
|
+
description: 'Filepath to file or folder of files to add to the simualted CIRCUITPY'
|
|
13
|
+
required: true
|
|
14
|
+
circuitpython-folder:
|
|
15
|
+
description: 'Folder name to use for the CircuitPython checkout'
|
|
16
|
+
required: true
|
|
17
|
+
default: 'cpysim'
|
|
18
|
+
outputs:
|
|
19
|
+
output-text:
|
|
20
|
+
description: 'The text output from the simulator'
|
|
21
|
+
value: ${{ steps.run-sim.outputs.simout }}
|
|
22
|
+
runs:
|
|
23
|
+
using: "composite"
|
|
24
|
+
steps:
|
|
25
|
+
- name: Setup Python 3.12
|
|
26
|
+
uses: actions/setup-python@v6
|
|
27
|
+
with:
|
|
28
|
+
python-version: 3.12
|
|
29
|
+
- name: Checkout CircuitPython repository
|
|
30
|
+
uses: actions/checkout@v6
|
|
31
|
+
with:
|
|
32
|
+
repository: adafruit/circuitpython
|
|
33
|
+
path: ${{ inputs.circuitpython-folder }}
|
|
34
|
+
ref: ${{ inputs.version }}
|
|
35
|
+
fetch-depth: 0
|
|
36
|
+
- name: Determine cache key
|
|
37
|
+
id: cache-key
|
|
38
|
+
shell: bash
|
|
39
|
+
working-directory: ${{ inputs.circuitpython-folder }}
|
|
40
|
+
run: |
|
|
41
|
+
if [[ "${{ inputs.version }}" == "main" ]]; then
|
|
42
|
+
GITREV=$(git rev-parse --short HEAD)
|
|
43
|
+
CACHE_KEY="$GITREV-zephyr-cache"
|
|
44
|
+
else
|
|
45
|
+
CACHE_KEY="${{ inputs.version }}-zephyr-cache"
|
|
46
|
+
fi
|
|
47
|
+
echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_OUTPUT
|
|
48
|
+
- name: Install system dependencies
|
|
49
|
+
shell: bash
|
|
50
|
+
run: |
|
|
51
|
+
sudo apt-get update
|
|
52
|
+
sudo apt-get install -y \
|
|
53
|
+
libusb-1.0-0-dev \
|
|
54
|
+
libudev-dev \
|
|
55
|
+
mtools \
|
|
56
|
+
protobuf-compiler \
|
|
57
|
+
dosfstools \
|
|
58
|
+
gcc-multilib \
|
|
59
|
+
g++-multilib
|
|
60
|
+
- name: Cache firmware build
|
|
61
|
+
id: cache-firmware
|
|
62
|
+
uses: actions/cache@v5
|
|
63
|
+
with:
|
|
64
|
+
path: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp/build-native_native_sim/firmware.exe
|
|
65
|
+
key: ${{ steps.cache-key.outputs.CACHE_KEY }}
|
|
66
|
+
- name: Fetch submodules
|
|
67
|
+
shell: bash
|
|
68
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
69
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
70
|
+
run: make fetch-port-submodules
|
|
71
|
+
- name: Install CircuitPython dev dependencies
|
|
72
|
+
shell: bash
|
|
73
|
+
working-directory: ${{ inputs.circuitpython-folder }}
|
|
74
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
75
|
+
run: pip install -r requirements-dev.txt
|
|
76
|
+
- name: Install west
|
|
77
|
+
shell: bash
|
|
78
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
79
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
80
|
+
run: pip install west
|
|
81
|
+
- name: Create west workspace
|
|
82
|
+
shell: bash
|
|
83
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
84
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
85
|
+
run: west init -l zephyr-config
|
|
86
|
+
- name: Update west project
|
|
87
|
+
shell: bash
|
|
88
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
89
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
90
|
+
run: west update
|
|
91
|
+
- name: Export Zephyr installation
|
|
92
|
+
shell: bash
|
|
93
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
94
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
95
|
+
run: west zephyr-export
|
|
96
|
+
- name: Install Zephyr script dependencies
|
|
97
|
+
shell: bash
|
|
98
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
99
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
100
|
+
run: |
|
|
101
|
+
pip install -r zephyr/scripts/requirements.txt
|
|
102
|
+
pip install protobuf grpcio-tools
|
|
103
|
+
- name: Install Zephyr SDK
|
|
104
|
+
shell: bash
|
|
105
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
106
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
107
|
+
run: west sdk install
|
|
108
|
+
- name: Make the firmware
|
|
109
|
+
shell: bash
|
|
110
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
111
|
+
if: steps.cache-firmware.outputs.cache-hit != 'true'
|
|
112
|
+
run: make BOARD=native_native_sim BUILD=build-native_native_sim build-native_native_sim/firmware.exe
|
|
113
|
+
- name: Create flash space
|
|
114
|
+
shell: bash
|
|
115
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
116
|
+
run: |
|
|
117
|
+
truncate -s 2M build-native_native_sim/flash.bin
|
|
118
|
+
mformat -i build-native_native_sim/flash.bin ::
|
|
119
|
+
- name: Create CIRCUITPY folder
|
|
120
|
+
shell: bash
|
|
121
|
+
run: |
|
|
122
|
+
python ${{ github.action_path }}/scripts/prepare.py ${{ inputs.circuitpy }} ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
123
|
+
- name: Add files to flash
|
|
124
|
+
shell: bash
|
|
125
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
126
|
+
run: mcopy -s -i build-native_native_sim/flash.bin CIRCUITPY/* ::;
|
|
127
|
+
- name: Install simulator command
|
|
128
|
+
shell: bash
|
|
129
|
+
run: pipx install ${{ github.action_path }}
|
|
130
|
+
- name: Run simulator script
|
|
131
|
+
id: run-sim
|
|
132
|
+
shell: bash
|
|
133
|
+
working-directory: ${{ inputs.circuitpython-folder }}/ports/zephyr-cp
|
|
134
|
+
run: |
|
|
135
|
+
SIM_OUTPUT=$(simulate-circuitpython)
|
|
136
|
+
{
|
|
137
|
+
echo "simout<<EOF"
|
|
138
|
+
echo "$SIM_OUTPUT"
|
|
139
|
+
echo "EOF"
|
|
140
|
+
} >> "$GITHUB_OUTPUT"
|
|
@@ -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,54 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026 Alec Delaney
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
[build-system]
|
|
5
|
+
requires = [
|
|
6
|
+
"setuptools",
|
|
7
|
+
"wheel",
|
|
8
|
+
"setuptools-scm",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "simulate-circuitpython-nativesim"
|
|
13
|
+
description = "Simulate CircuitPython using Zephyr simulator"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
authors = [
|
|
16
|
+
{name = "Alec Delaney", email = "tekktrik@gmail.com"}
|
|
17
|
+
]
|
|
18
|
+
urls = {Homepage = "https://github.com/tekktrik/simulate-circuitpython"}
|
|
19
|
+
keywords = [
|
|
20
|
+
"adafruit",
|
|
21
|
+
"blinka",
|
|
22
|
+
"circuitpython",
|
|
23
|
+
"micropython",
|
|
24
|
+
"zephyr",
|
|
25
|
+
"simulate",
|
|
26
|
+
"simulator",
|
|
27
|
+
]
|
|
28
|
+
license = "MIT"
|
|
29
|
+
classifiers = [
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"Topic :: Software Development :: Libraries",
|
|
32
|
+
"Topic :: Software Development :: Embedded Systems",
|
|
33
|
+
"Topic :: System :: Hardware",
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
]
|
|
36
|
+
dynamic = ["version"]
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = [
|
|
40
|
+
"pre-commit~=4.5",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
simulate-circuitpython = "circuitpy_sim:simulate_circuitpython"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
py-modules = ["circuitpy_sim"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.dynamic.version]
|
|
50
|
+
file = "VERSION"
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
select = ["D", "PL", "I"]
|
|
54
|
+
ignore = ["D213", "D203"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026 Alec Delaney
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""Prepare the CIRCUITPY drive."""
|
|
5
|
+
|
|
6
|
+
import pathlib
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def prepare():
|
|
12
|
+
"""Prepare the CIRCUITPY drive folder."""
|
|
13
|
+
src = pathlib.Path(sys.argv[1])
|
|
14
|
+
dst = pathlib.Path(sys.argv[2])
|
|
15
|
+
|
|
16
|
+
if not src.exists():
|
|
17
|
+
print(f"Filepath {src.absolute()} does not exist")
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
|
|
20
|
+
circuitpy = dst / "CIRCUITPY"
|
|
21
|
+
circuitpy.mkdir()
|
|
22
|
+
|
|
23
|
+
if src.is_file():
|
|
24
|
+
print(f"Copying file {src} to {circuitpy}")
|
|
25
|
+
shutil.copy(src, circuitpy)
|
|
26
|
+
else:
|
|
27
|
+
print(f"Copying folder {src} to {circuitpy}")
|
|
28
|
+
shutil.copytree(src, circuitpy, dirs_exist_ok=True)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
prepare()
|
|
@@ -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,20 @@
|
|
|
1
|
+
.pre-commit-config.yaml
|
|
2
|
+
LICENSE
|
|
3
|
+
README.md
|
|
4
|
+
README.md.license
|
|
5
|
+
VERSION
|
|
6
|
+
VERSION.license
|
|
7
|
+
action.yml
|
|
8
|
+
circuitpy_sim.py
|
|
9
|
+
pyproject.toml
|
|
10
|
+
.github/workflows/publish.yml
|
|
11
|
+
LICENSES/MIT.txt
|
|
12
|
+
LICENSES/Unlicense.txt
|
|
13
|
+
scripts/prepare.py
|
|
14
|
+
scripts/simulate.py
|
|
15
|
+
simulate_circuitpython_nativesim.egg-info/PKG-INFO
|
|
16
|
+
simulate_circuitpython_nativesim.egg-info/SOURCES.txt
|
|
17
|
+
simulate_circuitpython_nativesim.egg-info/dependency_links.txt
|
|
18
|
+
simulate_circuitpython_nativesim.egg-info/entry_points.txt
|
|
19
|
+
simulate_circuitpython_nativesim.egg-info/requires.txt
|
|
20
|
+
simulate_circuitpython_nativesim.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
simulate_circuitpython_nativesim-1.0.0/simulate_circuitpython_nativesim.egg-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
circuitpy_sim
|