Skip to content

Commit 011565f

Browse files
committed
Use Poetry for Python dependencies management
Previously, pip and venv were used for dependencies management. Since the time this project was set up, the Arduino Tooling Team has settled on Poetry as the standard tool for this task.
1 parent 6a16c2a commit 011565f

File tree

11 files changed

+842
-115
lines changed

11 files changed

+842
-115
lines changed

.github/workflows/lint-python.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
name: Lint Python code
22

3+
env:
4+
# See: https://pypi.org/project/poetry/#history
5+
POETRY_VERSION: 1.4.0
6+
37
on:
48
pull_request:
59
paths:
610
- '.github/workflows/lint-python.yml'
711
- 'compilesketches/**.py'
812
- '.python-version'
13+
- '**/poetry.lock'
14+
- '**/pyproject.toml'
915

1016
push:
1117
paths:
1218
- '.github/workflows/lint-python.yml'
1319
- 'compilesketches/**.py'
1420
- '.python-version'
21+
- '**/poetry.lock'
22+
- '**/pyproject.toml'
1523

1624
# Scheduled trigger checks for workflow failures resulting from updates to the linting tools
1725
schedule:
@@ -39,23 +47,20 @@ jobs:
3947
with:
4048
python-version-file: .python-version
4149

42-
- name: Run the set up script
43-
id: setup
50+
- name: Install Poetry
4451
run: |
45-
"${{ github.workspace }}/action-setup.sh"
52+
pipx \
53+
install \
54+
poetry==${{ env.POETRY_VERSION }}
4655
47-
- name: Install flake8
56+
- name: Install Python Dependencies
4857
run: |
49-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
50-
python \
51-
-m \
52-
pip install \
53-
flake8 \
54-
pep8-naming
58+
poetry \
59+
install \
60+
--only dev
5561
5662
- name: Lint with flake8
5763
env:
5864
PYTHON_PROJECT_PATH: ${GITHUB_WORKSPACE}/compilesketches
5965
run: |
60-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
61-
flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"
66+
poetry run flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"

.github/workflows/lint-shell.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/test-python.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
name: Test Python code
22

3+
env:
4+
# See: https://pypi.org/project/poetry/#history
5+
POETRY_VERSION: 1.4.0
6+
37
on:
48
pull_request:
59
paths:
610
- '.github/workflows/test-python.yml'
711
- '.python-version'
8-
- 'action-setup.sh'
12+
- '**/poetry.lock'
13+
- '**/pyproject.toml'
914
- 'compilesketches/**'
1015

1116
push:
1217
paths:
1318
- '.github/workflows/test-python.yml'
1419
- '.python-version'
15-
- 'action-setup.sh'
20+
- '**/poetry.lock'
21+
- '**/pyproject.toml'
1622
- 'compilesketches/**'
1723

1824
# Catch issues resulting from new patch releases of Python in the APT repository
@@ -46,43 +52,40 @@ jobs:
4652
with:
4753
python-version-file: .python-version
4854

49-
- name: Run the set up script
50-
id: setup
55+
- name: Install Poetry
5156
run: |
52-
"${{ github.workspace }}/action-setup.sh"
57+
pipx \
58+
install \
59+
poetry==${{ env.POETRY_VERSION }}
5360
54-
- name: Install test dependencies
61+
- name: Install Python Dependencies
5562
run: |
56-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
57-
python \
58-
-m \
59-
pip install \
60-
--requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
63+
poetry install
6164
6265
- name: Run Python unit tests and record code coverage data
6366
run: |
64-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
6567
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
66-
python \
67-
-m \
68-
coverage run \
69-
--rcfile="${{ env.PYTHON_PROJECT_TESTS_PATH }}/.coveragerc" \
70-
--source="${{ env.PYTHON_PROJECT_PATH }}" \
71-
--module \
72-
pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
68+
poetry run \
69+
python \
70+
-m \
71+
coverage run \
72+
--source="${{ env.PYTHON_PROJECT_PATH }}" \
73+
--module \
74+
pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
7375
# Generate coverage data file for consumption by `codecov/codecov-action`.
7476
# Otherwise that action generates the file using the system Python environment, which doesn't work.
75-
python \
76-
-m \
77-
coverage xml \
78-
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
77+
poetry run \
78+
python \
79+
-m \
80+
coverage xml \
81+
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
7982
8083
- name: Display code coverage report
8184
run: |
82-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
83-
python \
84-
-m \
85-
coverage report
85+
poetry run \
86+
python \
87+
-m \
88+
coverage report
8689
8790
- name: Upload coverage report to Codecov
8891
uses: codecov/codecov-action@v3

action-setup.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

action.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ runs:
5454
with:
5555
python-version-file: ${{ github.action_path }}/.python-version
5656

57-
- name: Run the set up script
58-
id: setup
57+
- name: Install Poetry
5958
shell: bash
6059
run: |
61-
# Group action setup log output
62-
echo "::group::Action set up"
63-
"${{ github.action_path }}/action-setup.sh"
64-
echo "::endgroup::"
60+
pipx install \
61+
poetry==1.4.0
62+
63+
- name: Install Python Dependencies
64+
shell: bash
65+
working-directory: ${{ github.action_path }}
66+
run: |
67+
poetry install \
68+
--only main
6569
6670
- name: Run script
6771
shell: bash
@@ -77,6 +81,7 @@ runs:
7781
INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }}
7882
INPUT_ENABLE-WARNINGS-REPORT: ${{ inputs.enable-warnings-report }}
7983
INPUT_SKETCHES-REPORT-PATH: ${{ inputs.sketches-report-path }}
84+
working-directory: ${{ github.action_path }}
8085
run: |
81-
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
82-
python "${{ github.action_path }}/compilesketches/compilesketches.py"
86+
poetry run \
87+
python "${{ github.action_path }}/compilesketches/compilesketches.py"

compilesketches/.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[flake8]
22
doctests = True
3-
extend-exclude = .venv
43
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
54
ignore = W503
65
max-complexity = 10

compilesketches/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

compilesketches/tests/.coveragerc

Lines changed: 0 additions & 3 deletions
This file was deleted.

compilesketches/tests/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)