Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions .github/workflows/test_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,51 @@ jobs:
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
id: setup-python
uses: ./setup-python
with:
python-version: ${{ matrix.python-version }}
- name: Check Python version
run: |
import sys, sysconfig, re
match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", "${{ matrix.python-version }}")
import sys, sysconfig, re, os

matrix_python_version = "${{ matrix.python-version }}"
output_python_version = "${{ steps.setup-python.outputs.python-version }}"

match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", matrix_python_version)
expected_version = tuple(int(g) for g in match.groups() if g is not None)
version = sys.version_info[:len(expected_version)]
if version != expected_version:
print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.")
sys.exit(1)
match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", output_python_version)
output_version = tuple(int(g) for g in match.groups() if g is not None)[:len(expected_version)]
if output_version != expected_version:
print(f"::error title=Test Failure::The outputs.python-version version does not match. Got {output_version}, expected {expected_version}.")
sys.exit(1)

implementation = sys.implementation.name
expected_implementation = "pypy" if "${{ matrix.python-version }}".startswith("pypy") else "cpython"
expected_implementation = "pypy" if matrix_python_version.startswith("pypy") else "cpython"
if implementation != expected_implementation:
print(f"::error title=Test Failure::The Python implementation does not match. Got {implementation}, expected {expected_implementation}.")
sys.exit(1)
output_implementation = "pypy" if output_python_version.startswith("pypy") else "cpython"
if output_implementation != expected_implementation:
print(f"::error title=Test Failure::The outputs.python-version implementation does not match. Got {output_implementation}, expected {expected_implementation}.")

threading = "free-threading" if sysconfig.get_config_var("Py_GIL_DISABLED") else "GIL"
expected_threading = "free-threading" if "t" in "${{ matrix.python-version }}" else "GIL"
expected_threading = "free-threading" if "t" in matrix_python_version else "GIL"
if threading != expected_threading:
print(f"::error title=Test Failure::The Python threading does not match. Got {threading}, expected {expected_threading}.")
sys.exit(1)
output_threading = "free-threading" if "t" in output_python_version else "GIL"
if output_threading != expected_threading:
print(f"::error title=Test Failure::The outputs.python-version threading does not match. Got {output_threading}, expected {expected_threading}.")

env_python_version = os.environ["pythonVersion"]
if env_python_version != output_python_version:
print(f"::error title=Test Failure::env.pythonVersion does not match outputs.python-version. Got {env_python_version}, expected {output_python_version}.")
sys.exit(1)
shell: python

test_setup_poetry:
Expand Down
22 changes: 3 additions & 19 deletions setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ outputs:
python-path:
value: ${{ steps.setup-python.outputs.python-path }}
python-version:
value: ${{ steps.get-python-version.outputs.python-version }}
value: ${{ steps.setup-python.outputs.python-version }}
runs:
using: composite
steps:
Expand All @@ -16,22 +16,6 @@ runs:
id: setup-python
with:
python-version: ${{ inputs.python-version }}
# Workaround for https://github.com/actions/setup-python/issues/1109 -
# Python-version output for PyPy isn't unique across different versions
- name: Get Python version
id: get-python-version
run: |
import os, platform, sys, sysconfig
if sys.implementation.name == "pypy":
version = f"pypy{platform.python_version()}-v{'.'.join(map(str,sys.implementation.version[:3]))}"
else:
version = platform.python_version()
# Also take free-threading into account
if sysconfig.get_config_var("Py_GIL_DISABLED"):
version += "t"
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
print(f"python-version={version}", file=output)
shell: python
- name: Add pythonVersion environment variable
run: echo "pythonVersion=${{ steps.get-python-version.outputs.python-version }}" >> "$GITHUB_ENV"
shell: bash
run: echo "pythonVersion=${{ steps.setup-python.outputs.python-version }}" >> "$GITHUB_ENV"
shell: bash
Loading