actions / setup-python

Set up your GitHub Actions workflow with a specific version of Python
MIT License
1.59k stars 507 forks source link

Difference between env.pythonLocation on macOS in Python 3.11+ #813

Open adamjstewart opened 4 months ago

adamjstewart commented 4 months ago

Description:

I'm encountering a strange issue related to caching the Python installation. I'm using actions/setup-python@v5.0.0 to install Python, then actions/cache@v4.0.0 to cache the env.pythonLocation directory, similar to this blog.

This works fantastically, except on macOS in Python 3.11 and 3.12, and I have no idea why. For some reason, the cache is empty, but only for those specific versions. Did anything change in the installation layout or env.pythonLocation variable that could explain this?

Action version:

5.0.0

Platform:

Runner type:

Tools version:

Python 3.11, 3.12

Repro steps:

The full workflow can be seen here.

Expected behavior:

I would expect this to work for all platforms/Python versions and cache the installed Python packages.

Actual behavior:

The cache is empty. See https://github.com/actions/cache/issues/1176 for the cross-referenced bug report.

HarithaVattikuti commented 4 months ago

Hello @adamjstewart
Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.

aparnajyothi-y commented 4 months ago

Hello @adamjstewart, Thank you for creating this issue once again. We are able to reproduce the issue in our local and investigated further. In the actions/setup-python GitHub action, the env.pythonLocation variable is used to denote the directory where the Python, GraalPython, or PyPy binary is installed. After a successful setup, env.pythonLocation is set to the Python installation directory.env.pythonLocation is used consistently across different operating systems and Python versions, including Python 3.11+ on macOS. We are clear there is nothing changed from the functionality of env.pythonLocation for Python 3.11+ on macOS. There could be change from the python version or from the mac os. Continuing the investigation to find the exact root cause. We will update you once we found the root cause. Please feel free to reach us, in case of any concerns on the above information :)

aparnajyothi-y commented 4 months ago

Hello @adamjstewart, We have investigated furthermore on this and found that there is difference in building installation packages before and after python 3.11 in actions/python-versions which setup-python uses to build the packages. The main difference between the processes are: For Python < 3.11:

  1. The action downloads the official Python sources from python.org.
  2. It builds the downloaded source using the make tool.
  3. The built version is archived together with the installation script for further distribution and installation.
  4. Each Python version is built against the oldest version of macOS available at the time the Python version is released. This is done for backward compatibility.

For Python >= 3.11:

  1. The action directly downloads the official macOS universal2 Python binaries from python.org, skipping the build process.
  2. The downloaded binary is archived together with the installation script for further distribution and installation.
  3. In summary, the building step from the source is skipped for Python >= 3.11, and instead, prebuilt binaries are used. Please feel free to reach us, in case of any other clarification is needed.
adamjstewart commented 4 months ago

@aparnajyothi-y Does actions/python-versions define env.pythonLocation or does actions/setup-python? It sounds like we just need to set this variable differently for macOS and Python 3.11+.

aparnajyothi-y commented 3 months ago

Hello @adamjstewart, actions/setup-python defines env.pythonLocation and the functionality is to contains the absolute path to the folder where the requested version of Python or PyPy is installed.Python Building installation packages depends on the python source build process.

Please react out us incase of any other concerns :)

adamjstewart commented 3 months ago

Great, so then this is a bug in how actions/setup-python sets env.pythonLocation? And all we need to do is fix that bug and then env.pythonLocation will point to the correct directory? Let me know if there's anything I can do to help fix this bug.

aparnajyothi-y commented 3 months ago

Hi @adamjstewart, The environment variable 'env.pythonLocation' is utilized by the 'actions/setup-python' action to indicate the installation location of the desired Python or PyPy version. This helps subsequent workflow steps to find and use the Python executable. Regarding Python 3.11+, there is no modification in the usage of 'env.pythonLocation'. It continues to reference the Python interpreter's installation location. Any new features or alterations in Python 3.11+ would pertain to the Python build process itself, not directly to the 'env.pythonLocation' variable or the 'actions/setup-python' action. Therefore, we cannot implement any fixes related to 'env.pythonLocation' for Python 3.11+ versions. Please reach out if you need any more clarification.

adamjstewart commented 3 months ago

The directory indicated by env.pythonLocation on macOS for Python 3.11+ contains ~0 MB (534 B) of data, even after installing hundreds of packages. I find it hard to believe that this directory is indeed correct.

aparnajyothi-y commented 2 months ago

Hello @adamjstewart, We have further investigated the env.pythonLocation functionality and it is pointing to the installation location of the desired Python or PyPy version. The directory indicated by env.pythonLocation on macOS for Python 3.11+ contains ~0 MB (534 B) of data is due to the changes in the official python build process itself and no changes from setup-python. In case of any updates needed as part of env.pythonLocation to get the actual cache size, that can be considered as part of a feature request in future. Please let us know in case any further clarifications needed. Thank you.

adamjstewart commented 2 months ago

it is pointing to the installation location of the desired Python or PyPy version

It is pointing to an empty directory.

changes in the official python build process itself and no changes from setup-python

It seems like the solution would be to change setup-python so that it correctly handles this new build process?

In case of any updates needed as part of env.pythonLocation to get the actual cache size, that can be considered as part of a feature request in future

In that case, I would like to request a feature that points to the installation directory of Python. env.pythonLocation might be a good name to call it.

adamjstewart commented 2 months ago

Since the switch from macos-13 (x86_64) to macos-14 (arm64) this week, I'm not seeing this bug in Python 3.10 as well: https://github.com/microsoft/torchgeo/actions/runs/8837018251/job/24264909202?pr=2023.