Skip to content

Commit

Permalink
feat: ILPY_PREFERENCE env var (#59)
Browse files Browse the repository at this point in the history
* feat: ILPY_PREFERENCE env var

* lint
  • Loading branch information
tlambert03 authored Apr 22, 2024
1 parent 1746c8b commit 5dc9202
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 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,18 @@ 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
else:
warnings.warn(
f"Unknown ILPY_PREFERENCE {env_pref!r}, using default {DEFAULT_PREF.name}"
)

cdef class Solver:

cdef shared_ptr[decl.SolverBackend] p
Expand All @@ -252,7 +267,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 5dc9202

Please sign in to comment.