Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
per1234 committed Mar 17, 2023
commit 011565f5db93efd57baa591750d0180b0f9baa38
29 changes: 17 additions & 12 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
name: Lint Python code

env:
# See: https://pypi.org/project/poetry/#history
POETRY_VERSION: 1.4.0

on:
pull_request:
paths:
- '.github/workflows/lint-python.yml'
- 'compilesketches/**.py'
- '.python-version'
- '**/poetry.lock'
- '**/pyproject.toml'

push:
paths:
- '.github/workflows/lint-python.yml'
- 'compilesketches/**.py'
- '.python-version'
- '**/poetry.lock'
- '**/pyproject.toml'

# Scheduled trigger checks for workflow failures resulting from updates to the linting tools
schedule:
Expand Down Expand Up @@ -39,23 +47,20 @@ jobs:
with:
python-version-file: .python-version

- name: Run the set up script
id: setup
- name: Install Poetry
run: |
"${{ github.workspace }}/action-setup.sh"
pipx \
install \
poetry==${{ env.POETRY_VERSION }}

- name: Install flake8
- name: Install Python Dependencies
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
python \
-m \
pip install \
flake8 \
pep8-naming
poetry \
install \
--only dev

- name: Lint with flake8
env:
PYTHON_PROJECT_PATH: ${GITHUB_WORKSPACE}/compilesketches
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"
poetry run flake8 --config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" --show-source "${{ env.PYTHON_PROJECT_PATH }}"
24 changes: 0 additions & 24 deletions .github/workflows/lint-shell.yml

This file was deleted.

57 changes: 30 additions & 27 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
name: Test Python code

env:
# See: https://pypi.org/project/poetry/#history
POETRY_VERSION: 1.4.0

on:
pull_request:
paths:
- '.github/workflows/test-python.yml'
- '.python-version'
- 'action-setup.sh'
- '**/poetry.lock'
- '**/pyproject.toml'
- 'compilesketches/**'

push:
paths:
- '.github/workflows/test-python.yml'
- '.python-version'
- 'action-setup.sh'
- '**/poetry.lock'
- '**/pyproject.toml'
- 'compilesketches/**'

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

- name: Run the set up script
id: setup
- name: Install Poetry
run: |
"${{ github.workspace }}/action-setup.sh"
pipx \
install \
poetry==${{ env.POETRY_VERSION }}

- name: Install test dependencies
- name: Install Python Dependencies
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
python \
-m \
pip install \
--requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
poetry install

- name: Run Python unit tests and record code coverage data
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
python \
-m \
coverage run \
--rcfile="${{ env.PYTHON_PROJECT_TESTS_PATH }}/.coveragerc" \
--source="${{ env.PYTHON_PROJECT_PATH }}" \
--module \
pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
poetry run \
python \
-m \
coverage run \
--source="${{ env.PYTHON_PROJECT_PATH }}" \
--module \
pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
# Generate coverage data file for consumption by `codecov/codecov-action`.
# Otherwise that action generates the file using the system Python environment, which doesn't work.
python \
-m \
coverage xml \
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
poetry run \
python \
-m \
coverage xml \
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"

- name: Display code coverage report
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
python \
-m \
coverage report
poetry run \
python \
-m \
coverage report

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
Expand Down
32 changes: 0 additions & 32 deletions action-setup.sh

This file was deleted.

21 changes: 13 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ runs:
with:
python-version-file: ${{ github.action_path }}/.python-version

- name: Run the set up script
id: setup
- name: Install Poetry
shell: bash
run: |
# Group action setup log output
echo "::group::Action set up"
"${{ github.action_path }}/action-setup.sh"
echo "::endgroup::"
pipx install \
poetry==1.4.0

- name: Install Python Dependencies
shell: bash
working-directory: ${{ github.action_path }}
run: |
poetry install \
--only main

- name: Run script
shell: bash
Expand All @@ -77,6 +81,7 @@ runs:
INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }}
INPUT_ENABLE-WARNINGS-REPORT: ${{ inputs.enable-warnings-report }}
INPUT_SKETCHES-REPORT-PATH: ${{ inputs.sketches-report-path }}
working-directory: ${{ github.action_path }}
run: |
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
python "${{ github.action_path }}/compilesketches/compilesketches.py"
poetry run \
python "${{ github.action_path }}/compilesketches/compilesketches.py"
1 change: 0 additions & 1 deletion compilesketches/.flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[flake8]
doctests = True
extend-exclude = .venv
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
ignore = W503
max-complexity = 10
Expand Down
4 changes: 0 additions & 4 deletions compilesketches/requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions compilesketches/tests/.coveragerc

This file was deleted.

4 changes: 0 additions & 4 deletions compilesketches/tests/requirements.txt

This file was deleted.

Loading