Skip to content

Commit 0838eb9

Browse files
committed
Correct constraint extraction code for Python not installed error message
Some of the templates make use of Python packages. These dependencies are managed by the "Poetry" tool. The templates provide a task for automatically installing the project's managed version of Poetry. Python is required to install Poetry (and to use it after installation), so this is a prerequisite for project contributors using the template locally. In order to make the project infrastructure more friendly for contributors, instead of failing with a cryptic error if Python is not installed, the task starts by checking whether Python is installed, and if not displays a friendly error message explaining the need to install it. The project's standard Python version must later be available for use by Poetry, so it makes sense for the contributor to install that version of Python in this case, rather than installing an arbitrary version and then needing to install yet another copy later. For this reason, the task contains code to determine the version constraint for the Python dependency and include that information in the error message. Previously that code extracted the version constraint for Poetry instead of for Python as intended, resulting in incorrect information in the error message. The code is hereby corrected to get the correct data.
1 parent 1319758 commit 0838eb9

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

Taskfile.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -827,35 +827,29 @@ tasks:
827827
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
828828
-d "{{.INSTANCE_PATH}}"
829829
830-
# Print the version constraint for the project's Poetry tool dependency.
831830
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
832-
poetry:get-version:
831+
poetry:install:
832+
desc: Install Poetry
833+
run: once
833834
cmds:
834835
- |
835836
if ! which yq &>/dev/null; then
836837
echo "yq not found or not in PATH."
837838
echo "Please install: https://github.com/mikefarah/yq/#install"
838839
exit 1
839840
fi
840-
- |
841-
yq \
842-
--input-format toml \
843-
--output-format yaml \
844-
'.tool.poetry.group.pipx.dependencies.poetry' \
845-
< pyproject.toml
846-
847-
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
848-
poetry:install:
849-
desc: Install Poetry
850-
run: once
851-
vars:
852-
POETRY_VERSION:
853-
sh: task poetry:get-version
854-
cmds:
855841
- |
856842
if ! which python &>/dev/null; then
843+
python_constraint="$( \
844+
yq \
845+
--input-format toml \
846+
--output-format yaml \
847+
'.tool.poetry.dependencies.python' \
848+
< pyproject.toml
849+
)"
850+
857851
echo "Python not found or not in PATH."
858-
echo "Please install a version of Python meeting the constraint {{.POETRY_VERSION}}:"
852+
echo "Please install a version of Python satisfying the constraint ${python_constraint}:"
859853
echo "https://wiki.python.org/moin/BeginnersGuide/Download"
860854
exit 1
861855
fi
@@ -870,9 +864,18 @@ tasks:
870864
task utility:normalize-path \
871865
RAW_PATH="$(which python)" \
872866
)"
867+
868+
poetry_constraint="$( \
869+
yq \
870+
--input-format toml \
871+
--output-format yaml \
872+
'.tool.poetry.group.pipx.dependencies.poetry' \
873+
< pyproject.toml
874+
)"
875+
873876
pipx install \
874877
--force \
875-
"poetry=={{.POETRY_VERSION}}"
878+
"poetry==$poetry_constraint"
876879
877880
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
878881
poetry:install-deps:

workflow-templates/assets/poetry-task/Taskfile.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,29 @@
22
version: "3"
33

44
tasks:
5-
# Print the version constraint for the project's Poetry tool dependency.
65
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
7-
poetry:get-version:
6+
poetry:install:
7+
desc: Install Poetry
8+
run: once
89
cmds:
910
- |
1011
if ! which yq &>/dev/null; then
1112
echo "yq not found or not in PATH."
1213
echo "Please install: https://github.com/mikefarah/yq/#install"
1314
exit 1
1415
fi
15-
- |
16-
yq \
17-
--input-format toml \
18-
--output-format yaml \
19-
'.tool.poetry.group.pipx.dependencies.poetry' \
20-
< pyproject.toml
21-
22-
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
23-
poetry:install:
24-
desc: Install Poetry
25-
run: once
26-
vars:
27-
POETRY_VERSION:
28-
sh: task poetry:get-version
29-
cmds:
3016
- |
3117
if ! which python &>/dev/null; then
18+
python_constraint="$( \
19+
yq \
20+
--input-format toml \
21+
--output-format yaml \
22+
'.tool.poetry.dependencies.python' \
23+
< pyproject.toml
24+
)"
25+
3226
echo "Python not found or not in PATH."
33-
echo "Please install a version of Python meeting the constraint {{.POETRY_VERSION}}:"
27+
echo "Please install a version of Python satisfying the constraint ${python_constraint}:"
3428
echo "https://wiki.python.org/moin/BeginnersGuide/Download"
3529
exit 1
3630
fi
@@ -45,9 +39,18 @@ tasks:
4539
task utility:normalize-path \
4640
RAW_PATH="$(which python)" \
4741
)"
42+
43+
poetry_constraint="$( \
44+
yq \
45+
--input-format toml \
46+
--output-format yaml \
47+
'.tool.poetry.group.pipx.dependencies.poetry' \
48+
< pyproject.toml
49+
)"
50+
4851
pipx install \
4952
--force \
50-
"poetry=={{.POETRY_VERSION}}"
53+
"poetry==$poetry_constraint"
5154
5255
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
5356
poetry:install-deps:

0 commit comments

Comments
 (0)