From d4f1d252efa5e2ca54b2d43eaa92880cdf4ad8dc Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:45:58 +0300 Subject: [PATCH 1/6] Test 3.13 free-threaded build on CI --- .ci/install.sh | 6 ++++-- .github/workflows/test.yml | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index 1eb098be9c1..0dc738ed805 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -37,12 +37,14 @@ python3 -m pip install -U pytest-timeout python3 -m pip install pyroma if [[ $(uname) != CYGWIN* ]]; then - python3 -m pip install numpy + # TODO Update condition when NumPy supports free-threading + if ! [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then python3 -m pip install numpy ; fi # PyQt6 doesn't support PyPy3 if [[ $GHA_PYTHON_VERSION == 3.* ]]; then sudo apt-get -qq install libegl1 libxcb-cursor0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0 - python3 -m pip install pyqt6 + # TODO Update condition when pyqt6 supports free-threading + if ! [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then python3 -m pip install pyqt6 ; fi fi # Pyroma uses non-isolated build and fails with old setuptools diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0972459b0fb..75165909c10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,6 +55,8 @@ jobs: REVERSE: "--reverse" - python-version: "3.10" PYTHONOPTIMIZE: 2 + # Free-threaded + - { os: "ubuntu-latest", python-version: "3.13-dev", disable-gil: true } # M1 only available for 3.10+ - os: "macos-13" python-version: "3.9" @@ -70,6 +72,7 @@ jobs: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 + if: "!endsWith(matrix.python-version, '-dev')" with: python-version: ${{ matrix.python-version }} allow-prereleases: true @@ -78,6 +81,13 @@ jobs: ".ci/*.sh" "pyproject.toml" + - name: Set up Python ${{ matrix.python-version }} (free-threaded) + uses: deadsnakes/action@v3.1.0 + if: endsWith(matrix.python-version, '-dev') + with: + python-version: ${{ matrix.python-version }} + nogil: ${{ matrix.disable-gil }} + - name: Build system information run: python3 .github/workflows/system-info.py From e76c31b67db5e1cdfe28b593862bbe2d83a81e23 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:46:46 +0300 Subject: [PATCH 2/6] Refactor to single line for readability --- .github/workflows/test.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 75165909c10..d858dcfff6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,19 +50,14 @@ jobs: "3.9", ] include: - - python-version: "3.11" - PYTHONOPTIMIZE: 1 - REVERSE: "--reverse" - - python-version: "3.10" - PYTHONOPTIMIZE: 2 + - { python-version: "3.11", PYTHONOPTIMIZE: 1, REVERSE: "--reverse" } + - { python-version: "3.10", PYTHONOPTIMIZE: 2 } # Free-threaded - { os: "ubuntu-latest", python-version: "3.13-dev", disable-gil: true } # M1 only available for 3.10+ - - os: "macos-13" - python-version: "3.9" + - { os: "macos-13", python-version: "3.9" } exclude: - - os: "macos-14" - python-version: "3.9" + - { os: "macos-14", python-version: "3.9" } runs-on: ${{ matrix.os }} name: ${{ matrix.os }} Python ${{ matrix.python-version }} From 701539d017356d8624fba6a6efc97b8e2ebf75e2 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:38:50 +0300 Subject: [PATCH 3/6] Add PYTHON_GIL=0 env var to keep GIL disabled --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d858dcfff6e..fc8be6ced33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,6 +83,11 @@ jobs: python-version: ${{ matrix.python-version }} nogil: ${{ matrix.disable-gil }} + - name: Set PYTHON_GIL + if: "${{ matrix.disable-gil }}" + run: | + echo "PYTHON_GIL=0" >> $GITHUB_ENV + - name: Build system information run: python3 .github/workflows/system-info.py From 2d2889e6178ab619bae30952f4d477ac66352dea Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:49:27 +0300 Subject: [PATCH 4/6] Install nightly NumPy for free-threaded --- .ci/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.ci/install.sh b/.ci/install.sh index 0dc738ed805..e1274f41cc2 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -38,7 +38,11 @@ python3 -m pip install pyroma if [[ $(uname) != CYGWIN* ]]; then # TODO Update condition when NumPy supports free-threading - if ! [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then python3 -m pip install numpy ; fi + if [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then + python3 -m pip install numpy --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple + else + python3 -m pip install numpy + fi # PyQt6 doesn't support PyPy3 if [[ $GHA_PYTHON_VERSION == 3.* ]]; then From dcd833280538d8cd00b3c2a4617b534efdfa4ff0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:36:58 +0300 Subject: [PATCH 5/6] Include 'free-threading' in job name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc8be6ced33..70284181417 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,7 +60,7 @@ jobs: - { os: "macos-14", python-version: "3.9" } runs-on: ${{ matrix.os }} - name: ${{ matrix.os }} Python ${{ matrix.python-version }} + name: ${{ matrix.os }} Python ${{ matrix.python-version }} ${{ matrix.disable-gil && 'free-threaded' || '' }} steps: - uses: actions/checkout@v4 From 41eb218a6829ddc58a282d6952d9c0b5af25688d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 7 Jul 2024 22:04:50 +1000 Subject: [PATCH 6/6] Check GIL, rather than Python version --- .ci/install.sh | 4 ++-- .github/workflows/test.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index e1274f41cc2..8e65f64c447 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -38,7 +38,7 @@ python3 -m pip install pyroma if [[ $(uname) != CYGWIN* ]]; then # TODO Update condition when NumPy supports free-threading - if [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then + if [[ "$PYTHON_GIL" == "0" ]]; then python3 -m pip install numpy --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple else python3 -m pip install numpy @@ -48,7 +48,7 @@ if [[ $(uname) != CYGWIN* ]]; then if [[ $GHA_PYTHON_VERSION == 3.* ]]; then sudo apt-get -qq install libegl1 libxcb-cursor0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0 # TODO Update condition when pyqt6 supports free-threading - if ! [[ "$GHA_PYTHON_VERSION" == "3.13-dev" ]]; then python3 -m pip install pyqt6 ; fi + if ! [[ "$PYTHON_GIL" == "0" ]]; then python3 -m pip install pyqt6 ; fi fi # Pyroma uses non-isolated build and fails with old setuptools diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70284181417..6e63333b0da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,7 +67,7 @@ jobs: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 - if: "!endsWith(matrix.python-version, '-dev')" + if: "${{ !matrix.disable-gil }}" with: python-version: ${{ matrix.python-version }} allow-prereleases: true @@ -78,7 +78,7 @@ jobs: - name: Set up Python ${{ matrix.python-version }} (free-threaded) uses: deadsnakes/action@v3.1.0 - if: endsWith(matrix.python-version, '-dev') + if: "${{ matrix.disable-gil }}" with: python-version: ${{ matrix.python-version }} nogil: ${{ matrix.disable-gil }}