diff --git a/CMakeLists.txt b/CMakeLists.txt index b174831109372cb014741d63032fa6a470e74042..236363944e1c3e2d3a828ccafced69dae5ab7810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF) option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF) option(GLIDE_INSTALL "Download and install go dependencies " ON) option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF) +option(UNITTEST_USE_VIRTUALENV "Python unittest with virtualenv" ON) # CMAKE_BUILD_TYPE if(NOT CMAKE_BUILD_TYPE) diff --git a/cmake/external/python.cmake b/cmake/external/python.cmake index 67a359d4b5f4cca8fc8e74eab4d4acb4cc12baed..490c87d67ed79a238dd506127cd4d9855fab6626 100644 --- a/cmake/external/python.cmake +++ b/cmake/external/python.cmake @@ -24,7 +24,6 @@ IF(WITH_PYTHON) ENDIF(WITH_PYTHON) SET(py_env "") -SET(USE_VIRTUALENV_FOR_TEST 1) IF(PYTHONINTERP_FOUND) find_python_module(pip REQUIRED) find_python_module(numpy REQUIRED) diff --git a/cmake/util.cmake b/cmake/util.cmake index 87ad9d91d8701c56255c1e7f224764998df634a7..9790016df98411dcae25f2f3f1aa23f606a8726c 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -150,9 +150,19 @@ 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 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}) + if (UNITTEST_USE_VIRTUALENV) + add_test(NAME ${TEST_NAME} + COMMAND env PADDLE_PACKAGE_DIR=${PADDLE_PYTHON_PACKAGE_DIR} + bash ${PROJ_ROOT}/paddle/scripts/run_python_tests.sh ${ARGN} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + else() + foreach(arg ${ARGN}) + get_filename_component(py_fn ${arg} NAME_WE) + set(TRG_NAME ${TEST_NAME}_${py_fn}) + add_test(NAME ${TRG_NAME} + COMMAND env PYTHONPATH=${PADDLE_PYTHON_PACKAGE_DIR} + python2 ${arg} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endforeach() + endif() endfunction() diff --git a/paddle/.set_python_path.sh b/paddle/.set_python_path.sh index fa7baccc86e0b56e57d52a40c95cfe1b98fececc..8fd58925ee4820269572176ff9496f42914652da 100755 --- a/paddle/.set_python_path.sh +++ b/paddle/.set_python_path.sh @@ -21,22 +21,15 @@ # # It same as PYTHONPATH=${YOUR_PYTHON_PATH}:$PYTHONPATH {exec...} # - -if ! python -c "import paddle" >/dev/null 2>/dev/null; then - PYPATH="" - set -x - while getopts "d:" opt; do - case $opt in - d) - PYPATH=$OPTARG - ;; - esac - done - shift $(($OPTIND - 1)) - export PYTHONPATH=$PYPATH:$PYTHONPATH - $@ -else - echo "paddle package is already in your PYTHONPATH. But unittest need a clean environment." - echo "Please uninstall paddle package before start unittest. Try to 'pip uninstall paddle'" - exit 1 -fi +PYPATH="" +set -x +while getopts "d:" opt; do + case $opt in + d) + PYPATH=$OPTARG + ;; + esac +done +shift $(($OPTIND - 1)) +export PYTHONPATH=$PYPATH:$PYTHONPATH +$@ diff --git a/paddle/scripts/docker/build.sh b/paddle/scripts/docker/build.sh index 8de0e608c1f482e4553c07ff7ffd572d65a772aa..f50b793bf5e7bbb9e239287aee3277f2de8fb96b 100644 --- a/paddle/scripts/docker/build.sh +++ b/paddle/scripts/docker/build.sh @@ -49,29 +49,27 @@ cmake .. \ -DCUDNN_ROOT=/usr/ \ -DWITH_STYLE_CHECK=${WITH_STYLE_CHECK:-OFF} \ -DWITH_TESTING=${WITH_TESTING:-OFF} \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DUNITTEST_USE_VIRTUALENV=OFF cat < /dev/null SCRIPTPATH=$PWD popd > /dev/null -USE_VIRTUALENV_FOR_TEST=$1; shift -PYTHON=$1; shift - -if [ $USE_VIRTUALENV_FOR_TEST -ne 0 ]; then - rm -rf .test_env - virtualenv .test_env - unset PYTHONHOME - unset PYTHONPATH - source .test_env/bin/activate - PYTHON=python -fi +rm -rf .test_env +virtualenv .test_env +unset PYTHONHOME +unset PYTHONPATH +source .test_env/bin/activate +PYTHON=python $PYTHON -m pip install $SCRIPTPATH/../dist/*.whl @@ -49,7 +44,5 @@ do fi done -if [ $USE_VIRTUALENV_FOR_TEST -ne 0 ]; then - deactivate - rm -rf .test_env -fi +deactivate +rm -rf .test_env diff --git a/paddle/setup.py.in b/paddle/setup.py.in index 06d55d3abc6097fa7d4b2b2ac9e29681e0fddfd5..31c9329f6a65f22b01d9a42a5cea2ce69641c583 100644 --- a/paddle/setup.py.in +++ b/paddle/setup.py.in @@ -22,7 +22,7 @@ setup(name="py_paddle", package_data={'py_paddle':['*.py','_swig_paddle.so']}, install_requires = [ 'nltk>=3.2.2', - 'numpy>=1.8.0', # The numpy is required. + 'numpy>=1.12.0', # The numpy is required. 'protobuf==${PROTOBUF_VERSION}' # The paddle protobuf version ], url='http://www.paddlepaddle.org/', diff --git a/python/setup.py.in b/python/setup.py.in index 65a26940d4d703ea4fbb5022523a90716982ec10..7808238aa6ba5ca5c13292638f1c513f87cc2af2 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -14,7 +14,7 @@ packages=['paddle', 'paddle.v2.framework.proto'] setup_requires=["requests", - "numpy", + "numpy>=1.12", "protobuf==3.1", "recordio", "matplotlib",