integrate install_python_dependencies in python + use protobuf from sources
This commit is contained in:
@@ -2,16 +2,19 @@ import logging, sys, inspect
|
||||
from os.path import dirname, abspath
|
||||
from optparse import OptionParser
|
||||
|
||||
def log_error_and_exit(error_message):
|
||||
logging.error(error_message)
|
||||
raise SystemExit
|
||||
|
||||
#try to import setuptools
|
||||
try:
|
||||
from setuptools import setup, Extension
|
||||
from setuptools.command import easy_install
|
||||
except ImportError:
|
||||
raise ImportError("""setuptools is not installed for \"""" + sys.executable + """\"
|
||||
log_error_and_exit("""setuptools is not installed for \"""" + sys.executable + """\"
|
||||
Follow this link for installing instructions :
|
||||
https://pypi.python.org/pypi/setuptools
|
||||
make sure you use \"""" + sys.executable + """\" during the installation""")
|
||||
raise SystemExit
|
||||
|
||||
from pkg_resources import parse_version
|
||||
|
||||
@@ -24,10 +27,6 @@ def wrong_module(module_file, modulename):
|
||||
The python examples are not importing the """ + modulename + """ module from the sources.
|
||||
Remove the site-package that contains \"""" + module_file + """\", either manually or by using pip, and rerun this script again."""
|
||||
|
||||
def log_error_and_exit(error_message):
|
||||
logging.error(error_message)
|
||||
raise SystemExit
|
||||
|
||||
# Returns the n_th parent of file
|
||||
def n_dirname(n, file):
|
||||
directory = file
|
||||
@@ -54,6 +53,8 @@ if __name__ == '__main__':
|
||||
|
||||
logging.info("Python path : " + sys.executable)
|
||||
logging.info("Python version : " + sys.version)
|
||||
logging.info("sys.path : " + str(sys.path))
|
||||
ortools_project_path = n_dirname(3, abspath(inspect.getfile(inspect.currentframe())))
|
||||
|
||||
#try to import ortools
|
||||
try:
|
||||
@@ -65,22 +66,11 @@ if __name__ == '__main__':
|
||||
#check if we're using ortools from the sources or it's binded by pypi's module
|
||||
ortools_module_file = inspect.getfile(ortools)
|
||||
ortools_module_path = n_dirname(3, ortools_module_file)
|
||||
ortools_project_path = n_dirname(3, abspath(inspect.getfile(inspect.currentframe())))
|
||||
try:
|
||||
if(ortools_module_path == ortools_project_path):
|
||||
logging.info("Good! The python examples are importing the ortools module from the sources. The imported module is : " + inspect.getfile(ortools))
|
||||
else:
|
||||
raise Exception
|
||||
except (Exception):
|
||||
if(ortools_module_path == ortools_project_path):
|
||||
logging.info("Or-tools is imported from : " + ortools_module_file)
|
||||
else:
|
||||
log_error_and_exit(wrong_module(ortools_module_file, "ortools"))
|
||||
|
||||
#try to import protobuf
|
||||
try:
|
||||
import google.protobuf
|
||||
logging.info("Protobuf is imported from " + inspect.getfile(google.protobuf))
|
||||
except ImportError:
|
||||
log_error_and_exit(notinstalled("protobuf"))
|
||||
|
||||
# Check if python can load the libraries' modules
|
||||
# this is useful when the library architecture is not compatbile with the python executable,
|
||||
# or when the library's dependencies are not available or not compatible.
|
||||
@@ -89,4 +79,20 @@ if __name__ == '__main__':
|
||||
from ortools.algorithms import _pywrapknapsack_solver
|
||||
from ortools.graph import _pywrapgraph
|
||||
|
||||
#try to import protobuf
|
||||
try:
|
||||
import google.protobuf
|
||||
except ImportError:
|
||||
log_error_and_exit(notinstalled("protobuf"))
|
||||
|
||||
#check if we're using protobuf from the sources or it's binded by pypi's module
|
||||
protobuf_module_file = inspect.getfile(google.protobuf)
|
||||
protobuf_module_path = n_dirname(7, protobuf_module_file)
|
||||
if(protobuf_module_path == ortools_project_path):
|
||||
logging.info("Protobuf is imported from : " + protobuf_module_file)
|
||||
else:
|
||||
log_error_and_exit(wrong_module(protobuf_module_file, "protobuf"))
|
||||
|
||||
#Check if the protobuf modules were successfully generated
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import descriptor_pb2
|
||||
@@ -1,3 +1,5 @@
|
||||
.PHONY : install_python_modules
|
||||
|
||||
# Python support using SWIG
|
||||
|
||||
# Detect python3
|
||||
@@ -23,11 +25,18 @@ ifeq ("$(PYTHON_VERSION)","35")
|
||||
SWIG_PYTHON3_FLAG=-py3 -DPY3
|
||||
endif
|
||||
|
||||
|
||||
OR_TOOLS_PYTHONPATH = $(OR_ROOT_FULL)$Ssrc$(CPSEP)$(OR_ROOT_FULL)$Sdependencies$Ssources$Sprotobuf-$(PROTOBUF_TAG)$Spython
|
||||
|
||||
ifeq ($(SYSTEM),win)
|
||||
PYTHON_EXECUTABLE = $(WINDOWS_PYTHON_PATH)$Spython
|
||||
SET_PYTHONPATH = @set PYTHONPATH=$(OR_TOOLS_PYTHONPATH) &&
|
||||
else #UNIX
|
||||
PYTHON_EXECUTABLE = python$(UNIX_PYTHON_VER)
|
||||
SET_PYTHONPATH = @PYTHONPATH=$(OR_TOOLS_PYTHONPATH)
|
||||
endif
|
||||
|
||||
# Main target
|
||||
python: pyinit pycp pyalgorithms pygraph pylp
|
||||
python: install_python_modules pyinit pycp pyalgorithms pygraph pylp
|
||||
|
||||
# Clean target
|
||||
clean_python:
|
||||
@@ -51,6 +60,15 @@ clean_python:
|
||||
-$(DEL) $(LIB_DIR)$S_pywrap*.$(SWIG_LIB_SUFFIX)
|
||||
-$(DEL) $(OBJ_DIR)$Sswig$S*python_wrap.$O
|
||||
|
||||
install_python_modules: dependencies/sources/protobuf-3.0.0/python/google/protobuf/descriptor_pb2.py
|
||||
|
||||
dependencies/sources/protobuf-3.0.0/python/google/protobuf/descriptor_pb2.py: \
|
||||
dependencies/sources/protobuf-$(PROTOBUF_TAG)/python/setup.py
|
||||
ifeq ("$(SYSTEM)", "win")
|
||||
copy dependencies$Sinstall$Sbin$Sprotoc.exe dependencies$Ssources$Sprotobuf-$(PROTOBUF_TAG)$Ssrc
|
||||
endif
|
||||
cd dependencies$Ssources$Sprotobuf-$(PROTOBUF_TAG)$Spython && $(PYTHON_EXECUTABLE) setup.py build
|
||||
|
||||
pyinit: $(GEN_DIR)$Sortools$S__init__.py
|
||||
|
||||
$(GEN_DIR)$Sortools$S__init__.py:
|
||||
@@ -206,12 +224,7 @@ endif
|
||||
|
||||
rpy: $(LIB_DIR)/_pywraplp.$(SWIG_LIB_SUFFIX) $(LIB_DIR)/_pywrapcp.$(SWIG_LIB_SUFFIX) $(LIB_DIR)/_pywrapgraph.$(SWIG_LIB_SUFFIX) $(LIB_DIR)/_pywrapknapsack_solver.$(SWIG_LIB_SUFFIX) $(EX)
|
||||
@echo Running $(EX)
|
||||
ifeq ($(SYSTEM),win)
|
||||
@set PYTHONPATH=$(OR_TOOLS_PYTHONPATH) && $(WINDOWS_PATH_TO_PYTHON)$Spython $(EX) $(ARGS)
|
||||
else
|
||||
@PYTHONPATH=$(OR_TOOLS_PYTHONPATH) python$(PYTHON_VERSION) $(EX) $(ARGS)
|
||||
endif
|
||||
|
||||
$(SET_PYTHONPATH) $(PYTHON_EXECUTABLE) $(EX) $(ARGS)
|
||||
|
||||
# Build stand-alone archive file for redistribution.
|
||||
|
||||
@@ -301,15 +314,15 @@ endif
|
||||
endif
|
||||
|
||||
pypi_upload: pypi_archive
|
||||
@echo Uploading Pypi module for python$(PYTHON_VERSION).
|
||||
@echo Uploading Pypi module for $(PYTHON_EXECUTABLE).
|
||||
ifeq ($(SYSTEM),win)
|
||||
set VS90COMNTOOLS=$(VS$(VS_COMTOOLS)COMNTOOLS)
|
||||
cd temp\ortools && $(WINDOWS_PATH_TO_PYTHON)\python setup.py register bdist_egg bdist_wheel bdist_wininst upload
|
||||
cd temp\ortools && $(PYTHON_EXECUTABLE) setup.py register bdist_egg bdist_wheel bdist_wininst upload
|
||||
else
|
||||
ifeq ($(PLATFORM),MACOSX)
|
||||
cd temp/ortools && python$(PYTHON_VERSION) setup.py register bdist_egg bdist_wheel upload
|
||||
cd temp/ortools && $(PYTHON_EXECUTABLE) setup.py register bdist_egg bdist_wheel upload
|
||||
else
|
||||
cd temp/ortools && python$(PYTHON_VERSION) setup.py register bdist_egg upload
|
||||
cd temp/ortools && $(PYTHON_EXECUTABLE) setup.py register bdist_egg upload
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -468,11 +468,6 @@ clean_third_party:
|
||||
# Create Makefile.local
|
||||
makefile_third_party: Makefile.local
|
||||
|
||||
# Install python modules
|
||||
install_python_modules: install_protobuf
|
||||
cd dependencies/sources/protobuf-$(PROTOBUF_TAG)/python && python$(PYTHON_VERSION) setup.py build
|
||||
cd dependencies/sources/protobuf-$(PROTOBUF_TAG)/python && python$(PYTHON_VERSION) setup.py install --user
|
||||
|
||||
Makefile.local:
|
||||
@echo Generating Makefile.local
|
||||
@echo UNIX_PYTHON_VER = $(DETECTED_PYTHON_VERSION) > Makefile.local
|
||||
|
||||
@@ -431,12 +431,6 @@ clean_third_party:
|
||||
# Create Makefile.local
|
||||
makefile_third_party: Makefile.local
|
||||
|
||||
# Install python modules
|
||||
install_python_modules: install_protobuf
|
||||
copy dependencies\install\bin\protoc.exe dependencies\sources\protobuf-$(PROTOBUF_TAG)\src
|
||||
cd dependencies\sources\protobuf-$(PROTOBUF_TAG)/python && $(WINDOWS_PATH_TO_PYTHON)\\python.exe setup.py build
|
||||
cd dependencies\sources\protobuf-$(PROTOBUF_TAG)/python && $(WINDOWS_PATH_TO_PYTHON)\\python.exe setup.py install --user
|
||||
|
||||
Makefile.local:
|
||||
@echo Generating Makefile.local
|
||||
@echo WINDOWS_ZLIB_DIR = $(OR_ROOT_FULL)\\dependencies\\install> Makefile.local
|
||||
|
||||
@@ -7,24 +7,24 @@ try:
|
||||
from setuptools.command import easy_install
|
||||
except ImportError:
|
||||
raise ImportError("""setuptools is not installed for \"""" + sys.executable + """\"
|
||||
Follow this link for installing instructions :
|
||||
Please follow this link for installing instructions :
|
||||
https://pypi.python.org/pypi/setuptools
|
||||
make sure you use \"""" + sys.executable + """\" during the installation""")
|
||||
raise SystemExit
|
||||
|
||||
from pkg_resources import parse_version
|
||||
|
||||
required_ortools_version = "VVVV"
|
||||
required_protobuf_version = "PROTOBUF_TAG"
|
||||
required_ortools_version = "5.0.3919"
|
||||
required_protobuf_version = "3.0.0"
|
||||
|
||||
def notinstalled(modulename):
|
||||
return modulename + """ is not installed for \"""" + sys.executable + """\"
|
||||
Run \"""" + sys.executable + """ setup.py install --user\" to install it"""
|
||||
Please run \"""" + str(sys.executable) + """ setup.py install --user\""""
|
||||
|
||||
def wrong_version(module, modulename, required_version, installed_version):
|
||||
return """You are using """ + modulename + """-""" + installed_version + """ : """ + inspect.getfile(module) + """, while the required version is : """ + required_version + """
|
||||
Run \"""" + sys.executable + """ setup.py install --user\" to upgrade.
|
||||
If the problem persists, remove the site-package that contains \"""" + inspect.getfile(module) + """\". You can do so either manually or by using pip."""
|
||||
Run \"""" + str(sys.executable) + """ setup.py install --user\" to upgrade.
|
||||
If the problem persists, then \"""" + inspect.getfile(module) + """\" is binding the newely installed version of """ + modulename + """. Remove it manually or by using pip."""
|
||||
|
||||
def log_error_and_exit(error_message):
|
||||
logging.error(error_message)
|
||||
|
||||
Reference in New Issue
Block a user