Skip to content

Commit

Permalink
Merge pull request #16147 from BastianZim/add-or-tools-package
Browse files Browse the repository at this point in the history
Add or-tools package
  • Loading branch information
wolfv authored Oct 25, 2021
2 parents 0a9349d + 4a374ce commit 17e965e
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 0 deletions.
73 changes: 73 additions & 0 deletions recipes/or-tools/0001-Fix-import-and-fail-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From 2a87f77dcd5a6e4b8bfae3225737548ba69fafcc Mon Sep 17 00:00:00 2001
From: BastianZim <[email protected]>
Date: Tue, 19 Oct 2021 19:55:59 +0200
Subject: [PATCH 1/2] Fix import and fail install

1) Fix the import until upstream releases a new version.
2) Do not install dependencies if not available.
---
cmake/python.cmake | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/cmake/python.cmake b/cmake/python.cmake
index a19d2d2ab3..5c77a60669 100644
--- a/cmake/python.cmake
+++ b/cmake/python.cmake
@@ -27,10 +27,10 @@ find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
list(APPEND CMAKE_SWIG_FLAGS "-py3" "-DPY3")

# Find if python module MODULE_NAME is available,
-# if not install it to the Python 3 user install directory.
-function(search_python_module MODULE_NAME)
+# if not install it (PACKAGE_NAME) to the Python3 user install directory.
+function(search_python_module MODULE_NAME PACKAGE_NAME)
execute_process(
- COMMAND ${Python3_EXECUTABLE} -c "import ${MODULE_NAME}; print(${MODULE_NAME}.__version__)"
+ COMMAND ${Python3_EXECUTABLE} -c "import ${MODULE_NAME}; print(${MODULE_NAME}.__package__)"
RESULT_VARIABLE _RESULT
OUTPUT_VARIABLE MODULE_VERSION
ERROR_QUIET
@@ -39,11 +39,7 @@ function(search_python_module MODULE_NAME)
if(${_RESULT} STREQUAL "0")
message(STATUS "Found python module: ${MODULE_NAME} (found version \"${MODULE_VERSION}\")")
else()
- message(WARNING "Can't find python module \"${MODULE_NAME}\", install it using pip...")
- execute_process(
- COMMAND ${Python3_EXECUTABLE} -m pip install --user ${MODULE_NAME}
- OUTPUT_STRIP_TRAILING_WHITESPACE
- )
+ message(FATAL_ERROR "Can't find python module \"${MODULE_NAME}\", please install it using your system package manager.")
endif()
endfunction()

@@ -64,7 +60,7 @@ function(search_python_internal_module MODULE_NAME)
endfunction()

# Generate Protobuf py sources with mypy support
-search_python_module(mypy-protobuf)
+search_python_module(mypy_protobuf mypy-protobuf)
set(PROTO_PYS)
file(GLOB_RECURSE proto_py_files RELATIVE ${PROJECT_SOURCE_DIR}
"ortools/constraint_solver/*.proto"
@@ -157,8 +153,8 @@ configure_file(
COPYONLY)

# Look for python module wheel
-search_python_module(setuptools)
-search_python_module(wheel)
+search_python_module(setuptools setuptools)
+search_python_module(wheel wheel)

# Main Target
add_custom_target(python_package ALL
@@ -199,7 +195,7 @@ install(SCRIPT ${PROJECT_BINARY_DIR}/python/python-install.cmake)
# Test
if(BUILD_TESTING)
# Look for python module venv
- search_python_module(absl-py)
+ search_python_module(absl absl-py)
search_python_internal_module(venv)
# Testing using a vitual environment
set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m venv)
--
2.33.0
27 changes: 27 additions & 0 deletions recipes/or-tools/0002-Do-not-install-dependencies.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 825c7460902c62a51f585d06d6a11a8bf2420370 Mon Sep 17 00:00:00 2001
From: BastianZim <[email protected]>
Date: Tue, 19 Oct 2021 19:57:42 +0200
Subject: [PATCH 2/2] Do not install dependencies

---
ortools/python/setup.py.in | 4 ----
1 file changed, 4 deletions(-)

diff --git a/ortools/python/setup.py.in b/ortools/python/setup.py.in
index 8e5bf834d9..0cb915dc1f 100644
--- a/ortools/python/setup.py.in
+++ b/ortools/python/setup.py.in
@@ -41,10 +41,6 @@ setup(
name='@PROJECT_NAME@',
version='@PROJECT_VERSION@',
packages=find_packages(),
- install_requires=[
- 'protobuf >= 3.18.0',
- 'absl-py >= 0.13',
- ],
package_data={
'@PROJECT_NAME@':[$<$<STREQUAL:$<TARGET_PROPERTY:@PYTHON_PROJECT@,TYPE>,SHARED_LIBRARY>:'.libs/*', '../$<TARGET_SONAME_FILE_NAME:@PYTHON_PROJECT@>'>],
'@[email protected]':['$<TARGET_FILE_NAME:pywrapinit>'],
--
2.33.0

14 changes: 14 additions & 0 deletions recipes/or-tools/build-cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cmake ${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=ON \
-BUILD_DEPS=OFF \
-DUSE_SCIP=OFF \
-S. \
-Bbuild \
-DBUILD_SAMPLES=OFF \
-DBUILD_EXAMPLES=OFF

cmake --build build --target install -j${CPU_COUNT}
20 changes: 20 additions & 0 deletions recipes/or-tools/build-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

cmake ${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_DEPS=OFF \
-DUSE_SCIP=OFF \
-S. \
-Bbuild \
-DBUILD_SAMPLES=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PYTHON=ON \
-DPython3_EXECUTABLE="$PYTHON"

cmake --build build -j${CPU_COUNT}

echo Install begins here

${PYTHON} -m pip install --no-index --find-links=build/python/dist ortools -vv
170 changes: 170 additions & 0 deletions recipes/or-tools/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{% set name = "or-tools" %}
{% set package_name = "ortools" %}
{% set version = "9.1" %}
{% set home = "https://developers.google.com/optimization" %}
{% set license = "Apache-2.0" %}
{% set license_family = "Apache" %}
{% set license_file = "LICENSE-2.0.txt" %}
{% set dev_url = "https://github.com/google/or-tools" %}


package:
name: {{ name|lower }}-package
version: {{ version }}

source:
url: https://github.com/google/or-tools/archive/v{{ version }}.tar.gz
sha256: b51ca3b08f768de5a0c1029f7127264640e50d9c7b83383a175109ef213bd307
patches:
- 0001-Fix-import-and-fail-install.patch
- 0002-Do-not-install-dependencies.patch

# The meta package

build:
number: 0
skip: True # [not linux]

outputs:
# The core package
- name: {{ package_name }}-cpp
script: build-cpp.sh

requirements:
build:
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- cmake >=3.18
# Source: https://github.com/google/or-tools/blob/stable/cmake/python.cmake#L6
- git
- pkg-config
host:
- abseil-cpp =20210324.2
- libprotobuf
- zlib 1.2.11
# coin or deps
- coin-or-utils 2.11.4
- coin-or-osi 0.108.6
- coin-or-clp 1.17.4
- coin-or-cgl 0.60.3
- coin-or-cbc 2.10.5
# Source: https://github.com/google/or-tools/blob/stable/cmake/dependencies/CMakeLists.txt
run_constrained:
- scip =7.0.1

test:
commands:
- test -f $PREFIX/lib/libortools${SHLIB_EXT}
- test -f $PREFIX/lib/cmake/ortools/ortoolsTargets.cmake
- test -f $PREFIX/lib/cmake/ortools/ortoolsConfig.cmake
- test -f $PREFIX/include/ortools_export.h
- test -f $PREFIX/include/ortools/algorithms/dense_doubly_linked_list.h

about:
home: {{ home }}
license: {{ license }}
license_family: {{ license_family }}
license_file: {{ license_file }}
summary: 'Google Operations Research Tools (or-tools)'
description: |
OR-Tools is an open source software suite for optimization, tuned for tackling
the world's toughest problems in vehicle routing, flows, integer and linear
programming, and constraint programming.
After modeling your problem in the programming language of your choice, you
can use any of a half dozen solvers to solve it: commercial solvers such as
Gurobi or CPLEX, or open-source solvers such as SCIP, GLPK, or Google's GLOP
and award-winning CP-SAT.
dev_url: {{ dev_url }}

# The python package.
- name: {{ package_name }}-python
script: build-python.sh

requirements:
build:
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- cmake >=3.18
- git
- mypy-protobuf
- pkg-config
- setuptools
- swig >=4.0
host:
- abseil-cpp =20210324.2
- absl-py >=0.13
- libprotobuf
- mypy-protobuf
- pip >=9.0.1
- python >=3.6
- wheel
- zlib 1.2.11
# coin or deps
- coin-or-utils 2.11.4
- coin-or-osi 0.108.6
- coin-or-clp 1.17.4
- coin-or-cgl 0.60.3
- coin-or-cbc 2.10.5
run:
- absl-py >=0.13
- mypy-protobuf
- protobuf
- python >=3.6
# Source: https://github.com/google/or-tools/blob/stable/ortools/python/setup.py.in#L44
run_constrained:
- scip =7.0.1

test:
imports:
- ortools
- ortools.linear_solver.pywraplp
commands:
- pip check
- ${PYTHON} cmake/samples/python/sample.py
- ${PYTHON} ortools/sat/samples/assignment_sat.py
requires:
- pip
source_files:
- cmake/samples/python/sample.py
- ortools/sat/samples/assignment_sat.py

about:
home: {{ home }}
license: {{ license }}
license_family: {{ license_family }}
license_file: {{ license_file }}
summary: 'Google Operations Research Tools (or-tools) python package'
description: |
OR-Tools is an open source software suite for optimization, tuned for tackling
the world's toughest problems in vehicle routing, flows, integer and linear
programming, and constraint programming.
After modeling your problem in the programming language of your choice, you
can use any of a half dozen solvers to solve it: commercial solvers such as
Gurobi or CPLEX, or open-source solvers such as SCIP, GLPK, or Google's GLOP
and award-winning CP-SAT.
dev_url: {{ dev_url }}

about:
home: {{ home }}
license: {{ license }}
license_family: {{ license_family }}
license_file: {{ license_file }}
summary: 'Google Operations Research Tools (or-tools) python package'
description: |
OR-Tools is an open source software suite for optimization, tuned for tackling
the world's toughest problems in vehicle routing, flows, integer and linear
programming, and constraint programming.
After modeling your problem in the programming language of your choice, you
can use any of a half dozen solvers to solve it: commercial solvers such as
Gurobi or CPLEX, or open-source solvers such as SCIP, GLPK, or Google's GLOP
and award-winning CP-SAT.
dev_url: {{ dev_url }}

extra:
recipe-maintainers:
- wolfv
- BastianZim
feedstock-name: or-tools

0 comments on commit 17e965e

Please sign in to comment.