QPIDIT-135: Added check for Python3 availability, disable Python3 shims when not present
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e3c33b..790d7d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,9 +36,12 @@
# Find Python 2.7.x install path
find_package( PythonInterp 2.7 REQUIRED )
-execute_process(COMMAND ${CMAKE_SOURCE_DIR}/get-python-dir-name
- OUTPUT_VARIABLE PYTHON_DIR_NAME)
-message(STATUS "Python install directory name: ${PYTHON_DIR_NAME}")
+execute_process(COMMAND ${CMAKE_SOURCE_DIR}/get-python-dir-name 2
+ OUTPUT_VARIABLE PYTHON2_DIR_NAME)
+message(STATUS "Python 2 install directory name: ${PYTHON2_DIR_NAME}")
+execute_process(COMMAND ${CMAKE_SOURCE_DIR}/get-python-dir-name 3
+ OUTPUT_VARIABLE PYTHON3_DIR_NAME)
+message(STATUS "Python 3 install directory name: ${PYTHON3_DIR_NAME}")
# Find Java
@@ -126,7 +129,7 @@
add_subdirectory(docs)
# Install files using python setup.py
-install(CODE "MESSAGE(STATUS \"Python install dir: ${CMAKE_INSTALL_PREFIX}/lib/${PYTHON_DIR_NAME}/site-packages/qpid_interop_test/\")")
+install(CODE "MESSAGE(STATUS \"Python install dir: ${CMAKE_INSTALL_PREFIX}/lib/${PYTHON2_DIR_NAME}/site-packages/qpid_interop_test/\")")
install(CODE "execute_process(COMMAND python setup.py install --prefix ${CMAKE_INSTALL_PREFIX}
WORKING_DIRECTORY ../)")
@@ -134,6 +137,6 @@
# Find a way to handle this as part of the Python install process instead
# Set the following Python scripts to executable:
install(CODE "execute_process(COMMAND bash -c \"chmod +x *_test.py\"
- WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/${PYTHON_DIR_NAME}/site-packages/qpid_interop_test/)")
+ WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/${PYTHON2_DIR_NAME}/site-packages/qpid_interop_test/)")
configure_file(config.sh.in config.sh)
diff --git a/config.sh.in b/config.sh.in
index dff4634..f7bd3c2 100644
--- a/config.sh.in
+++ b/config.sh.in
@@ -19,8 +19,13 @@
export QPID_INTEROP_TEST_HOME=@CMAKE_SOURCE_DIR@
export QIT_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@
CURRENT_PYTHONPATH=$PYTHONPATH
-export PYTHONPATH=@CMAKE_INSTALL_PREFIX@/lib64/proton/bindings/python:@CMAKE_INSTALL_PREFIX@/lib/@PYTHON_DIR_NAME@/site-packages:@CMAKE_INSTALL_PREFIX@/libexec/qpid_interop_test/shims/qpid-proton-python:$CURRENT_PYTHONPATH
-CURRENT_PYTHON3PATH=$PYTHON3PATH
-export PYTHON3PATH=@CMAKE_INSTALL_PREFIX@/lib64/proton/bindings/python3:@CMAKE_INSTALL_PREFIX@/lib/@PYTHON_DIR_NAME@/site-packages:@CMAKE_INSTALL_PREFIX@/libexec/qpid_interop_test/shims/qpid-proton-python:$CURRENT_PYTHON3PATH
+export PYTHONPATH=@CMAKE_INSTALL_PREFIX@/lib64/proton/bindings/python:@CMAKE_INSTALL_PREFIX@/lib/@PYTHON2_DIR_NAME@/site-packages:@CMAKE_INSTALL_PREFIX@/libexec/qpid_interop_test/shims/qpid-proton-python:$CURRENT_PYTHONPATH
+if [[ "@PYTHON3_DIR_NAME@" == "NOT_FOUND" ]]; then
+ unset PYTHON3PATH
+ echo "No Python 3.x found, Python 3 shims disabled"
+else
+ CURRENT_PYTHON3PATH=$PYTHON3PATH
+ export PYTHON3PATH=@CMAKE_INSTALL_PREFIX@/lib64/proton/bindings/python3:@CMAKE_INSTALL_PREFIX@/lib/@PYTHON3_DIR_NAME@/site-packages:@CMAKE_INSTALL_PREFIX@/libexec/qpid_interop_test/shims/qpid-proton-python:$CURRENT_PYTHON3PATH
+fi
export LD_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@/lib64:$LD_LIBRARY_PATH
export PATH=@CMAKE_INSTALL_PREFIX@/lib/@PYTHON_DIR_NAME@/site-packages/qpid_interop_test:$PATH
diff --git a/get-python-dir-name b/get-python-dir-name
index e7515e6..8d971d8 100755
--- a/get-python-dir-name
+++ b/get-python-dir-name
@@ -15,5 +15,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-PYTHON_DIR=`ls -d /usr/lib/python2*`
-echo -n ${PYTHON_DIR##*/}
+# $1: Python major version, either 2 or 3
+
+if [[ $# != 1 ]]; then
+ echo "Python major ver required as parameter"
+ exit 1
+fi
+PYTHON_DIR=`ls -d /usr/lib/python${1}* 2> /dev/null`
+if [[ $? == 0 ]]; then
+ echo -n ${PYTHON_DIR##*/}
+else
+ echo -n "NOT_FOUND"
+fi
diff --git a/src/python/qpid_interop_test/qit_common.py b/src/python/qpid_interop_test/qit_common.py
index 6091a33..9921675 100644
--- a/src/python/qpid_interop_test/qit_common.py
+++ b/src/python/qpid_interop_test/qit_common.py
@@ -37,6 +37,7 @@
if QIT_INSTALL_PREFIX is None:
print('ERROR: Environment variable QIT_INSTALL_PREFIX is not set')
sys.exit(1)
+QIT_ENABLE_PYTHON3_SHIM = getenv('PYTHON3PATH') is not None
QIT_TEST_SHIM_HOME = path.join(QIT_INSTALL_PREFIX, 'libexec', 'qpid_interop_test', 'shims')
QPID_JMS_SHIM_VER = '0.2.0'
@@ -320,9 +321,12 @@
qpid_interop_test.qit_shim.ProtonCppShim(proton_cpp_snd_shim, proton_cpp_rcv_shim),
qpid_interop_test.qit_shim.ProtonPython2Shim.NAME: \
qpid_interop_test.qit_shim.ProtonPython2Shim(proton_python_snd_shim, proton_python_rcv_shim),
- qpid_interop_test.qit_shim.ProtonPython3Shim.NAME: \
- qpid_interop_test.qit_shim.ProtonPython3Shim(proton_python_snd_shim, proton_python_rcv_shim),
+# qpid_interop_test.qit_shim.ProtonPython3Shim.NAME: \
+# qpid_interop_test.qit_shim.ProtonPython3Shim(proton_python_snd_shim, proton_python_rcv_shim),
}
+ if QIT_ENABLE_PYTHON3_SHIM:
+ self.shim_map[qpid_interop_test.qit_shim.ProtonPython3Shim.NAME] = \
+ qpid_interop_test.qit_shim.ProtonPython3Shim(proton_python_snd_shim, proton_python_rcv_shim)
# Add shims that need detection during installation only if the necessary bits are present
# Rhea Javascript client