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

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

Open
2 of 5 tasks
adamjstewart opened this issue Feb 6, 2024 · 11 comments
Open
2 of 5 tasks

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

adamjstewart opened this issue Feb 6, 2024 · 11 comments
Labels
feature request New feature or request to improve the current logic

Comments

@adamjstewart
Copy link
Contributor

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:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

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 actions/cache#1176 for the cross-referenced bug report.

@HarithaVattikuti
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

aparnajyothi-y commented Feb 21, 2024

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
Copy link
Contributor Author

@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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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.

@aparnajyothi-y aparnajyothi-y added the feature request New feature or request to improve the current logic label Apr 19, 2024
@aparnajyothi-y aparnajyothi-y removed their assignment Apr 19, 2024
@aparnajyothi-y aparnajyothi-y removed the bug Something isn't working label Apr 19, 2024
@adamjstewart
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

3 participants