Skip to content

Commit a1ffe98

Browse files
authored
Merge pull request #108 from per1234/support-external-python-deps
Restore support for external Python package platform dependencies
2 parents 5b164ce + 69fd7b0 commit a1ffe98

File tree

11 files changed

+205
-6
lines changed

11 files changed

+205
-6
lines changed

.github/workflows/test-integration.yml

+59-2
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ on:
66
- '.github/workflows/test-integration.yml'
77
- '.github/workflows/testdata/**'
88
- 'action.yml'
9-
- 'action-setup.sh'
109
- 'compilesketches/**'
1110

1211
push:
1312
paths:
1413
- '.github/workflows/test-integration.yml'
1514
- '.github/workflows/testdata/**'
1615
- 'action.yml'
17-
- 'action-setup.sh'
1816
- 'compilesketches/**'
1917

2018
env:
2119
SKETCHES_REPORTS_PATH: sketches-reports
20+
TESTDATA_PLATFORMS_PATH: .github/workflows/testdata/platforms
2221
TESTDATA_SKETCHES_PATH: .github/workflows/testdata/sketches
2322
TESTDATA_REPORTS_PATH: .github/workflows/testdata/reports
2423

@@ -203,6 +202,64 @@ jobs:
203202
sketch-paths: |
204203
- examples/Sweep
205204
205+
python-package-dependency:
206+
runs-on: ubuntu-latest
207+
208+
steps:
209+
- name: Checkout local repo
210+
uses: actions/checkout@v3
211+
212+
- name: Install Python package dependency
213+
run: |
214+
pip install \
215+
--ignore-installed \
216+
--user \
217+
cowsay
218+
219+
- name: Run action with board that has external Python package dependency
220+
# Use action from local path
221+
uses: ./
222+
with:
223+
platforms: |
224+
- name: arduino:avr
225+
- source-path: ${{ env.TESTDATA_PLATFORMS_PATH }}/PythonPackageDependent
226+
name: PythonPackageDependent:avr
227+
fqbn: PythonPackageDependent:avr:package_dependent
228+
libraries: |
229+
[]
230+
sketch-paths: |
231+
- ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum
232+
233+
234+
# Targeted testing for ESP32 boards platform support.
235+
pyserial-dependency:
236+
runs-on: ubuntu-latest
237+
238+
steps:
239+
- name: Checkout local repo
240+
uses: actions/checkout@v3
241+
242+
- name: Install pyserial
243+
run: |
244+
# Use of pip3 and omission of recommended flags done to reproduce established use pattern:
245+
# https://github.com/arduino-libraries/ArduinoIoTCloud/blob/1.11.0/.github/workflows/compile-examples.yml#L206
246+
pip3 install pyserial
247+
248+
- name: Run action with board that has pyserial dependency
249+
# Use action from local path
250+
uses: ./
251+
with:
252+
platforms: |
253+
- name: arduino:avr
254+
- source-path: ${{ env.TESTDATA_PLATFORMS_PATH }}/PyserialDependent
255+
name: PyserialDependent:avr
256+
fqbn: PyserialDependent:avr:pyserial_dependent
257+
libraries: |
258+
[]
259+
sketch-paths: |
260+
- ${{ env.TESTDATA_SKETCHES_PATH }}/BareMinimum
261+
262+
206263
check-sketches-reports:
207264
needs: all-inputs
208265
runs-on: ubuntu-latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pyserial_dependent.name=pyserial Dependent Board
2+
pyserial_dependent.upload.maximum_size=32256
3+
pyserial_dependent.upload.maximum_data_size=2048
4+
pyserial_dependent.build.mcu=atmega328p
5+
pyserial_dependent.build.f_cpu=16000000L
6+
pyserial_dependent.build.board=FOO
7+
pyserial_dependent.build.core=arduino:arduino
8+
pyserial_dependent.build.variant=arduino:standard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name=pyserial Dependent Platform
2+
version=0.0.0
3+
# python3 is used to parallel ESP32 platform configuration:
4+
# https://github.com/espressif/arduino-esp32/blob/2.0.7/platform.txt#L220
5+
recipe.hooks.prebuild.1.pattern=python3 -c 'import serial'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package_dependent.name=External Python Package Dependent Board
2+
package_dependent.upload.maximum_size=32256
3+
package_dependent.upload.maximum_data_size=2048
4+
package_dependent.build.mcu=atmega328p
5+
package_dependent.build.f_cpu=16000000L
6+
package_dependent.build.board=FOO
7+
package_dependent.build.core=arduino:arduino
8+
package_dependent.build.variant=arduino:standard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Import external package to verify Python package dependencies can be installed by user into runner environment.
2+
import cowsay # noqa: F401
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=External Python Package Dependent Platform
2+
version=0.0.0
3+
recipe.hooks.prebuild.1.pattern=python "{runtime.platform.path}/dependent.py"

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This action checks whether [Arduino](https://www.arduino.cc/) sketches compile a
3535
- [How it works](#how-it-works)
3636
- [`enable-warnings-report`](#enable-warnings-report)
3737
- [Example usage](#example-usage)
38+
- [Additional resources](#additional-resources)
3839

3940
<!-- tocstop -->
4041

@@ -226,3 +227,10 @@ Set to `true` to cause the action to record the compiler warning count for each
226227
- name: Stepper
227228
version: 1.1.3
228229
```
230+
231+
## Additional resources
232+
233+
- [Introductory article about **arduino/compile-sketches**](https://blog.arduino.cc/2021/04/09/test-your-arduino-projects-with-github-actions/)
234+
- [Frequently asked questions about **arduino/compile-sketches**](docs/FAQ.md#frequently-asked-questions)
235+
- [**GitHub Actions** documentation](https://docs.github.com/actions/learn-github-actions/understanding-github-actions)
236+
- [Discuss or request assistance on **Arduino Forum**](https://forum.arduino.cc/)

action.yml

+27-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ inputs:
4949
runs:
5050
using: composite
5151
steps:
52+
# User installations of external Python package platform dependencies will be located here.
53+
- name: Get system Python "user site-packages" path
54+
id: system-user-site-packages
55+
shell: bash
56+
run: |
57+
echo "path=$(python -m site --user-site)" >> $GITHUB_OUTPUT
58+
5259
- name: Install Python
5360
uses: actions/[email protected]
5461
with:
@@ -58,14 +65,32 @@ runs:
5865
shell: bash
5966
run: |
6067
pipx install \
68+
--python "$(which python)" \
6169
poetry==1.4.0
6270
6371
- name: Install Python Dependencies
6472
shell: bash
6573
working-directory: ${{ github.action_path }}
6674
run: |
6775
poetry install \
68-
--only main
76+
--only main,external
77+
78+
- name: Make user-installed Python packages available to platforms
79+
shell: bash
80+
working-directory: ${{ github.action_path }}
81+
run: |
82+
readonly PYTHON_ENVIRONMENT_PATH="$(
83+
poetry env info \
84+
--path
85+
)"
86+
readonly VENV_SITE_PACKAGES_PATH="$(
87+
poetry run \
88+
python -c \
89+
'import site; print(site.getsitepackages()[0])'
90+
)"
91+
echo \
92+
"${{ steps.system-user-site-packages.outputs.path }}" > \
93+
"${VENV_SITE_PACKAGES_PATH}/system-user-site-packages.pth"
6994
7095
- name: Run script
7196
shell: bash
@@ -84,4 +109,4 @@ runs:
84109
working-directory: ${{ github.action_path }}
85110
run: |
86111
poetry run \
87-
python "${{ github.action_path }}/compilesketches/compilesketches.py"
112+
python compilesketches/compilesketches.py

docs/FAQ.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Frequently Asked Questions
2+
3+
## How can I install dependencies of a boards platform?
4+
5+
### Managed Dependencies
6+
7+
The Arduino **Boards Manager** system installs tool dependencies along with a platform. When you specify a [**Boards Manager**-sourced platform dependency](../README.md#boards-manager) via the action's [`platforms` input](../README.md#platforms) the managed platform dependencies are installed automatically.
8+
9+
If an alternative [platform dependency source](../README.md#supported-platform-sources) is used this automatic tool dependency installation does not occur. The convenient way to install the tool dependencies in this case is to install a **Boards Manager**-sourced platform that has a dependency on the required tools in addition to the target platform from the alternative source.
10+
11+
---
12+
13+
**Example:**
14+
15+
```yaml
16+
- uses: arduino/compile-sketches@v1
17+
with:
18+
platforms: |
19+
# Use Boards Manager to install the latest release of the platform to get the toolchain.
20+
- name: arduino:avr
21+
# Overwrite the Boards Manager installation with the development version of the platform.
22+
- source-url: https://github.com/arduino/ArduinoCore-avr.git
23+
name: arduino:avr
24+
```
25+
26+
---
27+
28+
### External Dependencies
29+
30+
Arduino boards platforms typically bundle all dependencies. However, there are some platforms that require the user to manually install dependencies on their system in order to use the platform.
31+
32+
The **arduino/compile-sketches** action runs in the same environment as the rest of the steps of the [workflow job](https://docs.github.com/actions/using-jobs/using-jobs-in-a-workflow), which means you can simply perform the dependency installation in a prior [step](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsteps) of the job.
33+
34+
---
35+
36+
**Example:**
37+
38+
```yaml
39+
- run: <some dependency installation command>
40+
- uses: arduino/compile-sketches@v1
41+
```
42+
43+
---
44+
45+
#### Python Packages
46+
47+
The **arduino/compile-sketches** action uses a Python [virtual environment](https://docs.python.org/glossary.html#term-virtual-environment). In order to enable user installation of Python [package](https://docs.python.org/glossary.html#term-package) dependencies of boards platforms, the packages installed in the "[user site-packages](https://peps.python.org/pep-0370/)" folder are included in this virtual environment.
48+
49+
In order to be certain your installation of a package dependency will be available to the platform, add the [`--ignore-installed`](https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-ignore-installed) and [`--user`](https://pip.pypa.io/en/stable/cli/pip_install/#install-user) flags to the [**pip**](https://pip.pypa.io/) command used to install the package.
50+
51+
---
52+
53+
**Example:**
54+
55+
```yaml
56+
- run: pip install --ignore-installed --user pyserial
57+
- uses: arduino/compile-sketches@v1
58+
```
59+
60+
---

poetry.lock

+17-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ pytest-mock = "3.10.0"
1818
flake8 = "5.0.4"
1919
pep8-naming = "0.13.3"
2020

21+
# Provided only for use by boards platforms
22+
# NOTE: This group is a temporary workaround that will be removed at the 2.0.0 release of the action.
23+
[tool.poetry.group.external]
24+
optional = true
25+
26+
[tool.poetry.group.external.dependencies]
27+
pyserial = "3.5"
28+
2129
[tool.pytest.ini_options]
2230
filterwarnings = [
2331
"error",

0 commit comments

Comments
 (0)