Skip to content

Commit

Permalink
Make the extension work for Python 3.8+.
Browse files Browse the repository at this point in the history
See https://docs.python.org/3/c-api/stable.html for background.

Accordingly, the build matrix no longer needs the Python version.

Change-Id: I36c0f0c399c54e1ea06011bbe1d4aa8afef4cf05
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61871
Reviewed-by: Paul Wankadia <[email protected]>
Reviewed-by: Alex Chernyakhovsky <[email protected]>
  • Loading branch information
junyer committed Sep 7, 2023
1 parent b1e4fda commit 3a9939d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: number
jobs:
wheel-linux:
name: Linux ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
name: Linux ${{ matrix.os }}, ${{ matrix.arch.name }}
runs-on: ${{ matrix.arch.runs-on }}
container:
image: quay.io/pypa/${{ matrix.os }}_${{ matrix.arch.python-name }}
Expand All @@ -19,17 +19,16 @@ jobs:
- { name: X64, python-name: x86_64, runs-on: [ubuntu-latest] }
- { name: ARM64, python-name: aarch64, runs-on: [self-hosted, linux, arm64] }
os: [manylinux2014, manylinux_2_28]
ver: ['3.8', '3.9', '3.10', '3.11']
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
# TODO(junyer): Use `v2` whenever a new release is tagged.
- uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
- name: Prepare Python ${{ matrix.ver }} environment
- name: Prepare Python environment
run: |
ln -sf /usr/local/bin/python${{ matrix.ver }} /usr/local/bin/python
ln -sf /usr/local/bin/python${{ matrix.ver }} /usr/local/bin/python3
ln -sf /usr/local/bin/python3.8 /usr/local/bin/python
ln -sf /usr/local/bin/python3.8 /usr/local/bin/python3
python -m pip install --upgrade pip
python -m pip install --upgrade build wheel auditwheel
python -m pip install --upgrade absl-py
Expand Down Expand Up @@ -58,7 +57,7 @@ jobs:
path: python/google_re2-*.whl
retention-days: 1
wheel-macos:
name: macOS ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
name: macOS ${{ matrix.os }}, ${{ matrix.arch.name }}
runs-on: macos-${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -67,7 +66,6 @@ jobs:
- { name: X64, bazel-name: x86_64, python-name: x86_64 }
- { name: ARM64, bazel-name: arm64, python-name: arm64 }
os: [11, 12, 13]
ver: ['3.8', '3.9', '3.10', '3.11']
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BAZEL_CPU: darwin_${{ matrix.arch.bazel-name }}
Expand All @@ -81,8 +79,8 @@ jobs:
- uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.ver }}
- name: Prepare Python ${{ matrix.ver }} environment
python-version: '3.8'
- name: Prepare Python environment
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build wheel delocate
Expand All @@ -107,15 +105,14 @@ jobs:
path: python/google_re2-*.whl
retention-days: 1
wheel-windows:
name: Windows, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
name: Windows, ${{ matrix.arch.name }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
arch:
- { name: X86, bazel-name: x64_x86, python-name: win32 }
- { name: X64, bazel-name: x64, python-name: win_amd64 }
ver: ['3.8', '3.9', '3.10', '3.11']
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows
Expand All @@ -135,9 +132,9 @@ jobs:
shell: bash
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.ver }}
python-version: '3.8'
architecture: ${{ env.architecture }}
- name: Prepare Python ${{ matrix.ver }} environment
- name: Prepare Python environment
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build wheel delvewheel
Expand Down Expand Up @@ -170,8 +167,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Prepare Python 3.x environment
python-version: '3.8'
- name: Prepare Python environment
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build wheel
Expand Down
4 changes: 4 additions & 0 deletions python/_re2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// The extension works for Python 3.8+.
// See https://docs.python.org/3/c-api/stable.html for background.
#define Py_LIMITED_API 0x03080000

#include <memory>
#include <string>
#include <tuple>
Expand Down
3 changes: 3 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def options():
bdist_wheel['plat_name'] = os.environ['PLAT_NAME']
except KeyError:
pass
# The extension works for Python 3.8+.
# See https://docs.python.org/3/c-api/stable.html for background.
bdist_wheel['py_limited_api'] = 'cp38'
return {'bdist_wheel': bdist_wheel}


Expand Down

0 comments on commit 3a9939d

Please sign in to comment.