Skip to content

Commit

Permalink
feat: ILPY_PREFERENCE env var
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Apr 22, 2024
1 parent 1746c8b commit 96a3cc7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ilpy/wrapper.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# distutils: language = c++
import os
import warnings

from typing import TYPE_CHECKING

from libc.stdint cimport uint32_t
Expand Down Expand Up @@ -242,6 +245,16 @@ cdef class Constraints:
def __len__(self):
return self.p.size()

DEFAULT_PREF = Preference.Any
env_pref = os.environ.get("ILPY_PREFERENCE")
if env_pref:
for p in Preference:
if p.name.lower() == env_pref.lower():
DEFAULT_PREF = p
break

Check warning on line 254 in ilpy/wrapper.pyx

View check run for this annotation

Codecov / codecov/patch

ilpy/wrapper.pyx#L251-L254

Added lines #L251 - L254 were not covered by tests
else:
warnings.warn(f"Unknown ILPY_PREFERENCE {env_pref!r}, using default {DEFAULT_PREF.name}")

Check warning on line 256 in ilpy/wrapper.pyx

View check run for this annotation

Codecov / codecov/patch

ilpy/wrapper.pyx#L256

Added line #L256 was not covered by tests

cdef class Solver:

cdef shared_ptr[decl.SolverBackend] p
Expand All @@ -252,7 +265,7 @@ cdef class Solver:
num_variables,
default_variable_type,
dict variable_types=None,
Preference preference=Preference.Any):
Preference preference=DEFAULT_PREF):
cdef decl.SolverFactory factory
cdef cppmap[unsigned int, decl.VariableType] vtypes
if variable_types is not None:
Expand Down

0 comments on commit 96a3cc7

Please sign in to comment.