Skip to content

Commit

Permalink
Add tests and wheel for Python 3.12 (#42)
Browse files Browse the repository at this point in the history
* Add tests and wheels for Python 3.12

* Point the manylinux wheel test to python version 3.12

* Replace distutils module for build

* Change to shutil module to replace spawn check

* Replace get_python_inc() function with sysconfig equivalent

* Install/upgrade setuptools in all virtual environments
  • Loading branch information
StephenOman authored Oct 30, 2024
1 parent 079fb3d commit 3531028
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-20.04, macos-latest]
fail-fast: false
steps:
- name: Setup Python ${{ matrix.python-version }} env
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Ensure latest pip & wheel
run: python -m pip install -q --upgrade pip wheel
- name: Ensure latest pip, wheel & setuptools
run: python -m pip install -q --upgrade pip wheel setuptools
- name: Install dependencies
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
Expand Down Expand Up @@ -53,8 +53,8 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Ensure latest pip & wheel
run: python -m pip install -q --upgrade pip wheel
- name: Ensure latest pip, wheel & setuptools
run: python -m pip install -q --upgrade pip wheel setuptools
- name: Install dependencies
run: |
brew install cmake
Expand All @@ -75,17 +75,17 @@ jobs:
pushd ..
python -m pytest --import-mode=append -svx $REPONAME/nle/tests
popd
test_sdist_3_11:
name: Test sdist on MacOS w/ Py3.11
test_sdist_3_12:
name: Test sdist on MacOS w/ Py3.12
needs: test_repo
runs-on: macos-latest
steps:
- name: Setup Python 3.11 env
- name: Setup Python 3.12 env
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Ensure latest pip & wheel
run: python -m pip install -q --upgrade pip wheel
python-version: 3.12
- name: Ensure latest pip, wheel & setuptools
run: python -m pip install -q --upgrade pip wheel setuptools
- name: Install dependencies
run: |
brew install cmake
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
if: github.event_name != 'release'
uses: pypa/[email protected] # The main configuration is in pyproject.toml
env:
CIBW_BUILD: "cp311-manylinux*" # Build only python 3.11 wheels for testing
CIBW_BUILD: "cp312-manylinux*" # Build only python 3.12 wheels for testing
# Increase verbosity to see what's going on in the build in case of failure
CIBW_BUILD_VERBOSITY: 3
CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
Expand All @@ -145,17 +145,17 @@ jobs:
with:
name: python-wheels
path: ./wheelhouse/*.whl
test_manylinux_3_11:
name: Test manylinux wheel on Ubuntu w/ Py3.11
test_manylinux_3_12:
name: Test manylinux wheel on Ubuntu w/ Py3.12
needs: build_wheels
runs-on: ubuntu-20.04
steps:
- name: Setup Python 3.11 env
- name: Setup Python 3.12 env
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Ensure latest pip & wheel
run: python -m pip install -q --upgrade pip wheel
python-version: 3.12
- name: Ensure latest pip, wheel & setuptools
run: python -m pip install -q --upgrade pip wheel tools
- uses: actions/checkout@v4
with:
submodules: true
Expand All @@ -166,7 +166,7 @@ jobs:
path: dist
- name: Install from wheel # Install wheel mathcing the Python version and architecture
run: |
WHEELNAME=$(ls dist/*311*manylinux*x86_64*.whl)
WHEELNAME=$(ls dist/*312*manylinux*x86_64*.whl)
MODE="[all]"
pip install "$WHEELNAME$MODE"
- name: Run tests outside repo dir
Expand All @@ -179,7 +179,7 @@ jobs:
# Use prereleases to test publish the artefacts to testpypi
test_deploy:
name: Deploy artefacts to testpypi
needs: [test_sdist_3_11, test_manylinux_3_11]
needs: [test_sdist_3_12, test_manylinux_3_12]
if: github.event_name == 'release' && github.event.action == 'prereleased'
runs-on: ubuntu-latest
environment:
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
# functionalities like workflow dependencies :|
deploy_sdist:
name: Deploy sdist to pypi
needs: [test_sdist_3_11, test_manylinux_3_11]
needs: [test_sdist_3_12, test_manylinux_3_12]
if: github.event_name == 'release' && github.event.action == 'released'
runs-on: ubuntu-latest
environment:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
fail-fast: false
steps:
- name: Setup Python ${{ matrix.python-version }} env
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Ensure latest pip & wheel
run: "python -m pip install -q --upgrade pip wheel"
- name: Ensure latest pip, wheel & setuptools
run: "python -m pip install -q --upgrade pip wheel setuptools"
- name: Install dependencies
run: |
brew install cmake
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ allow-dict-calls-with-keyword-arguments = true

[tool.cibuildwheel]
# We need to build wheels for the following Python versions:
build = "cp{38,39,310,311}-*"
build = "cp{38,39,310,311,312}-*"

[tool.cibuildwheel.linux]
# Only manylinux is supported (no musllinux)
build = "cp{38,39,310,311}-manylinux*"
build = "cp{38,39,310,311,312}-manylinux*"

# We need to clean up the build directory, all .so files, and CMakeCache.txt
# and install the dependencies using yum, as manylinux2014 image is CentOS 7-based
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#
import os
import pathlib
import shutil
import subprocess
import sys
from distutils import spawn
from distutils import sysconfig
import sysconfig

import setuptools
from setuptools.command import build_ext
Expand All @@ -44,7 +44,7 @@ def build_extension(self, ext):
os.makedirs(self.build_temp, exist_ok=True)
build_type = "Debug" if self.debug else "Release"

generator = "Ninja" if spawn.find_executable("ninja") else "Unix Makefiles"
generator = "Ninja" if shutil.which("ninja") else "Unix Makefiles"

use_seeding = os.environ.get("USE_SEEDING", "ON")
use_seeding = {"1": "ON", "0": "OFF"}.get(use_seeding, use_seeding.upper())
Expand All @@ -60,7 +60,7 @@ def build_extension(self, ext):
"-DCMAKE_INSTALL_PREFIX=%s" % sys.base_prefix,
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=%s" % output_path,
"-DHACKDIR=%s" % hackdir_path,
"-DPYTHON_INCLUDE_DIR=%s" % sysconfig.get_python_inc(),
"-DPYTHON_INCLUDE_DIR=%s" % sysconfig.get_paths()["include"],
"-DPYTHON_LIBRARY=%s" % sysconfig.get_config_var("LIBDIR"),
"-DUSE_SEEDING=%s" % use_seeding,
]
Expand Down Expand Up @@ -175,6 +175,7 @@ def build_extension(self, ext):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: C",
"Programming Language :: C++",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
Expand Down

0 comments on commit 3531028

Please sign in to comment.