setup-python icon indicating copy to clipboard operation
setup-python copied to clipboard

The action fails if the `.python-version` (passed into `python-version-file` input) contains a comment

Open nitrocode opened this issue 1 year ago • 3 comments

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

nitrocode avatar Sep 22 '24 17:09 nitrocode

Hello @nitrocode 👋, Thank you for reporting this issue. We will investigate it and get back to you as soon as we have some feedback.

priya-kinthali avatar Sep 23 '24 04:09 priya-kinthali

The same issue occurs if multiple versions of python are specified in the .python-version file.

olivierlefloch avatar Sep 26 '24 19:09 olivierlefloch

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!

priya-kinthali avatar Sep 27 '24 05:09 priya-kinthali

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.

lmvysakh avatar May 23 '25 03:05 lmvysakh

Thank you very much!

nitrocode avatar May 26 '25 04:05 nitrocode