Skip to content

Commit

Permalink
add back conda search
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Dec 15, 2024
1 parent 8c7f210 commit 902039b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
10 changes: 4 additions & 6 deletions ilpy/impl/solvers/SolverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
#endif

// Platform-specific library names
// These must match the names in setup.py
#if defined(_WIN32) || defined(_WIN64)
#define GUROBI_LIB_NAME "ilpy_gurobi.dll"
#define SCIP_LIB_NAME "ilpy_scip.dll"
#elif defined(__APPLE__)
#define GUROBI_LIB_NAME "ilpybackend-gurobi.dll"
#define SCIP_LIB_NAME "ilpybackend-scip.dll"
#else
#define GUROBI_LIB_NAME "ilpybackend-gurobi.so"
#define SCIP_LIB_NAME "ilpybackend-scip.so"
#else
#define GUROBI_LIB_NAME "ilpy_gurobi.so"
#define SCIP_LIB_NAME "ilpy_scip.so"
#endif

// Load a library and return a handle
Expand Down
38 changes: 27 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@
define_macros = [("CYTHON_TRACE", CYTHON_TRACE)]


################ Main wrapper extension ################

include_dirs = ["ilpy/impl"]
library_dirs = []
if os.name == "nt":
compile_args = ["/O2", "/std:c++17", "/wd4702"]
else:
compile_args = ["-O3", "-std=c++17", "-Wno-unreachable-code"]


# include conda environment windows include/lib if it exists
# this will be done automatically by conda build, but is useful if someone
# tries to build this directly with pip install in a conda environment
if os.name == "nt" and "CONDA_PREFIX" in os.environ:
include_dirs.append(os.path.join(os.environ["CONDA_PREFIX"], "Library", "include"))
library_dirs.append(os.path.join(os.environ["CONDA_PREFIX"], "Library", "lib"))


################ Main wrapper extension ################


wrapper = Extension(
"ilpy.wrapper",
sources=["ilpy/wrapper.pyx"],
extra_compile_args=compile_args,
include_dirs=["ilpy/impl"],
include_dirs=include_dirs,
define_macros=define_macros,
)

Expand All @@ -37,6 +49,7 @@

################ Backend extensions ################


BACKEND_SOURCES = [
"ilpy/impl/solvers/Solution.cpp",
"ilpy/impl/solvers/Constraint.cpp",
Expand All @@ -58,21 +71,24 @@ def _find_lib(lib: str) -> str | None:
gurobi_backend = Extension(
name="ilpy.ilpybackend-gurobi",
sources=["ilpy/impl/solvers/GurobiBackend.cpp", *BACKEND_SOURCES],
include_dirs=["ilpy/impl"],
include_dirs=include_dirs,
libraries=[gurobi_lib],
library_dirs=library_dirs,
extra_compile_args=compile_args,
define_macros=define_macros,
)
ext_modules.append(gurobi_backend)
else:
print("Gurobi library NOT found, skipping Gurobi backend")


if scip_lib := _find_lib("scip"):
scip_backend = Extension(
name="ilpy.ilpybackend-scip",
sources=["ilpy/impl/solvers/ScipBackend.cpp", *BACKEND_SOURCES],
include_dirs=["ilpy/impl"],
include_dirs=include_dirs,
libraries=["scip"],
library_dirs=library_dirs,
extra_compile_args=compile_args,
define_macros=define_macros,
)
Expand All @@ -82,9 +98,12 @@ def _find_lib(lib: str) -> str | None:


################ Custom build_ext command ################

# Custom build_ext command to remove platform-specific tags ("cpython-312-darwin")
# from the generated shared libraries. This makes it easier to discover them


class CustomBuildExt(build_ext): # type: ignore
# Custom build_ext command to remove platform-specific tags ("cpython-312-darwin")
# from the generated shared libraries. This makes it easier to discover them
def get_ext_filename(self, fullname: str) -> str:
filename: str = super().get_ext_filename(fullname)
if "ilpybackend-" in filename:
Expand All @@ -94,7 +113,4 @@ def get_ext_filename(self, fullname: str) -> str:
return filename


setup(
ext_modules=ext_modules,
cmdclass={"build_ext": CustomBuildExt},
)
setup(ext_modules=ext_modules, cmdclass={"build_ext": CustomBuildExt})

0 comments on commit 902039b

Please sign in to comment.