blob: a52f6f70306fec0f04f6e19e523bb7b65c6acba4 [file] [log] [blame]
Vijay Vasudevanbf6b5362015-12-02 15:04:40 -08001#!/bin/bash
2
3set -e -o errexit
4
5EXPECTED_PATHS="util/python/python_include util/python/python_lib third_party/py/numpy/numpy_include"
6
7function main {
8 argument="$1"
9 shift
10 case $argument in
11 --check)
12 check_python
13 exit 0
14 ;;
15 --setup)
16 setup_python "$1"
17 exit 0
18 ;;
19 esac
20}
21
22function setup_python {
23 PYTHON_BIN_PATH="$1";
24
25 if [ -z "$PYTHON_BIN_PATH" ]; then
26 echo "PYTHON_BIN_PATH was not provided. Did you run configure?"
27 exit 1
28 fi
29 if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then
30 echo "PYTHON_BIN_PATH is not executable. Is it the python binary?"
31 exit 1
32 fi
33
34 local python_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc());')
35 if [ "$python_include" == "" ]; then
36 echo -e "\n\nERROR: Problem getting python include path. Is distutils installed?"
37 exit 1
38 fi
39 local python_lib=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_lib());')
40 if [ "$python_lib" == "" ]; then
41 echo -e "\n\nERROR: Problem getting python lib path. Is distutils installed?"
42 exit 1
43 fi
44 local numpy_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import numpy; print(numpy.get_include());')
45 if [ "$numpy_include" == "" ]; then
46 echo -e "\n\nERROR: Problem getting numpy include path. Is numpy installed?"
47 exit 1
48 fi
49
50 for x in $EXPECTED_PATHS; do
51 if [ -e "$x" ]; then
52 rm "$x"
53 fi
54 done
55
56 ln -s "${python_include}" util/python/python_include
57 ln -s "${python_lib}" util/python/python_lib
58 ln -s "${numpy_include}" third_party/py/numpy/numpy_include
59}
60
61function check_python {
62 for x in $EXPECTED_PATHS; do
63 if [ ! -e "$x" ]; then
64 echo -e "\n\nERROR: Cannot find '${x}'. Did you run configure?\n\n" 1>&2
65 exit 1
66 fi
67 if [ ! -L "${x}" ]; then
68 echo -e "\n\nERROR: '${x}' is not a symbolic link. Internal error.\n\n" 1>&2
69 exit 1
70 fi
71 true_path=$(readlink "${x}")
72 if [ ! -d "${true_path}" ]; then
73 echo -e "\n\nERROR: '${x}' does not refer to an existing directory: ${true_path}. Do you need to rerun configure?\n\n" 1>&2
74 exit 1
75 fi
76 done
77}
78
79main "$@"