From 19127b479c40d5f00c4310eb44e2888f52c65978 Mon Sep 17 00:00:00 2001
From: Yu Yang <yuyang18@baidu.com>
Date: Thu, 25 May 2017 12:16:56 +0800
Subject: [PATCH] Fix bug in run_python_tests.sh

* Also, test_plot cannot run in MacOS because of matplotlib & ipython's
  limit.
* Add missing dependency in setup.py.
* fix #2264
---
 cmake/util.cmake                           | 5 +++--
 paddle/scripts/run_python_tests.sh         | 9 +++++++--
 python/CMakeLists.txt                      | 4 +++-
 python/paddle/v2/plot/tests/CMakeLists.txt | 6 +++++-
 python/setup.py.in                         | 1 +
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/cmake/util.cmake b/cmake/util.cmake
index b828eef322b..8c914346222 100644
--- a/cmake/util.cmake
+++ b/cmake/util.cmake
@@ -149,8 +149,9 @@ endfunction()
 # Create a python unittest using run_python_tests.sh,
 # which takes care of making correct running environment
 function(add_python_test TEST_NAME)
-    add_test(NAME ${TEST_NAME}
-        COMMAND bash ${PROJ_ROOT}/paddle/scripts/run_python_tests.sh
+  add_test(NAME ${TEST_NAME}
+        COMMAND env PADDLE_PACKAGE_DIR=${PADDLE_PYTHON_PACKAGE_DIR}
+        bash ${PROJ_ROOT}/paddle/scripts/run_python_tests.sh
         ${USE_VIRTUALENV_FOR_TEST} ${PYTHON_EXECUTABLE} ${ARGN}
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 endfunction()
diff --git a/paddle/scripts/run_python_tests.sh b/paddle/scripts/run_python_tests.sh
index 02d2cdb9774..6dfc05a9497 100755
--- a/paddle/scripts/run_python_tests.sh
+++ b/paddle/scripts/run_python_tests.sh
@@ -28,8 +28,13 @@ if [ $USE_VIRTUALENV_FOR_TEST -ne 0 ]; then
    PYTHON=python
 fi
 
-export PYTHONPATH=$SCRIPTPATH/../../python/
-$PYTHON -m pip install $SCRIPTPATH/../dist/*.whl requests matplotlib opencv-python ipython==5.3
+$PYTHON -m pip install $SCRIPTPATH/../dist/*.whl
+
+if [ "X${PADDLE_PACKAGE_DIR}" != "X" ]; then
+   $PYTHON -m pip install ${PADDLE_PACKAGE_DIR}/*.whl
+fi
+
+$PYTHON -m pip install ipython==5.3
 
 for fn in "$@"
 do
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index bfa19d5ecc8..4f52f0f6cfd 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -23,7 +23,9 @@ add_custom_command(OUTPUT ${OUTPUT_DIR}/.timestamp
 add_custom_target(paddle_python ALL DEPENDS
     ${OUTPUT_DIR}/.timestamp)
 
+set(PADDLE_PYTHON_PACKAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dist/)
 add_subdirectory(paddle/trainer_config_helpers/tests)
+
 if (WITH_SWIG_PY)
   # enable v2 API unittest only when paddle swig api is compiled
   add_subdirectory(paddle/v2/tests)
@@ -31,6 +33,6 @@ if (WITH_SWIG_PY)
   add_subdirectory(paddle/v2/plot/tests)
 endif()
 
-install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/
+install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}
     DESTINATION opt/paddle/share/wheels
 )
diff --git a/python/paddle/v2/plot/tests/CMakeLists.txt b/python/paddle/v2/plot/tests/CMakeLists.txt
index b1132f13173..da5cd764889 100644
--- a/python/paddle/v2/plot/tests/CMakeLists.txt
+++ b/python/paddle/v2/plot/tests/CMakeLists.txt
@@ -1 +1,5 @@
-add_python_test(test_ploter test_ploter.py)
+if (NOT APPLE)
+  # The Mac OS X backend will not be able to function correctly if Python is
+  # not installed as a framework.
+  add_python_test(test_ploter test_ploter.py)
+endif()
diff --git a/python/setup.py.in b/python/setup.py.in
index 5dfb46192ae..d7472884344 100644
--- a/python/setup.py.in
+++ b/python/setup.py.in
@@ -18,6 +18,7 @@ setup(name='paddle',
           "numpy",
           "protobuf==${PROTOBUF_VERSION}",
           "matplotlib",
+          "opencv-python"
       ],
       packages=packages,
       package_dir={
-- 
GitLab