Skip to content

Commit 5da9ace

Browse files
committed
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 project.toml file.
1 parent cda2ca4 commit 5da9ace

7 files changed

+1440
-31
lines changed

.github/workflows/check-poetry-task.yml

-6
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ jobs:
6565
with:
6666
python-version: ${{ env.PYTHON_VERSION }}
6767

68-
- name: Install Poetry
69-
run: pip install poetry
70-
7168
- name: Install Task
7269
uses: arduino/setup-task@v2
7370
with:
@@ -93,9 +90,6 @@ jobs:
9390
with:
9491
python-version: ${{ env.PYTHON_VERSION }}
9592

96-
- name: Install Poetry
97-
run: pip install poetry
98-
9993
- name: Install Task
10094
uses: arduino/setup-task@v2
10195
with:

.github/workflows/check-python-task.yml

-9
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ jobs:
7979
with:
8080
python-version: ${{ env.PYTHON_VERSION }}
8181

82-
- name: Install Poetry
83-
run: pip install poetry
84-
8582
- name: Install Task
8683
uses: arduino/setup-task@v2
8784
with:
@@ -110,9 +107,6 @@ jobs:
110107
with:
111108
python-version: ${{ env.PYTHON_VERSION }}
112109

113-
- name: Install Poetry
114-
run: pip install poetry
115-
116110
- name: Install Task
117111
uses: arduino/setup-task@v2
118112
with:
@@ -141,9 +135,6 @@ jobs:
141135
with:
142136
python-version: ${{ env.PYTHON_VERSION }}
143137

144-
- name: Install Poetry
145-
run: pip install poetry
146-
147138
- name: Install Task
148139
uses: arduino/setup-task@v2
149140
with:

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

-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ jobs:
5757
with:
5858
python-version: ${{ env.PYTHON_VERSION }}
5959

60-
- name: Install Poetry
61-
run: pip install poetry
62-
6360
- name: Install Task
6461
uses: arduino/setup-task@v2
6562
with:

.github/workflows/test-python-poetry-task.yml

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ jobs:
8181
with:
8282
python-version: ${{ env.PYTHON_VERSION }}
8383

84-
- name: Install Poetry
85-
run: pip install poetry
86-
8784
- name: Install Task
8885
uses: arduino/setup-task@v2
8986
with:

Taskfile.yml

+37
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,49 @@ tasks:
208208
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
209209
-d "{{.PROJECT_FOLDER}}/{{.INSTANCE_PATH}}"
210210
211+
poetry:install:
212+
desc: Install Poetry
213+
run: once
214+
cmds:
215+
- |
216+
if ! which pipx &>/dev/null; then
217+
echo "pipx not found or not in PATH."
218+
echo "Please install: https://pipx.pypa.io/stable/installation/#installing-pipx"
219+
exit 1
220+
fi
221+
- |
222+
if ! which yq &>/dev/null; then
223+
echo "yq not found or not in PATH."
224+
echo "Please install: https://github.com/mikefarah/yq/#install"
225+
exit 1
226+
fi
227+
- |
228+
export PIPX_DEFAULT_PYTHON="$( \
229+
task utility:normalize-path \
230+
RAW_PATH="$(which python)" \
231+
)"
232+
pipx install \
233+
--force \
234+
"poetry==$( \
235+
yq \
236+
--input-format toml \
237+
--output-format yaml \
238+
'.tool.poetry.group.pipx.dependencies.poetry' \
239+
< pyproject.toml
240+
)"
241+
211242
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
212243
poetry:install-deps:
213244
desc: Install dependencies managed by Poetry
245+
deps:
246+
- task: poetry:install
214247
cmds:
215248
- poetry install --no-root
216249

217250
poetry:sync:
218251
desc: Sync poetry.lock
252+
deps:
253+
- task: poetry:install
219254
cmds:
220255
- |
221256
poetry \
@@ -224,6 +259,8 @@ tasks:
224259
225260
poetry:validate:
226261
desc: Validate pyproject.toml
262+
deps:
263+
- task: poetry:install
227264
cmds:
228265
- |
229266
poetry \

poetry.lock

+1,395-10
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
@@ -20,6 +20,14 @@ pytest = "7.4.3"
2020
pytest-mock = "3.12.0"
2121
mypy = "1.7.1"
2222

23+
# The dependencies in this group are installed using pipx; NOT Poetry. The use of a `poetry` section is a hack required
24+
# in order to be able to manage updates of these dependencies via Dependabot, as used for all other dependencies.
25+
[tool.poetry.group.pipx]
26+
optional = true
27+
28+
[tool.poetry.group.pipx.dependencies]
29+
poetry = "2.1.1"
30+
2331
[build-system]
2432
requires = ["poetry-core"]
2533
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)