Skip to content
Snippets Groups Projects
Unverified Commit ef9956e6 authored by darrylong's avatar darrylong Committed by GitHub
Browse files

Fix Pytest error in test cases due to Numpy 2.0 incompatibility (#627)

parent 52979eb5
Branches
No related tags found
No related merge requests found
...@@ -8,6 +8,9 @@ jobs: ...@@ -8,6 +8,9 @@ jobs:
build-and-test: build-and-test:
docker: docker:
- image: cimg/python:3.10.2 - image: cimg/python:3.10.2
environment:
LIMIT_NUMPY_VERSION: 2.0.0
LIMIT_SCIPY_VERSION: 1.13.1
steps: steps:
- checkout - checkout
- python/install-packages: - python/install-packages:
...@@ -17,7 +20,7 @@ jobs: ...@@ -17,7 +20,7 @@ jobs:
no_output_timeout: 30m no_output_timeout: 30m
command: | command: |
pip install --upgrade pip pip install --upgrade pip
pip install --only-binary=numpy,scipy numpy==1.22.4 scipy Cython pytest pytest-cov codecov pip install --only-binary=numpy,scipy "numpy<$LIMIT_NUMPY_VERSION" "scipy<=$LIMIT_SCIPY_VERSION" Cython pytest pytest-cov codecov
pip install -e .[tests] pip install -e .[tests]
- run: - run:
name: Run tests name: Run tests
......
...@@ -17,14 +17,10 @@ jobs: ...@@ -17,14 +17,10 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [windows-latest, ubuntu-latest, macos-13, macos-14] os: [windows-latest, ubuntu-latest, macos-13, macos-14]
# python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
versions: env:
- { python: "3.8", numpy: 1.22.4 } LIMIT_NUMPY_VERSION: 2.0.0
- { python: "3.9", numpy: 1.22.4 } LIMIT_SCIPY_VERSION: 1.13.1
- { python: "3.10", numpy: 1.22.4 }
- { python: "3.11", numpy: 1.24.3 }
- { python: "3.12", numpy: 1.26.4 }
steps: steps:
- name: Get number of CPU cores - name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2 uses: SimenB/github-actions-cpu-cores@v2
...@@ -32,47 +28,47 @@ jobs: ...@@ -32,47 +28,47 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Python ${{ matrix.versions.python }} - name: Setup Python ${{ matrix.python-version }}
if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.versions.python != '3.8') && (matrix.versions.python != '3.9')) }} if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.python-version != '3.8') && (matrix.python-version != '3.9')) }}
uses: actions/setup-python@v5 uses: actions/setup-python@v5
id: pysetup id: pysetup
with: with:
python-version: ${{ matrix.versions.python }} python-version: ${{ matrix.python-version }}
cache: 'pip' cache: 'pip'
- name: Setup Python 3.8-3.9 - macos-arm - name: Setup Python 3.8-3.9 - macos-arm
if: ${{ (matrix.os == 'macos-14') && ((matrix.versions.python == '3.8') || (matrix.versions.python == '3.9')) }} if: ${{ (matrix.os == 'macos-14') && ((matrix.python-version == '3.8') || (matrix.python-version == '3.9')) }}
run: | run: |
brew update brew update
brew install python@${{ matrix.versions.python }} brew install python@${{ matrix.python-version }}
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python${{ matrix.versions.python }} get-pip.py python${{ matrix.python-version }} get-pip.py
- name: Create Python alias for Windows - name: Create Python alias for Windows
if: matrix.os == 'windows-latest' if: matrix.os == 'windows-latest'
run: | run: |
$newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.versions.python }}.exe") $newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.python-version }}.exe")
New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}" New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}"
- name: Display Python and Pip versions - name: Display Python and Pip versions
run: | run: |
python${{ matrix.versions.python }} -c "import sys; print(sys.version)" python${{ matrix.python-version }} -c "import sys; print(sys.version)"
pip --version pip --version
- name: Upgrade pip wheel setuptools - name: Upgrade pip wheel setuptools
run: pip install wheel setuptools pip --upgrade run: python${{ matrix.python-version }} -m pip install wheel setuptools pip --upgrade
- name: Install numpy ${{ matrix.versions.numpy }}
run: pip install numpy==${{ matrix.versions.numpy }}
- name: Display numpy version - name: Install other dependencies
run: python${{ matrix.versions.python }} -c "import numpy; print(numpy.__version__)" run: python${{ matrix.python-version }} -m pip install Cython pytest pytest-cov flake8
- name: Install other dependencies - name: Install other dependencies
run: | run: |
pip install scipy Cython pytest pytest-cov flake8 python${{ matrix.python-version }} -m pip install Cython pytest pytest-cov flake8 "numpy<${{ env.LIMIT_NUMPY_VERSION }}" "scipy<=${{ env.LIMIT_SCIPY_VERSION }}"
python${{ matrix.versions.python }} setup.py build_ext -j${{ steps.cpu-cores.outputs.count }} python${{ matrix.python-version }} setup.py build_ext -j${{ steps.cpu-cores.outputs.count }}
pip install -e .[tests] python${{ matrix.python-version }} -m pip install -e .[tests]
- name: Display numpy version
run: python${{ matrix.python-version }} -c "import numpy; print(numpy.__version__)"
- name: Lint with flake8 - name: Lint with flake8
run: | run: |
...@@ -83,4 +79,4 @@ jobs: ...@@ -83,4 +79,4 @@ jobs:
- name: Test with pytest - name: Test with pytest
run: | run: |
pytest --cov=cornac python${{ matrix.python-version }} -m pytest --cov=cornac
...@@ -12,6 +12,10 @@ on: ...@@ -12,6 +12,10 @@ on:
release: release:
types: [published] types: [published]
env:
LIMIT_NUMPY_VERSION: 2.0.0
LIMIT_SCIPY_VERSION: 1.13.1
jobs: jobs:
build-wheels: build-wheels:
name: Building on ${{ matrix.os }} name: Building on ${{ matrix.os }}
...@@ -20,58 +24,52 @@ jobs: ...@@ -20,58 +24,52 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [windows-latest, ubuntu-latest, macos-13, macos-14] os: [windows-latest, ubuntu-latest, macos-13, macos-14]
versions: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
- { 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: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Python ${{ matrix.versions.python }} - name: Setup Python ${{ matrix.python-version }}
if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.versions.python != '3.8') && (matrix.versions.python != '3.9')) }} if: ${{ (matrix.os != 'macos-14') || ((matrix.os == 'macos-14') && (matrix.python-version != '3.8') && (matrix.python-version != '3.9')) }}
uses: actions/setup-python@v5 uses: actions/setup-python@v5
id: pysetup id: pysetup
with: with:
python-version: ${{ matrix.versions.python }} python-version: ${{ matrix.python-version }}
cache: 'pip' cache: 'pip'
- name: Setup Python 3.8-3.9 - macos-arm - name: Setup Python 3.8-3.9 - macos-arm
if: ${{ (matrix.os == 'macos-14') && ((matrix.versions.python == '3.8') || (matrix.versions.python == '3.9')) }} if: ${{ (matrix.os == 'macos-14') && ((matrix.python-version == '3.8') || (matrix.python-version == '3.9')) }}
run: | run: |
brew update brew update
brew install python@${{ matrix.versions.python }} brew install python@${{ matrix.python-version }}
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python${{ matrix.versions.python }} get-pip.py python${{ matrix.python-version }} get-pip.py
- name: Create Python alias for Windows - name: Create Python alias for Windows
if: matrix.os == 'windows-latest' if: matrix.os == 'windows-latest'
run: | run: |
$newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.versions.python }}.exe") $newPath = "${{ steps.pysetup.outputs.python-path }}".Replace("python.exe", "python${{ matrix.python-version }}.exe")
New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}" New-Item -ItemType HardLink -Path "$newPath" -Value "${{ steps.pysetup.outputs.python-path }}"
- name: Display Python and Pip versions - name: Display Python and Pip versions
run: | run: |
python${{ matrix.versions.python }} -c "import sys; print(sys.version)" python${{ matrix.python-version }} -c "import sys; print(sys.version)"
pip --version pip --version
- name: Upgrade pip wheel setuptools - name: Upgrade pip wheel setuptools
run: pip install wheel setuptools pip --upgrade run: python${{ matrix.python-version }} -m pip install wheel setuptools pip --upgrade
- name: Install numpy ${{ matrix.versions.numpy }}
run: pip install numpy==${{ matrix.versions.numpy }}
- name: Display numpy version - name: Install numpy, scipy
run: python${{ matrix.versions.python }} -c "import numpy; print(numpy.__version__)" run: pip install "numpy<${{ env.LIMIT_NUMPY_VERSION }}" "scipy<=${{ env.LIMIT_SCIPY_VERSION }}"
- name: Install other dependencies - name: Install other dependencies
run: | run: |
pip install scipy Cython wheel pip install Cython wheel
- name: Display numpy version
run: python${{ matrix.python-version }} -c "import numpy; print(numpy.__version__)"
- name: Build wheels - name: Build wheels
run: python${{ matrix.versions.python }} setup.py bdist_wheel run: python${{ matrix.python-version }} setup.py bdist_wheel
- name: Rename Linux wheels to supported platform of PyPI - name: Rename Linux wheels to supported platform of PyPI
if: matrix.os == 'ubuntu-latest' if: matrix.os == 'ubuntu-latest'
...@@ -105,12 +103,12 @@ jobs: ...@@ -105,12 +103,12 @@ jobs:
- name: Install numpy - name: Install numpy
run: | run: |
python -m pip install numpy==1.22.4 python -m pip install "numpy<${{ env.LIMIT_NUMPY_VERSION }}" "scipy<=${{ env.LIMIT_SCIPY_VERSION }}"
python -c "import numpy; print(numpy.__version__)" python -c "import numpy; print(numpy.__version__)"
- name: Install other dependencies - name: Install other dependencies
run: | run: |
python -m pip install scipy Cython wheel python -m pip install Cython wheel
- name: Build source tar file - name: Build source tar file
run: python setup.py sdist run: python setup.py sdist
......
...@@ -343,7 +343,7 @@ setup( ...@@ -343,7 +343,7 @@ setup(
"recommendation", "recommendation",
], ],
ext_modules=extensions, ext_modules=extensions,
install_requires=["numpy", "scipy", "tqdm", "powerlaw"], install_requires=["numpy<2.0.0", "scipy<=1.13.1", "tqdm", "powerlaw"],
extras_require={"tests": ["pytest", "pytest-pep8", "pytest-xdist", "pytest-cov", "Flask"]}, extras_require={"tests": ["pytest", "pytest-pep8", "pytest-xdist", "pytest-cov", "Flask"]},
cmdclass=cmdclass, cmdclass=cmdclass,
packages=find_packages(), packages=find_packages(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment