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

Identify all installed Python versions

Open kurtmckee opened this issue 2 years ago • 3 comments

Description:

I'd like trivially use all of the installed Python versions (in full) in my cache keys (like "3.8.16" and "3.9.16 (PyPy 7.3.11)").

This could be implemented in several ways, including:

  • A python-versions (plural!) output that includes the full Python versions in full. (How it's delimited doesn't matter to me due to my use case.) For example, 3.8.10; 3.9.13; 3.9.16 (PyPy 7.3.11).
  • A file written at a known or configurable location that lists all of the install Python versions.

Justification:

I'm very pleased with the new ability to install multiple Python versions simultaneously! This pairs well with tox-based testing.

I'm wanting to cache and restore my .tox/ directories between runs, particularly on Windows hosts, because it's expensive to set up the tox environments for each Python version. In the past, with only one Python version installed, I would use the action output, python-version, as a part of the cache key.

However, when multiple versions are installed, if there is a cache hit but one of the Python versions that isn't the default has updated (say, if "3.11" is the default but "3.8" updates from "3.8.10" to "3.8.11") then tox will rebuild the 3.8 environment each time the cache is restored, the cache won't be invalidated, and test setup times will start to increase.

I don't know of a trivial, cross-platform way to write this myself that will work consistently as new Python versions and host platforms are added (like Pyston, as I saw in another ticket)...but I'd prefer to avoid crawling the filesystem and executing python -V on every executable that looks like a Python interpreter.

Therefore, I think that outputting this metadata from within the setup-python action would be the most ideal scenario.

Are you willing to submit a PR?

I'd love to try! I don't know TypeScript and it might take a bit to write something that fits the requirements and runs correctly.

I'll take a look at what that might look like (particularly by studying the existing python-version output) while awaiting feedback for this idea.

kurtmckee avatar Feb 10 '23 03:02 kurtmckee

I've attempted to implement this. So far in my testing I'm not getting the additional python-versions output. I'm not sure what I'm doing wrong, but if someone could take a look, I'd like to get this ship-shape so I can submit a PR for this!

https://github.com/actions/setup-python/compare/main...kurtmckee:setup-python:output-python-versions

kurtmckee avatar Feb 10 '23 04:02 kurtmckee

Hello @kurtmckee! We will investigate the issue and get back to you.

e-korolevskii avatar Feb 10 '23 09:02 e-korolevskii

Hmm...it may be that I need to run ncc to build the project before it will run the new code. I'm having trouble doing that on Windows (I'm getting errors that paths containing backslashes and forward slashes don't exist, but they do if I manually normalize the paths), so I'll try building and testing the changes on Linux today.

kurtmckee avatar Feb 10 '23 14:02 kurtmckee

Closing this.

For any others finding this: I wrote https://github.com/kurtmckee/detect-pythons to address this need, since #611 didn't get reviewed/merged.

kurtmckee avatar May 13 '24 15:05 kurtmckee