Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 03636cb

Browse files
committedMar 16, 2025·
Manage versioning of Poetry tool dependency
The project's Python package dependencies are managed by the Poetry tool. Previously, the version of Poetry was not managed in any way. The GitHub Actions workflows used whichever version of Poetry happened to be installed on the runner machine. This meant that the GitHub Actions workflows could break at any time through the poetry installation on the runner machine being updated to an incompatible version. The contributors used whichever version of Poetry happened to be installed on their machine. This meant that they might get different results from that produced by the environment of the GitHub Actions workflows. The better solution is to take the same approach for managing the Poetry dependency as done for the project's other dependencies: * Install a specific version of Poetry according to a single source of versioning data. * Use the Dependabot service to get automated update pull requests. The logical place to define the Poetry package dependency version is in pyproject.toml, as is done for all direct Python package dependencies. Dependabot recognizes two forms of dependency data in the pyproject.toml file: * Poetry * PEP 621 Since Poetry can't be used to manage itself, the obvious approach would be to define the Poetry dependency in a PEP 621 field in the file. However, this is not possible because if Dependabot finds Poetry data in pyproject.toml, it ignores the PEP 621 fields. So it is necessary to define the Poetry dependency in the Poetry fields of the file. A special dependencies group is created for this purpose. That group is configured as "optional" so that it won't be installed redundantly by `poetry install` commands. Unfortunately pipx doesn't support using pyproject.toml as a dependency configuration file so it is necessary to generate the dependency argument in the pipx command by parsing the contents of the project.toml file.
1 parent deec84b commit 03636cb

File tree

5 files changed

+1535
-15
lines changed

5 files changed

+1535
-15
lines changed
 

‎.github/workflows/check-yaml-task.yml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-yaml-task.md
22
name: Check YAML
33

4-
env:
5-
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
6-
PYTHON_VERSION: "3.9"
7-
84
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
95
on:
106
create:
@@ -103,9 +99,6 @@ jobs:
10399
with:
104100
python-version-file: pyproject.toml
105101

106-
- name: Install Poetry
107-
run: pip install poetry
108-
109102
- name: Install Task
110103
uses: arduino/setup-task@v2
111104
with:

‎.github/workflows/spell-check-task.yml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/spell-check-task.md
22
name: Spell Check
33

4-
env:
5-
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
6-
PYTHON_VERSION: "3.9"
7-
84
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
95
on:
106
create:
@@ -57,9 +53,6 @@ jobs:
5753
with:
5854
python-version-file: pyproject.toml
5955

60-
- name: Install Poetry
61-
run: pip install poetry
62-
6356
- name: Install Task
6457
uses: arduino/setup-task@v2
6558
with:

‎Taskfile.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,42 @@ tasks:
347347
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
348348
-d "{{.INSTANCE_PATH}}"
349349
350+
poetry:install:
351+
desc: Install Poetry
352+
run: once
353+
cmds:
354+
- |
355+
if ! which pipx &>/dev/null; then
356+
echo "pipx not found or not in PATH."
357+
echo "Please install: https://pipx.pypa.io/stable/installation/#installing-pipx"
358+
exit 1
359+
fi
360+
- |
361+
if ! which yq &>/dev/null; then
362+
echo "yq not found or not in PATH."
363+
echo "Please install: https://github.com/mikefarah/yq/#install"
364+
exit 1
365+
fi
366+
- |
367+
export PIPX_DEFAULT_PYTHON="$( \
368+
task utility:normalize-path \
369+
RAW_PATH="$(which python)" \
370+
)"
371+
pipx install \
372+
--force \
373+
"poetry==$( \
374+
yq \
375+
--input-format toml \
376+
--output-format yaml \
377+
'.tool.poetry.group.pipx.dependencies.poetry' \
378+
< pyproject.toml
379+
)"
380+
350381
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
351382
poetry:install-deps:
352383
desc: Install dependencies managed by Poetry
384+
deps:
385+
- task: poetry:install
353386
cmds:
354387
- poetry install --no-root
355388

‎poetry.lock‎

Lines changed: 1494 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ python = "~3.9"
1111
yamllint = "^1.36.0"
1212
codespell = "^2.4.1"
1313

14+
# The dependencies in this group are installed using pipx; NOT Poetry. The use of a `poetry` section is a hack required
15+
# in order to be able to manage updates of these dependencies via Dependabot, as used for all other dependencies.
16+
[tool.poetry.group.pipx]
17+
optional = true
18+
19+
[tool.poetry.group.pipx.dependencies]
20+
poetry = "2.1.1"
21+
1422
[build-system]
1523
requires = ["poetry-core>=1.0.0"]
1624
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)
Please sign in to comment.