From cbdc8f24f0e1066341ce5b16fc9ed40e9b89db6f Mon Sep 17 00:00:00 2001 From: Tuan Truong Date: Thu, 4 Apr 2024 09:10:23 -0700 Subject: [PATCH] Add more build platforms in GitHub Actions (#612) --- .github/workflows/python-package.yml | 76 +++++++++++++++++----------- .github/workflows/python-publish.yml | 76 ++++++++++++++++------------ setup.py | 1 + 3 files changed, 92 insertions(+), 61 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 812b502b0..9352892de 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,47 +16,63 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macos-latest, windows-latest] - python-version: ["3.8", "3.9", "3.10", "3.11"] - + os: [windows-latest, ubuntu-latest, macos-13, macos-14] + # python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + versions: + - { python: "3.8", numpy: 1.22.4 } + - { python: "3.9", numpy: 1.22.4 } + - { python: "3.10", numpy: 1.22.4 } + - { python: "3.11", numpy: 1.24.3 } + - { python: "3.12", numpy: 1.26.4 } + steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: Get number of CPU cores + uses: SimenB/github-actions-cpu-cores@v2 + id: cpu-cores + + - uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.versions.python }} + if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.versions.python != '3.8') && (matrix.versions.python != '3.9')) }} + uses: actions/setup-python@v5 + id: pysetup with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.versions.python }} cache: 'pip' - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - - name: Upgrade pip wheel setuptools - run: python -m pip install wheel setuptools pip --upgrade + - name: Setup Python 3.8-3.9 - macos-arm + if: ${{ (matrix.os == 'macos-14') && ((matrix.versions.python == '3.8') || (matrix.versions.python == '3.9')) }} + run: | + brew update + brew install python@${{ matrix.versions.python }} + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + python${{ matrix.versions.python }} get-pip.py - - name: Install numpy for Python 3.8 - if: matrix.python-version == '3.8' - run: python -m pip install numpy==1.20.3 - - - name: Install numpy for Python 3.9 - if: matrix.python-version == '3.9' - run: python -m pip install numpy==1.20.3 + - name: Create Python alias for Windows + if: matrix.os == 'windows-latest' + run: | + $newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.versions.python }}.exe") + New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}" - - name: Install numpy for Python 3.10 - if: matrix.python-version == '3.10' - run: python -m pip install numpy==1.22.4 + - name: Display Python and Pip versions + run: | + python${{ matrix.versions.python }} -c "import sys; print(sys.version)" + pip --version - - name: Install numpy for Python 3.11 - if: matrix.python-version == '3.11' - run: python -m pip install numpy==1.24.3 + - name: Upgrade pip wheel setuptools + run: pip install wheel setuptools pip --upgrade + - name: Install numpy ${{ matrix.versions.numpy }} + run: pip install numpy==${{ matrix.versions.numpy }} + - name: Display numpy version - run: python -c "import numpy; print(numpy.__version__)" + run: python${{ matrix.versions.python }} -c "import numpy; print(numpy.__version__)" - name: Install other dependencies run: | - python -m pip install scipy Cython pytest pytest-cov flake8 - python -m pip install -e .[tests] + pip install scipy Cython pytest pytest-cov flake8 + python${{ matrix.versions.python }} setup.py build_ext -j${{ steps.cpu-cores.outputs.count }} + pip install -e .[tests] - name: Lint with flake8 run: | @@ -67,4 +83,4 @@ jobs: - name: Test with pytest run: | - python -m pytest --cov=cornac + pytest --cov=cornac diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 0362715a8..32e0236e5 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -19,48 +19,62 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, macos-latest, windows-latest] - python-version: ["3.8", "3.9", "3.10", "3.11"] - - steps: - - uses: actions/checkout@v2 + os: [windows-latest, ubuntu-latest, macos-13, macos-14] + versions: + - { python: "3.8", numpy: 1.22.4 } + - { python: "3.9", numpy: 1.22.4 } + - { python: "3.10", numpy: 1.22.4 } + - { python: "3.11", numpy: 1.24.3 } + - { python: "3.12", numpy: 1.26.4 } - - name: Set up Python - uses: actions/setup-python@v2 + steps: + - uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.versions.python }} + if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.versions.python != '3.8') && (matrix.versions.python != '3.9')) }} + uses: actions/setup-python@v5 + id: pysetup with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.versions.python }} + cache: 'pip' - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - - name: Install numpy for Python 3.8 - if: matrix.python-version == '3.8' - run: python -m pip install numpy==1.20.3 - - - name: Install numpy for Python 3.9 - if: matrix.python-version == '3.9' - run: python -m pip install numpy==1.20.3 + - name: Setup Python 3.8-3.9 - macos-arm + if: ${{ (matrix.os == 'macos-14') && ((matrix.versions.python == '3.8') || (matrix.versions.python == '3.9')) }} + run: | + brew update + brew install python@${{ matrix.versions.python }} + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + python${{ matrix.versions.python }} get-pip.py - - name: Install numpy for Python 3.10 - if: matrix.python-version == '3.10' - run: python -m pip install numpy==1.22.4 + - name: Create Python alias for Windows + if: matrix.os == 'windows-latest' + run: | + $newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.versions.python }}.exe") + New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}" - - name: Install numpy for Python 3.11 - if: matrix.python-version == '3.11' - run: python -m pip install numpy==1.24.3 + - name: Display Python and Pip versions + run: | + python${{ matrix.versions.python }} -c "import sys; print(sys.version)" + pip --version + - name: Upgrade pip wheel setuptools + run: pip install wheel setuptools pip --upgrade + + - name: Install numpy ${{ matrix.versions.numpy }} + run: pip install numpy==${{ matrix.versions.numpy }} + - name: Display numpy version - run: python -c "import numpy; print(numpy.__version__)" + run: python${{ matrix.versions.python }} -c "import numpy; print(numpy.__version__)" - name: Install other dependencies run: | - python -m pip install scipy Cython wheel + pip install scipy Cython wheel - name: Build wheels - run: python setup.py bdist_wheel + run: python${{ matrix.versions.python }} setup.py bdist_wheel - name: Rename Linux wheels to supported platform of PyPI - if: matrix.os == 'ubuntu-20.04' + if: matrix.os == 'ubuntu-latest' run: for f in dist/*.whl; do mv "$f" "$(echo "$f" | sed s/linux/manylinux1/)"; done - name: Publish wheels to GitHub artifacts @@ -72,9 +86,9 @@ jobs: publish-pypi: needs: [build-wheels] - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/download-artifact@v2 with: @@ -82,7 +96,7 @@ jobs: path: dist/ - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/setup.py b/setup.py index 031891cf6..9bc9a3384 100644 --- a/setup.py +++ b/setup.py @@ -357,6 +357,7 @@ def run(self): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: Apache Software License", "Topic :: Software Development", "Topic :: Scientific/Engineering",