The action fails if the `.python-version` (passed into `python-version-file` input) contains a comment
Description: The workflow
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
The .python-version file
# This file is read by the terraform if var.runtime is unset
3.11
The error
Version # This file is read by the terraform if var.runtime is unset
3.11 was not found in the local cache
Error: The version '# This file is read by the terraform if var.runtime is unset
3.11' with architecture 'x64' was not found for Ubuntu 22.04.
The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
Action version: Latest v5
Platform:
- [x] Ubuntu
- [ ] macOS
- [ ] Windows
Runner type:
- [x] Hosted
- [ ] Self-hosted
Tools version:
Repro steps:
See above
Expected behavior: Ignores the comments and only grabs the version
Actual behavior: It doesn't ignore the comments
Hello @nitrocode 👋, Thank you for reporting this issue. We will investigate it and get back to you as soon as we have some feedback.
The same issue occurs if multiple versions of python are specified in the .python-version file.
Hello 👋,
@nitrocode , The setup-python action does not currently support comments within the .python-version file, which is causing the error you encountered. We appreciate you bringing this to our attention and will consider incorporating comment support in future enhancements. In the meantime, please ensure that the .python-version file contains only the version number without any comments.
@olivierlefloch , Regarding specifying multiple versions in the .python-version file, there is an existing feature request to support listing multiple versions. We will consider this for future updates.
Thank you both for your inputs and helping us improve the setup-python action!
Thank you for bringing up this feature request and outlining the scenario involving comments within the .python-version file. We are pleased to inform you that the relevant features and improvements have been implemented as part of PR #787. With this update, the action now properly ignores comment lines in the version file, ensuring only valid Python versions are processed.
As this feature request is now addressed, we are closing this issue. If you encounter any further issues or have additional suggestions, please feel free to open a new issue.
Thank you very much!