From 0097ef408d763afc8c65d4f9af74eb1c62e289b3 Mon Sep 17 00:00:00 2001 From: Christian Diener Date: Tue, 7 Jan 2025 13:19:04 +0100 Subject: [PATCH] Enable Python 3.13 and make tests more resilient to lacking cplex/gurobi wheels (#276) * switch to conditional additional solvers * add RNs * no idea how this syntax works * no idea how this syntax works * try this * change the dir test * Update src/optlang/tests/test_container.py Co-authored-by: Moritz E. Beber * update swiglpk * pin scipy to lower version to not break highs * fix req --------- Co-authored-by: Moritz E. Beber --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- CHANGELOG.rst | 1 + setup.cfg | 7 ++++--- src/optlang/tests/test_container.py | 10 ++++------ tox.ini | 22 ++++++++++++++-------- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f42424c..eb8f5d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ["3.11"] + python-version: ["3.13"] runs-on: ${{ matrix.os }} permissions: # Write permissions are needed to create OIDC tokens. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5cf7a8c..5e77184 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-13, windows-latest] - python-version: ["3.8", "3.11"] + python-version: ["3.9", "3.11", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8db42be..1bbc3ed 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Next Release * enable compatibility with Gurobi 12.0 * fix an issue where the removal of more than 350 constraints would lead to dangling references +* add support for Python 3.13 1.8.2 ----- diff --git a/setup.cfg b/setup.cfg index 277a987..3efa194 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,10 +15,11 @@ classifiers = License :: OSI Approved :: Apache Software License Natural Language :: English Operating System :: OS Independent - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Topic :: Scientific/Engineering :: Mathematics license = Apache-2.0 description = Formulate optimization problems using sympy expressions and solve them using interfaces to third-party optimization software (e.g. GLPK). @@ -33,9 +34,9 @@ keywords = [options] zip_safe = True install_requires = - swiglpk >=5.0.8 + swiglpk >=5.0.12 sympy >=1.12.0 -python_requires = >=3.8 +python_requires = >=3.9 tests_require = tox packages = find: diff --git a/src/optlang/tests/test_container.py b/src/optlang/tests/test_container.py index 444740e..dc7fd05 100644 --- a/src/optlang/tests/test_container.py +++ b/src/optlang/tests/test_container.py @@ -47,12 +47,10 @@ def test_dir(self): var = Variable('blub') self.container.append(var) print(dir(self.container)) - self.assertEqual(dir(self.container), - ['__contains__', '__delitem__', '__dict__', '__dir__', '__doc__', '__getattr__', '__getitem__', - '__getstate__', '__init__', '__iter__', '__len__', '__module__', '__setitem__', - '__setstate__', '__weakref__', '_check_for_name_attribute', '_reindex', 'append', 'blub', - 'clear', 'extend', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', - 'itervalues', 'keys', 'update_key', 'values']) + self.assertTrue( + all(hasattr(self.container, attribute) + for attribute in ['__contains__', 'keys', 'values']) + ) def test_del_by_index(self): variables_iterable = [Variable("v" + str(i), lb=10, ub=100) for i in range(1000)] diff --git a/tox.ini b/tox.ini index 4e09b02..fe236e9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,18 @@ [tox] -envlist = isort, black, flake8, safety, docs, py3{8,9,10,11}, py3{8,9,10,11}-symengine +envlist = + isort + black + flake8 + safety + docs + py3{9,11,13} + py3{9,11,13}-symengine [gh-actions] python = - 3.8: safety, py38, py38-symengine 3.9: safety, py39, py39-symengine - 3.10: safety, py310, py310-symengine 3.11: safety, py311, py311-symengine + 3.13: safety, py313, py313-symengine ;[testenv] ;deps = @@ -24,13 +30,13 @@ deps = jsonschema pytest pytest-cov - scipy - numpy >=1.13,<1.24 + scipy <1.15.0 # until https://github.com/scipy/scipy/issues/22257 is fixed + numpy >=1.13 osqp >=0.6.2 - mip >=1.9.1 + mip >=1.9.1; python_version < "3.13" highspy >=1.5.3 - cplex - gurobipy + cplex; python_version < "3.12" + gurobipy; python_version < "3.13" symengine: symengine passenv = CI commands =