From 4d735c484f87cd2d3b4c7cbfa220bdf62fd1365c Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 13 Jun 2025 20:40:07 -0500 Subject: [PATCH 01/14] github: Test setup-python and setup-poetry with pypy --- .github/workflows/test_actions.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 4127ebb..51a51a7 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -35,7 +35,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -62,7 +62,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -94,7 +94,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 From aff69aaa6b8e69be2609fc421bd8f4e60b97264c Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 13 Jun 2025 20:46:08 -0500 Subject: [PATCH 02/14] github: Handle pypy in setup-python test --- .github/workflows/test_actions.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 51a51a7..2c49607 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -23,10 +23,15 @@ jobs: run: | import sys version = sys.version_info[:2] - expected_version = tuple(map(int, "${{ matrix.python-version }}".split("."))) + expected_version = tuple(map(int, "${{ matrix.python-version }}".removeprefix("pypy").split("."))) if version != expected_version: print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.") sys.exit(1) + implementation = sys.implementation.name + 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) shell: python test_setup_poetry: From fa07367f95931be54376fbac11bb2954590de386 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 11:48:05 -0500 Subject: [PATCH 03/14] setup-python: Get Python version and set env.pythonVersion --- setup-python/action.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/setup-python/action.yml b/setup-python/action.yml index bda922d..3cee10b 100644 --- a/setup-python/action.yml +++ b/setup-python/action.yml @@ -7,7 +7,7 @@ outputs: python-path: value: ${{ steps.setup-python.outputs.python-path }} python-version: - value: ${{ steps.setup-python.outputs.python-version }} + value: ${{ steps.get-python-version.outputs.python-version }} runs: using: composite steps: @@ -16,3 +16,22 @@ 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 \ No newline at end of file From 5e2ab50749eccd52d2c6dcfe79a1c5310163bc83 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 11:48:36 -0500 Subject: [PATCH 04/14] setup-poetry: Use env.pythonVersion --- setup-poetry/action.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/setup-poetry/action.yml b/setup-poetry/action.yml index 379fb67..d58fa26 100644 --- a/setup-poetry/action.yml +++ b/setup-poetry/action.yml @@ -17,14 +17,12 @@ outputs: runs: using: composite steps: - - name: Get Python version - id: get-python-version + - name: Check that setup-python was called run: | - if [ ! -d "$pythonLocation" ]; then + if [ ! -d "$pythonLocation" -o -z "$pythonVersion" ]; then echo "You must use the setup-python action before using this action." exit 1 fi - "$pythonLocation/python" -c "import platform; print(f'python-version={platform.python_version()}')" >> "$GITHUB_OUTPUT" shell: bash - name: Set paths (Linux/Mac) if: runner.os != 'Windows' @@ -57,7 +55,7 @@ runs: path: | ${{ steps.copy-paths.outputs.poetry-bin-dir }}/poetry* ${{ steps.copy-paths.outputs.poetry-home }} - key: poetry${{ inputs.poetry-version }}-${{ runner.os }}-py${{ steps.get-python-version.outputs.python-version }} + key: poetry${{ inputs.poetry-version }}-${{ runner.os }}-py${{ env.pythonVersion }} - name: Install Poetry if: steps.cache-poetry.outputs.cache-hit != 'true' run: | From e018791dccefda3f96993b8671b1b53b59867687 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 11:51:46 -0500 Subject: [PATCH 05/14] tests: Add free-threading builds --- .github/workflows/test_actions.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 2c49607..a7f1636 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.12t, 3.13t, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -21,9 +21,9 @@ jobs: python-version: ${{ matrix.python-version }} - name: Check Python version run: | - import sys + import sys, sysconfig version = sys.version_info[:2] - expected_version = tuple(map(int, "${{ matrix.python-version }}".removeprefix("pypy").split("."))) + expected_version = tuple(map(int, "${{ matrix.python-version }}".removeprefix("pypy").removesuffix("t").split("."))) if version != expected_version: print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.") sys.exit(1) @@ -32,6 +32,11 @@ jobs: if implementation != expected_implementation: print(f"::error title=Test Failure::The Python implementation does not match. Got {implementation}, expected {expected_implementation}.") sys.exit(1) + threading = "free-threading" if sysconfig.get_config_var("Py_GIL_DISABLED") else "GIL" + expected_threading = "free-threading" if "${{ matrix.python-version }}".endswith("t") 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) shell: python test_setup_poetry: From 1c6ab169dbac5ff34eb340725a332f16d7f2391f Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 12:04:40 -0500 Subject: [PATCH 06/14] tests: Free-threaded builds are only for Python 3.13+ --- .github/workflows/test_actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index a7f1636..a8d4d3e 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.12t, 3.13t, pypy3.10, pypy3.11] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.13t, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 From 1f0f2c7fee1c875e97ac7b3a45192b03e57edbc6 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 12:05:10 -0500 Subject: [PATCH 07/14] tests: Test setup-poetry with free-threading too --- .github/workflows/test_actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index a8d4d3e..d07b5a0 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -45,7 +45,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.13t, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 From 31fd1235165ace891646a9e06514938f6188b0df Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 12:08:55 -0500 Subject: [PATCH 08/14] setup-poetry: Add `ls -al` for debugging --- setup-poetry/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/setup-poetry/action.yml b/setup-poetry/action.yml index d58fa26..bd5e172 100644 --- a/setup-poetry/action.yml +++ b/setup-poetry/action.yml @@ -59,6 +59,7 @@ runs: - name: Install Poetry if: steps.cache-poetry.outputs.cache-hit != 'true' run: | + ls -al "$pythonLocation" "$pythonLocation/python" -m venv "$POETRY_HOME" "$POETRY_HOME_BIN/python" -m pip install poetry==${{ inputs.poetry-version }} mkdir -p "$POETRY_BIN_DIR" From 8b74293fe80b154064c87222997e94efd78cddb0 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 12:32:04 -0500 Subject: [PATCH 09/14] tests: Add a temporary test of $pythonLocation --- .github/workflows/test_actions.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index d07b5a0..99a7d08 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -212,6 +212,19 @@ jobs: project-directory: test-project expected-version: 1.0.2.dev1 + test_python_location: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.11, pypy3.11] + steps: + - uses: actions/setup-python@v5.6.0 + with: + python-version: ${{ matrix.python-version }} + - run: ls -al $pythonLocation + shell: bash + # This job is intended to combine the test results so we don't have to list # each matrix combination in the required status check settings. There are a # lot of corner cases that make this harder than it should be; see See From 438a6a7a5e85dd48ec0ffabd1ee7461a5cbd8a6e Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 12:50:43 -0500 Subject: [PATCH 10/14] tests: More hacks --- .github/workflows/test_actions.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 99a7d08..d5a40f7 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -222,7 +222,10 @@ jobs: - uses: actions/setup-python@v5.6.0 with: python-version: ${{ matrix.python-version }} - - run: ls -al $pythonLocation + - run: ls -al "$pythonLocation" + shell: bash + - run: | + "$pythonLocation/python" -V shell: bash # This job is intended to combine the test results so we don't have to list From 8d3605313e742779953f4deb16db153a89a725ba Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 13:18:20 -0500 Subject: [PATCH 11/14] setup-poetry: Don't use $pythonLocation due to https://github.com/actions/setup-python/issues/1138 --- setup-poetry/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup-poetry/action.yml b/setup-poetry/action.yml index bd5e172..5664398 100644 --- a/setup-poetry/action.yml +++ b/setup-poetry/action.yml @@ -59,8 +59,7 @@ runs: - name: Install Poetry if: steps.cache-poetry.outputs.cache-hit != 'true' run: | - ls -al "$pythonLocation" - "$pythonLocation/python" -m venv "$POETRY_HOME" + python -m venv "$POETRY_HOME" "$POETRY_HOME_BIN/python" -m pip install poetry==${{ inputs.poetry-version }} mkdir -p "$POETRY_BIN_DIR" ln -s "$POETRY_HOME_BIN/poetry"* "$POETRY_BIN_DIR/" From 527d2663dd27ba9064db67235e027d826aabd37c Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 13:18:35 -0500 Subject: [PATCH 12/14] tests: Remove test_python_location --- .github/workflows/test_actions.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index d5a40f7..d07b5a0 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -212,22 +212,6 @@ jobs: project-directory: test-project expected-version: 1.0.2.dev1 - test_python_location: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-latest, ubuntu-latest] - python-version: [3.11, pypy3.11] - steps: - - uses: actions/setup-python@v5.6.0 - with: - python-version: ${{ matrix.python-version }} - - run: ls -al "$pythonLocation" - shell: bash - - run: | - "$pythonLocation/python" -V - shell: bash - # This job is intended to combine the test results so we don't have to list # each matrix combination in the required status check settings. There are a # lot of corner cases that make this harder than it should be; see See From 1156740eaaa0198cac94da61126d1b0c0ef50b3e Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 13:25:58 -0500 Subject: [PATCH 13/14] tests: Disable 3.13t for setup-poetry test --- .github/workflows/test_actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index d07b5a0..a8d4d3e 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -45,7 +45,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.13t, pypy3.10, pypy3.11] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11] steps: - name: Check out repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 From 28ebb279d8ecc05688912f3c98cea120d6bbf44d Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 16 Jun 2025 13:42:25 -0500 Subject: [PATCH 14/14] setup-python: Document new python-version behavior and env.pythonVersion --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index a4af285..3fa3501 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ - [Outputs](#outputs) - [`python-version`](#python-version-1) - [`python-path`](#python-path) + - [Environment Variables](#environment-variables) + - [`pythonVersion`](#pythonversion) - [`ni/python-actions/setup-poetry`](#nipython-actionssetup-poetry) - [Usage](#usage-1) - [Inputs](#inputs-1) @@ -82,6 +84,12 @@ steps: key: venv-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }} ``` +`python-version` is unique across implementations (CPython vs. PyPy) and free-threaded builds: + +- CPython: "3.13.4". +- CPython with free-threading: "3.13.4t" +- PyPy: "pypy3.11.11-v7.3.19" + #### `python-path` `actions/setup-python` sets the `pythonLocation` environment variable to the **directory** @@ -96,6 +104,13 @@ steps: - run: pipx install --python ${{ steps.setup-python.outputs.python-version }} ``` +### Environment Variables + +#### `pythonVersion` + +This is the same as `outputs.python-version` and is mainly intended for use in +`ni/python-actions/setup-poetry`. + ## `ni/python-actions/setup-poetry` The `setup-poetry` action installs Poetry, adds it to the PATH, and caches it to speed up