Skip to content

Commit

Permalink
Add python archive #3200
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Apr 4, 2022
1 parent 5514306 commit 253168d
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions makefiles/Makefile.python.mk
Expand Up @@ -64,7 +64,7 @@ rpy_%: \
"$(PYTHON_EXECUTABLE)" ortools$S$1$Ssamples$S$$*.py $(ARGS)
endef

PYTHON_SAMPLES := algorithms graph constraint_solver linear_solver model_builder sat
PYTHON_SAMPLES := algorithms graph constraint_solver linear_solver math_opt model_builder routing sat
$(foreach sample,$(PYTHON_SAMPLES),$(eval $(call python-sample-target,$(sample))))

# Examples
Expand Down Expand Up @@ -532,7 +532,7 @@ $(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools/.libs: | $(PYPI_ARCHIVE_TEMP_DIR)/ortoo
-$(MKDIR) $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$S.libs

ifneq ($(PYTHON_EXECUTABLE),)
package_python: cc
package_python: python
-$(DEL) $.*whl
$(COPY) $(PYTHON_BUILD_PATH)$Sdist$S*.whl .

Expand Down Expand Up @@ -659,6 +659,58 @@ endif

endif # HAS_PYTHON=ON

###############
## Archive ##
###############
.PHONY: archive_python # Generate Python OR-Tools archive.
archive_python: $(INSTALL_PYTHON_NAME)$(ARCHIVE_EXT)

$(INSTALL_PYTHON_NAME):
$(MKDIR) $(INSTALL_PYTHON_NAME)

$(INSTALL_PYTHON_NAME)/examples: | $(INSTALL_PYTHON_NAME)
$(MKDIR) $(INSTALL_PYTHON_NAME)$Sexamples

define python-sample-archive =
$(INSTALL_PYTHON_NAME)/examples/%.py: \
$(SRC_DIR)/ortools/$1/samples/%.py \
| $(INSTALL_PYTHON_NAME)/examples
$(COPY) $(SRC_DIR)$Sortools$S$1$Ssamples$S$$*.py $(INSTALL_PYTHON_NAME)$Sexamples
endef

$(foreach sample,$(PYTHON_SAMPLES),$(eval $(call python-sample-archive,$(sample))))

define python-example-archive =
$(INSTALL_PYTHON_NAME)/examples/%.py: \
$(SRC_DIR)/examples/$1/%.py \
| $(INSTALL_PYTHON_NAME)/examples
$(COPY) $(SRC_DIR)$Sexamples$S$1$S$$*.py $(INSTALL_PYTHON_NAME)$Sexamples
endef

$(foreach example,$(PYTHON_EXAMPLES),$(eval $(call python-example-archive,$(example))))

SAMPLE_PYTHON_FILES = \
$(addsuffix .py,$(addprefix $(INSTALL_PYTHON_NAME)/examples/,$(basename $(notdir $(wildcard ortools/*/samples/*.py)))))

EXAMPLE_PYTHON_FILES = \
$(addsuffix .py,$(addprefix $(INSTALL_PYTHON_NAME)/examples/,$(basename $(notdir $(wildcard examples/contrib/*.py))))) \
$(addsuffix .py,$(addprefix $(INSTALL_PYTHON_NAME)/examples/,$(basename $(notdir $(wildcard examples/python/*.py)))))

$(INSTALL_PYTHON_NAME)$(ARCHIVE_EXT): \
python \
$(SAMPLE_PYTHON_FILES) \
$(EXAMPLE_PYTHON_FILES)
$(COPY) $(PYTHON_BUILD_PATH)$Sdist$S*.whl $(INSTALL_PYTHON_NAME)
$(COPY) LICENSE $(INSTALL_PYTHON_NAME)
$(COPY) tools$SREADME.python.md $(INSTALL_PYTHON_NAME)$SREADME.md
$(COPY) tools$SMakefile.python $(INSTALL_PYTHON_NAME)$SMakefile
$(SED) -i -e 's/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/' $(INSTALL_PYTHON_NAME)$SMakefile
ifeq ($(PLATFORM),WIN64)
$(ZIP) -r $(INSTALL_PYTHON_NAME)$(ARCHIVE_EXT) $(INSTALL_PYTHON_NAME)
else
$(TAR) --no-same-owner -czvf $(INSTALL_PYTHON_NAME)$(ARCHIVE_EXT) $(INSTALL_PYTHON_NAME)
endif

################
## Cleaning ##
################
Expand Down

0 comments on commit 253168d

Please sign in to comment.