Skip to content

Commit 87d8d1a

Browse files
authored
setup-python: Remove custom python-version output logic (#76)
* setup-python: Remove custom python-version output * tests: Update test_setup_python to validate env.pythonVersion * tests: Test both env.pythonVersion and outputs.python-version
1 parent 52892c0 commit 87d8d1a

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

.github/workflows/test_actions.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,51 @@ jobs:
1717
- name: Check out repo
1818
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1919
- name: Set up Python
20+
id: setup-python
2021
uses: ./setup-python
2122
with:
2223
python-version: ${{ matrix.python-version }}
2324
- name: Check Python version
2425
run: |
25-
import sys, sysconfig, re
26-
match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", "${{ matrix.python-version }}")
26+
import sys, sysconfig, re, os
27+
28+
matrix_python_version = "${{ matrix.python-version }}"
29+
output_python_version = "${{ steps.setup-python.outputs.python-version }}"
30+
31+
match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", matrix_python_version)
2732
expected_version = tuple(int(g) for g in match.groups() if g is not None)
2833
version = sys.version_info[:len(expected_version)]
2934
if version != expected_version:
3035
print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.")
3136
sys.exit(1)
37+
match = re.search(r"(\d+)\.(\d+)(?:\.(\d+))?", output_python_version)
38+
output_version = tuple(int(g) for g in match.groups() if g is not None)[:len(expected_version)]
39+
if output_version != expected_version:
40+
print(f"::error title=Test Failure::The outputs.python-version version does not match. Got {output_version}, expected {expected_version}.")
41+
sys.exit(1)
42+
3243
implementation = sys.implementation.name
33-
expected_implementation = "pypy" if "${{ matrix.python-version }}".startswith("pypy") else "cpython"
44+
expected_implementation = "pypy" if matrix_python_version.startswith("pypy") else "cpython"
3445
if implementation != expected_implementation:
3546
print(f"::error title=Test Failure::The Python implementation does not match. Got {implementation}, expected {expected_implementation}.")
3647
sys.exit(1)
48+
output_implementation = "pypy" if output_python_version.startswith("pypy") else "cpython"
49+
if output_implementation != expected_implementation:
50+
print(f"::error title=Test Failure::The outputs.python-version implementation does not match. Got {output_implementation}, expected {expected_implementation}.")
51+
3752
threading = "free-threading" if sysconfig.get_config_var("Py_GIL_DISABLED") else "GIL"
38-
expected_threading = "free-threading" if "t" in "${{ matrix.python-version }}" else "GIL"
53+
expected_threading = "free-threading" if "t" in matrix_python_version else "GIL"
3954
if threading != expected_threading:
4055
print(f"::error title=Test Failure::The Python threading does not match. Got {threading}, expected {expected_threading}.")
4156
sys.exit(1)
57+
output_threading = "free-threading" if "t" in output_python_version else "GIL"
58+
if output_threading != expected_threading:
59+
print(f"::error title=Test Failure::The outputs.python-version threading does not match. Got {output_threading}, expected {expected_threading}.")
60+
61+
env_python_version = os.environ["pythonVersion"]
62+
if env_python_version != output_python_version:
63+
print(f"::error title=Test Failure::env.pythonVersion does not match outputs.python-version. Got {env_python_version}, expected {output_python_version}.")
64+
sys.exit(1)
4265
shell: python
4366

4467
test_setup_poetry:

setup-python/action.yml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ outputs:
77
python-path:
88
value: ${{ steps.setup-python.outputs.python-path }}
99
python-version:
10-
value: ${{ steps.get-python-version.outputs.python-version }}
10+
value: ${{ steps.setup-python.outputs.python-version }}
1111
runs:
1212
using: composite
1313
steps:
@@ -16,22 +16,6 @@ runs:
1616
id: setup-python
1717
with:
1818
python-version: ${{ inputs.python-version }}
19-
# Workaround for https://github.com/actions/setup-python/issues/1109 -
20-
# Python-version output for PyPy isn't unique across different versions
21-
- name: Get Python version
22-
id: get-python-version
23-
run: |
24-
import os, platform, sys, sysconfig
25-
if sys.implementation.name == "pypy":
26-
version = f"pypy{platform.python_version()}-v{'.'.join(map(str,sys.implementation.version[:3]))}"
27-
else:
28-
version = platform.python_version()
29-
# Also take free-threading into account
30-
if sysconfig.get_config_var("Py_GIL_DISABLED"):
31-
version += "t"
32-
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
33-
print(f"python-version={version}", file=output)
34-
shell: python
3519
- name: Add pythonVersion environment variable
36-
run: echo "pythonVersion=${{ steps.get-python-version.outputs.python-version }}" >> "$GITHUB_ENV"
37-
shell: bash
20+
run: echo "pythonVersion=${{ steps.setup-python.outputs.python-version }}" >> "$GITHUB_ENV"
21+
shell: bash

0 commit comments

Comments
 (0)