aboutsummaryrefslogtreecommitdiffhomepage
path: root/util/python/python_config.sh
diff options
context:
space:
mode:
Diffstat (limited to 'util/python/python_config.sh')
-rwxr-xr-xutil/python/python_config.sh76
1 files changed, 71 insertions, 5 deletions
diff --git a/util/python/python_config.sh b/util/python/python_config.sh
index d5762ad456..4b18bf3578 100755
--- a/util/python/python_config.sh
+++ b/util/python/python_config.sh
@@ -26,9 +26,23 @@ else
script_path=${script_path:-.}
fi
+EXPECTED_PATHS="$script_path/util/python/python_include"\
+" $script_path/util/python/python_lib"\
+" $script_path/third_party/py/numpy/numpy_include"
+
function main {
- setup_python "$1"
- exit 0
+ argument="$1"
+ shift
+ case $argument in
+ --check)
+ check_python
+ exit 0
+ ;;
+ --setup)
+ setup_python "$1"
+ exit 0
+ ;;
+ esac
}
function python_path {
@@ -79,7 +93,6 @@ END
function setup_python {
PYTHON_BIN_PATH="$1";
- # TODO(ngiraldo): move most of these checks to root configure
if [ -z "$PYTHON_BIN_PATH" ]; then
echo "PYTHON_BIN_PATH was not provided. Did you run configure?"
exit 1
@@ -95,7 +108,12 @@ function setup_python {
exit 1
fi
- # TODO(ngiraldo): confirm if these checks are really necessary, remove if not
+ local python_include="$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc());')"
+ if [ "$python_include" == "" ]; then
+ echo -e "\n\nERROR: Problem getting python include path. Is distutils installed?"
+ exit 1
+ fi
+
if [ -z "$PYTHON_LIB_PATH" ]; then
local python_lib_path
# Split python_path into an array of paths, this allows path containing spaces
@@ -131,12 +149,35 @@ function setup_python {
exit 1
fi
+ local numpy_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import numpy; print(numpy.get_include());')
+ if [ "$numpy_include" == "" ]; then
+ echo -e "\n\nERROR: Problem getting numpy include path. Is numpy installed?"
+ exit 1
+ fi
+
+ for x in $EXPECTED_PATHS; do
+ if [ -e "$x" ]; then
+ rm -rf "$x"
+ fi
+ done
+
+# ln -sf is actually implemented as copying in msys since creating symbolic
+# links is privileged on Windows. But copying is too slow, so invoke mklink
+# to create junctions on Windows.
+ if is_windows; then
+ cmd /c "mklink /J util\\python\\python_include \"${python_include}\""
+ cmd /c "mklink /J util\\python\\python_lib \"${python_lib}\""
+ cmd /c "mklink /J third_party\\py\\numpy\\numpy_include \"${numpy_include}\""
+ else
+ ln -sf "${python_include}" util/python/python_include
+ ln -sf "${python_lib}" util/python/python_lib
+ ln -sf "${numpy_include}" third_party/py/numpy/numpy_include
+ fi
# Convert python path to Windows style before writing into bazel.rc
if is_windows; then
PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")"
fi
- # TODO(ngiraldo): move all below to root configure
# Write tools/bazel.rc
echo "# Autogenerated by configure: DO NOT EDIT" > tools/bazel.rc
sed -e "s/\$PYTHON_MAJOR_VERSION/$python_major_version/g" \
@@ -156,4 +197,29 @@ function is_windows() {
fi
}
+function check_python {
+ for x in $EXPECTED_PATHS; do
+ if [ ! -e "$x" ]; then
+ echo -e "\n\nERROR: Cannot find '${x}'. Did you run configure?\n\n" 1>&2
+ exit 1
+ fi
+ # Don't check symbolic link on Windows
+ if ! is_windows && [ ! -L "${x}" ]; then
+ echo -e "\n\nERROR: '${x}' is not a symbolic link. Internal error.\n\n" 1>&2
+ exit 1
+ fi
+ if is_windows; then
+ # In msys, readlink <path> doesn't work, because no symbolic link on
+ # Windows. readlink -f <path> returns the real path of a junction.
+ true_path=$(readlink -f "${x}")
+ else
+ true_path=$(readlink "${x}")
+ fi
+ if [ ! -d "${true_path}" ]; then
+ echo -e "\n\nERROR: '${x}' does not refer to an existing directory: ${true_path}. Do you need to rerun configure?\n\n" 1>&2
+ exit 1
+ fi
+ done
+}
+
main "$@"