Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyproject.toml as Python version source #799

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Oct 16, 2024

Python and Python-based tools are used in the development and maintenance of the project. A standardized version of Python is used for these operations.

Poetry is used for Python package dependencies management. Poetry installs dependencies into a virtual environment. For this reason, the Poetry configuration includes a Python version number, which must match the correct version of Python for the project. This configuration is stored in the pyproject.toml file.

Python is installed in the GitHub Actions runner environments using the actions/setup-python action, which also must be configured to install the correct version of Python. Previously the version number for use by the actions/setup-python action was defined in each workflow. This meant that we had multiple copies of the Python version information, all of which had to be kept in sync.

Fortunately, support for using pyproject.toml as the source of version information for the actions/setup-python action was recently added (actions/setup-python@0d5da6a). This means it is now possible for all components of the project infrastructure to get the Python version from a single source.

Previously the configuration in the pyproject.toml file only pinned the major version number of Python. Although in
theory a strict adherence to SemVer would ensure that this was no problem, in practice changes that are breaking for our
usage have been introduced in minor version bumps of Python. So for the stability of the project infrastructure we will
now pin to the minor version. The hope is that leaving the patch version number unpinned will allow some flexibility to
contributors in regards to which version they must have installed locally while not resulting in instability.
Python and Python-based tools are used in the development and maintenance of the project. A standardized version of
Python is used for these operations.

Poetry is used for Python package dependencies management. Poetry installs dependencies into a virtual environment. For
this reason, the Poetry configuration includes a Python version number, which must match the correct version of Python
for the project. This configuration is stored in the `pyproject.toml` file.

Python is installed in the GitHub Actions runner environments using the "actions/setup-python" action, which also must
be configured to install the correct version of Python. Previously the version number for use by the actions/setup-python
action was defined in each workflow. This meant that we had multiple copies of the Python version information, all of
which had to be kept in sync.

Fortunately, support for using `pyproject.toml` as the source of version information for the "actions/setup-python"
action was recently added. This means it is now possible for all components of the project infrastructure to get the
Python version from a single source.
This does the same as setting `core.autocrlf=false` via `git config` or a Git configuration file, but in a manner that
allows that configuration to be distributed, rather than each contributor having their own settings.

The immediate motivation for adding this file is as a workaround for a bug in the "actions/setup-python" action which
causes it to fail spuriously when pyproject.toml is used as the Python versioning source and that file has CRLF line
endings:

```text
Error: Control characters (codes < 0x1f and 0x7f) are not allowed in comments, use \u000d instead at row 10, col 34, pos 211:
 9:
10> # Integration tests dependencies.
                                     ^
11: invoke = "^2.2.0"
```

The GitHub Actions Windows runners hosted by GitHub have `core.autocrlf=false` in their Git configuration, which causes
the "actions/checkout" action step in a workflow to convert the repo's LF line endings to CRLF if the workflow runs on a
Windows runner.

A fix for the "actions/setup-python" action bug has already been made, so this would no longer be a problem once the
next release of the action comes out. However, the conversion of line endings by Git is utterly pointless because any
tool suitable for development work will have absolutely no problem working with LF line endings. The files in the
project have the line endings they do for a reason and Git should not ever modify them. So the addition of this file has
the ongoing benefit of ensuring Git won't be configured for the annoying and potentially harmful line ending conversion
on the contributor's machine.
@per1234 per1234 added type: enhancement Proposed improvement topic: infrastructure Related to project infrastructure labels Oct 16, 2024
@per1234 per1234 self-assigned this Oct 16, 2024
@per1234 per1234 merged commit 209c464 into arduino:main Oct 16, 2024
17 checks passed
@per1234 per1234 deleted the pyproject_toml-versioning branch October 16, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant