Skip to content

Commit e5f98c3

Browse files
committed
Use Dependabot to manage Poetry version
The project's Python package dependencies are managed by the Poetry tool. Previously, the version of Poetry was managed in two inconsistent and sub-ideal ways: * The version used during execution of the action was hardcoded in the action metadata file. * The version used locally by contributors and by the GitHub Actions workflows was not managed at all. The first is problematic because there is no mechanism to facilitate updates, which means it will never be updated. The second is problematic because some versions might be incompatible, or produce different results than the version used by the action. 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 fdda776 commit e5f98c3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Taskfile.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,22 @@ tasks:
394394
echo "Please install: https://pipx.pypa.io/stable/installation/#installing-pipx"
395395
exit 1
396396
fi
397+
- |
398+
if ! which yq &>/dev/null; then
399+
echo "yq not found or not in PATH."
400+
echo "Please install: https://github.com/mikefarah/yq/#install"
401+
exit 1
402+
fi
397403
- |
398404
pipx install \
399405
--python "{{.PYTHON_PATH}}" \
400-
poetry
406+
"poetry==$( \
407+
yq \
408+
--input-format toml \
409+
--output-format yaml \
410+
'.tool.poetry.group.pipx.dependencies.poetry' \
411+
< pyproject.toml
412+
)"
401413
402414
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
403415
poetry:install-deps:

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ runs:
8787
# Install Poetry.
8888
pipx install \
8989
--python "$(which python)" \
90-
poetry==1.4.0
90+
"poetry==$( \
91+
yq \
92+
--input-format toml \
93+
--output-format yaml \
94+
'.tool.poetry.group.pipx.dependencies.poetry' \
95+
< pyproject.toml
96+
)"
9197
9298
# Install Python dependencies.
9399
poetry install \

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ optional = true
3232
[tool.poetry.group.external.dependencies]
3333
pyserial = "3.5"
3434

35+
# The dependencies in this group are installed using pipx; NOT Poetry. The use of a `poetry` section is a hack required
36+
# in order to be able to manage updates of these dependencies via Dependabot, as used for all other dependencies.
37+
[tool.poetry.group.pipx]
38+
optional = true
39+
40+
[tool.poetry.group.pipx.dependencies]
41+
poetry = "1.4.0"
42+
3543
[build-system]
3644
requires = ["poetry-core"]
3745
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)