diff --git a/.github/workflows/pytest-core-nompi.yml b/.github/workflows/pytest-core-nompi.yml index 553fbccb150..f3189f8aafa 100644 --- a/.github/workflows/pytest-core-nompi.yml +++ b/.github/workflows/pytest-core-nompi.yml @@ -163,8 +163,8 @@ jobs: if: "!contains(matrix.name, 'docker')" run: | pip install ${{ env.PIPFLAGS }} --upgrade pip - pip install ${{ env.PIPFLAGS }} -e .[tests] pip install ${{ env.PIPFLAGS }} sympy==${{matrix.sympy}} + pip install ${{ env.PIPFLAGS }} -e .[tests] - name: Check configuration run: | diff --git a/requirements.txt b/requirements.txt index acfe76d53c3..0ebd994b1aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ pip>=9.0.1 -numpy>1.16,<2.0 +numpy>1.16,<2.1 sympy>=1.9,<1.13 psutil>=5.1.0,<7.0 py-cpuinfo<10 diff --git a/setup.py b/setup.py index 5d22060ba09..9adeb42029e 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,37 @@ import versioneer import os +import sys +import pkg_resources from setuptools import setup, find_packages + +def numpy_compat(required): + new_reqs = [r for r in required if "numpy" not in r and "sympy" not in r] + if sys.version_info <= (3, 8): + # Numpy 2.0 requires python > 3.8 + new_reqs.extend(["sympy>=1.9,<1.13", "numpy>1.16,<2.0"]) + return new_reqs + + # Due to api changes in numpy 2.0, it requires sympy 1.12.1 at the minimum + # Check if sympy is installed and enforce numpy version accordingly. + # If sympy isn't installed, endforce sympy>=1.12.1 and numpy>=2.0 + try: + sympy_version = pkg_resources.get_distribution("sympy").version + min_ver2 = pkg_resources.parse_version("1.12.1") + if pkg_resources.parse_version(sympy_version) < min_ver2: + new_reqs.append("numpy>1.16,<2.0") + else: + new_reqs.append("numpy>=2.0") + except pkg_resources.DistributionNotFound: + new_reqs.extend(["sympy>=1.12.1", "numpy>=2.0"]) + + return new_reqs + + with open('requirements.txt') as f: required = f.read().splitlines() + required = numpy_compat(required) with open('requirements-optional.txt') as f: optionals = f.read().splitlines()