Skip to content

Commit

Permalink
build: update for cython 3 (#40)
Browse files Browse the repository at this point in the history
tlambert03 authored Nov 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b2549bb commit 4da32d0
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 0 additions & 4 deletions ilpy/impl/solvers/GurobiBackend.cpp
Original file line number Diff line number Diff line change
@@ -147,12 +147,8 @@ GurobiBackend::setConstraints(const Constraints& constraints) {
}

_numConstraints = constraints.size();
unsigned int j = 0;
for (const Constraint& constraint : constraints) {

addConstraint(constraint);

j++;
}

GRB_CHECK(GRBupdatemodel(_model));
10 changes: 4 additions & 6 deletions ilpy/impl/solvers/ScipBackend.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
#ifdef HAVE_SCIP

#include <sstream>
#include <stdexcept> // for std::runtime_error

#include <scip/scipdefplugins.h>
#include <scip/cons_linear.h>
@@ -131,12 +132,8 @@ ScipBackend::setConstraints(const Constraints& constraints) {
// allocate memory for new constraints
_constraints.reserve(constraints.size());

unsigned int j = 0;
for (const Constraint& constraint : constraints) {

addConstraint(constraint);

j++;
}
}

@@ -172,7 +169,7 @@ ScipBackend::addConstraint(const Constraint& constraint) {
if (constraint.getRelation() == GreaterEqual)
rhs = SCIPinfinity(_scip);

SCIP_CALL_ABORT(SCIPcreateConsBasicQuadratic(
SCIP_CALL_ABORT(SCIPcreateConsBasicQuadraticNonlinear(
_scip,
&c,
name.c_str(),
@@ -323,7 +320,8 @@ ScipBackend::scipVarType(VariableType type, double& lb, double& ub) {
return SCIP_VARTYPE_CONTINUOUS;
}

assert(false);
// Handle the unexpected value of 'type'
throw std::runtime_error("Unhandled VariableType passed to ScipBackend::scipVarType");
}

#endif // HAVE_SCIP
4 changes: 2 additions & 2 deletions ilpy/wrapper.pyx
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ from libcpp.memory cimport shared_ptr
from libcpp.map cimport map as cppmap
from libcpp.string cimport string
from cython.operator cimport dereference as deref
cimport decl
from . cimport decl
from typing import Iterable, Mapping, Sequence

if TYPE_CHECKING:
@@ -47,7 +47,7 @@ cdef class Solution:

def __cinit__(self, size):
self.p = new decl.Solution(size)
self._status = ""
self._status = b""

def __dealloc__(self):
del self.p
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://peps.python.org/pep-0517
[build-system]
requires = ["setuptools", "Cython<3"]
requires = ["setuptools", "Cython"]
build-backend = "setuptools.build_meta"

# https://peps.python.org/pep-0621/
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -44,4 +44,12 @@
define_macros=[("CYTHON_TRACE", CYTHON_TRACE)],
)

setup(ext_modules=cythonize([wrapper], compiler_directives={"linetrace": CYTHON_TRACE}))
setup(
ext_modules=cythonize(
[wrapper],
compiler_directives={
"linetrace": CYTHON_TRACE,
"language_level": "3",
},
)
)

0 comments on commit 4da32d0

Please sign in to comment.