{"id":16904462,"url":"https://github.com/kurtmckee/detect-pythons","last_synced_at":"2025-09-10T21:09:00.208Z","repository":{"id":196772087,"uuid":"693213720","full_name":"kurtmckee/detect-pythons","owner":"kurtmckee","description":"A GitHub action to detect installed Pythons. Excellent for cache-busting.","archived":false,"fork":false,"pushed_at":"2025-04-07T21:22:57.000Z","size":167,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T13:13:23.014Z","etag":null,"topics":["cache-busting","github-actions","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kurtmckee.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":".github/FUNDING.yaml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"kurtmckee","ko_fi":"kurtmckee"}},"created_at":"2023-09-18T15:15:46.000Z","updated_at":"2025-03-07T14:10:41.000Z","dependencies_parsed_at":"2023-09-27T13:22:58.931Z","dependency_job_id":"398e2bfd-a1ce-4403-a0f1-43d7c0463313","html_url":"https://github.com/kurtmckee/detect-pythons","commit_stats":null,"previous_names":["kurtmckee/setup-python-version-detector","kurtmckee/detect-pythons"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurtmckee%2Fdetect-pythons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurtmckee%2Fdetect-pythons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurtmckee%2Fdetect-pythons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurtmckee%2Fdetect-pythons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kurtmckee","download_url":"https://codeload.github.com/kurtmckee/detect-pythons/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571863,"owners_count":21126522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache-busting","github-actions","python"],"created_at":"2024-10-13T18:33:29.758Z","updated_at":"2025-04-12T13:13:28.127Z","avatar_url":"https://github.com/kurtmckee.png","language":"Python","funding_links":["https://github.com/sponsors/kurtmckee","https://ko-fi.com/kurtmckee"],"categories":[],"sub_categories":[],"readme":"..\n    This file is a part of the detect-pythons project.\n    https://github.com/kurtmckee/detect-pythons\n    Copyright 2023-2025 Kurt McKee \u003ccontactme@kurtmckee.org\u003e\n    SPDX-License-Identifier: MIT\n\nDetect Python interpreters\n##########################\n\n*Robust cache-busting based on Python implementations, versions, and architectures.*\n\n----\n\nPurpose\n=======\n\nIf you're caching Python virtual environments to speed up your CI runs,\nyou've likely encountered broken symlinks or missing libraries\nwhen a new Python patch version was released.\nThis is particularly likely to happen\nwhen using tox to test multiple Python versions simultaneously.\n\n``detect-pythons`` provides that much-needed cache busting.\n\nIt detects all Python executables in every directory on the ``$PATH``\nand identifies:\n\n*   The Python interpreter (like CPython, PyPy, or GraalPy)\n*   The Python version (like \"3.12.1\")\n    or the Python ABI version (like \"3.12\")\n*   The target architecture (like \"x64\")\n\nIn most cases, the path to the executable already contains this information\nso it's not necessary to run the Python interpreter to extract any info.\nThat makes ``detect-pythons`` *fast*.\n\nThere are some exceptions, however;\nthese are covered in the \"Implementation\" section below.\n\n\nUsage\n=====\n\nThe following example demonstrates how ``detect-pythons`` can be used\nwhen caching a Python virtual environment stored in ``.venv/``\nand tox test environments stored in ``.tox/``.\n\n\n..  START_README_EXAMPLE_BLOCK\n..  code-block:: yaml\n\n    - uses: \"actions/setup-python@v5\"\n      with:\n        python-version: |\n          graalpy-24\n          pypy-3.11\n          3.13\n\n    - uses: \"kurtmckee/detect-pythons@v1\"\n\n    - uses: \"actions/cache@v4\"\n      id: \"restore-cache\"\n      with:\n        # You may need to augment the list of files to hash.\n        # For example, you might add 'requirements/*.txt' or 'pyproject.toml'.\n        key: \"${{ hashFiles('.python-identifiers') }}\"\n        path: |\n          .tox/\n          .venv/\n\n    - name: \"Identify .venv path\"\n      shell: \"bash\"\n      run: |\n        echo 'venv-path=.venv/${{ runner.os == 'Windows' \u0026\u0026 'Scripts' || 'bin' }}' \u003e\u003e \"$GITHUB_ENV\"\n\n    - name: \"Create a virtual environment\"\n      if: \"steps.restore-cache.outputs.cache-hit == false\"\n      run: |\n        python -m venv .venv\n        ${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel\n\n        # You may need to customize what gets installed next.\n        # However, tox is able to run test suites against multiple Pythons,\n        # so it's a helpful tool for efficient testing.\n        ${{ env.venv-path }}/pip install tox\n\n    - name: \"Run the test suite against all installed Pythons\"\n      run: \"${{ env.venv-path }}/tox\"\n..  END_README_EXAMPLE_BLOCK\n\n\nInputs\n======\n\nBy default, the action writes to a file named ``.python-identifiers``,\nwhich can then be passed to GitHub's ``hashFiles`` function\nfor convenient cache-busting.\n\nYou can customize the path and filename\nby modifying the input variable ``identifiers-filename``:\n\n..  code-block:: yaml\n\n    - uses: \"kurtmckee/detect-pythons@v1\"\n      with:\n        identifiers-filename: \"favored_filename.txt\"\n\nTo prevent writing a file at all,\nset ``identifiers-filename`` to an empty string:\n\n..  code-block:: yaml\n\n    - uses: \"kurtmckee/detect-pythons@v1\"\n      with:\n        identifiers-filename: \"\"\n\n\nOutputs\n=======\n\nIn addition to writing to a file,\nthe action creates an output named ``python-identifiers``.\nThis may be useful in other contexts.\n\n\nImplementation\n==============\n\n``detect-pythons`` finds all Python interpreters available on the ``$PATH``\nand ensures that critical information about each interpreter is included\nin its output:\n\n*   Implementation\n*   Version\n*   Architecture\n\n\nCached Python interpreters\n--------------------------\n\nGitHub runners have common CPython and PyPy versions pre-installed.\nThese are installed under ``$RUNNER_TOOL_CACHE`` in informative directory paths,\nso the paths are used without executing the interpreters.\n\n..  csv-table::\n    :header: \"Platform\", \"Sample path under ``$RUNNER_TOOL_CACHE``\"\n\n    \"Linux\", \"``/opt/hostedtoolcache/Python/3.12.1/x64/bin``\"\n    \"macOS\", \"``/Users/runner/hostedtoolcache/PyPy/3.10.13/x64/bin``\"\n    \"Windows\", \"``C:\\hostedtoolcache\\windows\\Python\\3.12.1\\x64``\"\n\n\nSystem CPython interpreters\n---------------------------\n\nGitHub's Linux and macOS runners have system CPython interpreters installed.\nThese are available at paths which contain no useful information,\nlike ``/usr/bin/python``.\n\nFor these interpreters, the interpreter is executed\nand the value of ``sysconfig.get_config_var(\"EXT_SUFFIX\")`` is extracted.\nThis results in a value like the following:\n\n..  csv-table::\n    :header: \"Platform\", \"Sample ``EXT_SUFFIX`` value\"\n\n    \"Linux\", \"``.cpython-310-x86_64-linux-gnu.so``\"\n    \"macOS\", \"``.cpython-311-darwin.so``\"\n\nExtremely old Python versions might not have an ``EXT_SUFFIX`` value.\nFor example, CPython 2.7 doesn't have this value.\nIf this is detected then an equivalent value is constructed.\n\n..  csv-table::\n    :header: \"Platform\", \"Constructed ``EXT_SUFFIX`` equivalent\"\n\n    \"macOS\", \"``.cpython-27-darwin-x86_64``\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkurtmckee%2Fdetect-pythons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkurtmckee%2Fdetect-pythons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkurtmckee%2Fdetect-pythons/lists"}