From 96a3cc7e7238939c7aa6323f6143bdb11392450b Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Mon, 22 Apr 2024 15:57:58 -0400 Subject: [PATCH] feat: ILPY_PREFERENCE env var --- ilpy/wrapper.pyx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ilpy/wrapper.pyx b/ilpy/wrapper.pyx index 6b19d45..e096dd4 100644 --- a/ilpy/wrapper.pyx +++ b/ilpy/wrapper.pyx @@ -1,4 +1,7 @@ # distutils: language = c++ +import os +import warnings + from typing import TYPE_CHECKING from libc.stdint cimport uint32_t @@ -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 + else: + warnings.warn(f"Unknown ILPY_PREFERENCE {env_pref!r}, using default {DEFAULT_PREF.name}") + cdef class Solver: cdef shared_ptr[decl.SolverBackend] p @@ -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: