From 6030bcaa6e5676bbcedea230ac00d731a5b800ab Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 27 Apr 2018 15:06:36 +0100 Subject: [PATCH] add PYTHON_STRATEGY=PYTHONPATH, tidy before migration to SIRF --- SuperBuild.cmake | 75 +++++++--------------------- {SuperBuild => cmake}/__init__.py.in | 0 {SuperBuild => cmake}/setup.py.in | 0 setup.py.cmake | 49 ++++++++++++++++++ 4 files changed, 68 insertions(+), 56 deletions(-) rename {SuperBuild => cmake}/__init__.py.in (100%) rename {SuperBuild => cmake}/setup.py.in (100%) create mode 100644 setup.py.cmake diff --git a/SuperBuild.cmake b/SuperBuild.cmake index a51d7320..357212de 100644 --- a/SuperBuild.cmake +++ b/SuperBuild.cmake @@ -184,18 +184,28 @@ set(CCPPETMR_INSTALL ${SUPERBUILD_INSTALL_DIR}) set(ENV_PYTHON_BASH "##### Python not found #####") set(ENV_PYTHON_CSH "##### Python not found #####") if(PYTHONINTERP_FOUND) + set(PYTHON_STRATEGY "PYTHONPATH" CACHE STRING "\ + PYTHONPATH: prefix PYTHONPATH \n\ + SETUP_PY: execute ${PYTHON_EXECUTABLE} setup.py install \n\ + CONDA: do nothing") + set_property(CACHE PYTHON_STRATEGY PROPERTY STRINGS PYTHONPATH SETUP_PY CONDA) + + if("${PYTHON_STRATEGY}" STREQUAL "PYTHONPATH") + set(COMMENT_OUT_PREFIX "") + else() + set(COMMENT_OUT_PREFIX "#") + endif() set (ENV_PYTHON_CSH "\ - if $?PYTHONPATH then \n\ - #setenv PYTHONPATH ${PYTHON_DEST}:$PYTHONPATH \n\ - else \n\ - #setenv PYTHONPATH ${PYTHON_DEST} \n\ - setenv SIRF_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}") + ${COMMENT_OUT_PREFIX}if $?PYTHONPATH then \n\ + ${COMMENT_OUT_PREFIX} setenv PYTHONPATH ${PYTHON_DEST}:$PYTHONPATH \n\ + ${COMMENT_OUT_PREFIX}else \n\ + ${COMMENT_OUT_PREFIX} setenv PYTHONPATH ${PYTHON_DEST} \n\ + setenv SIRF_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}") set (ENV_PYTHON_BASH "\ - #export PYTHONPATH=${PYTHON_DEST}:$PYTHONPATH \n\ - export SIRF_PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}") - + ${COMMENT_OUT_PREFIX}export PYTHONPATH=\"${PYTHON_DEST}\${PYTHONPATH:+:\${PYTHONPATH}}\" \n\ + export SIRF_PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}") endif() set(ENV_MATLAB_BASH "##### Matlab not found #####") @@ -218,54 +228,7 @@ endif() configure_file(env_ccppetmr.sh.in ${CCPPETMR_INSTALL}/bin/env_ccppetmr.sh) configure_file(env_ccppetmr.csh.in ${CCPPETMR_INSTALL}/bin/env_ccppetmr.csh) -# Install python packages via pip and setup.py -if(PYTHONINTERP_FOUND) - set(PYTHON_SETUP_PKGS "sirf" CACHE INTERNAL "list of provided python packages") - - # alias sirf.p* -> p* for backward-compatibility - function(python_pkg_alias PY_PKG_NEW PY_PKG_OLD) - list(APPEND PYTHON_SETUP_PKGS ${PY_PKG_NEW}) - set(PYTHON_SETUP_PKGS "${PYTHON_SETUP_PKGS}" PARENT_SCOPE) - set(SETUP_PY_INIT_IN "${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/__init__.py.in") - set(SETUP_PY_INIT "${PYTHON_DEST}/${PY_PKG_NEW}/__init__.py") - configure_file("${SETUP_PY_INIT_IN}" "${SETUP_PY_INIT}") - # message(STATUS "setup.py:${SETUP_PY_INIT}") - message(STATUS "setup.py:${PY_PKG_NEW}<-${PY_PKG_OLD}") - endfunction(python_pkg_alias) - python_pkg_alias(pGadgetron "sirf.pGadgetron") - python_pkg_alias(pSTIR "sirf.pSTIR") - python_pkg_alias(pUtilities "sirf.pUtilities") - python_pkg_alias(pygadgetron "sirf.pygadgetron") - python_pkg_alias(pystir "sirf.pystir") - python_pkg_alias(pyiutilities "sirf.pyiutilities") - # convert to python CSV tuple for setup.py configure_file - string(REPLACE ";" "', '" PYTHON_SETUP_PKGS_CSV "${PYTHON_SETUP_PKGS}") - set(PYTHON_SETUP_PKGS_CSV "'${PYTHON_SETUP_PKGS_CSV}'") - # message(STATUS "setup.py:pacakges:${PYTHON_SETUP_PKGS_CSV}") - - # Create setup.py - set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/setup.py.in") - set(SETUP_PY "${PYTHON_DEST}/setup.py") - set(SETUP_PY_INIT "${PYTHON_DEST}/sirf/__init__.py") - message(STATUS "setup.py:${SETUP_PY}") - configure_file("${SETUP_PY_IN}" "${SETUP_PY}") - - # python setup.py build - add_custom_command(OUTPUT "${SETUP_PY_INIT}" - COMMAND "${CMAKE_COMMAND}" -E make_directory "${PYTHON_DEST}/sirf" - COMMAND "${CMAKE_COMMAND}" -E touch "${SETUP_PY_INIT}" - COMMAND "${PYTHON_EXECUTABLE}" setup.py build - DEPENDS "${SETUP_PY_IN}" - WORKING_DIRECTORY "${PYTHON_DEST}") - - add_custom_target(pybuild_sirf ALL DEPENDS ${SETUP_PY_INIT}) - - # python setup.py install - install(CODE "execute_process(COMMAND\n\ - \"${PYTHON_EXECUTABLE}\" setup.py install\n\ - WORKING_DIRECTORY \"${PYTHON_DEST}\")") -endif(PYTHONINTERP_FOUND) - +include("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmake") # add tests enable_testing() diff --git a/SuperBuild/__init__.py.in b/cmake/__init__.py.in similarity index 100% rename from SuperBuild/__init__.py.in rename to cmake/__init__.py.in diff --git a/SuperBuild/setup.py.in b/cmake/setup.py.in similarity index 100% rename from SuperBuild/setup.py.in rename to cmake/setup.py.in diff --git a/setup.py.cmake b/setup.py.cmake new file mode 100644 index 00000000..f1f76b9b --- /dev/null +++ b/setup.py.cmake @@ -0,0 +1,49 @@ +# Install python packages via pip and setup.py +if(PYTHONINTERP_FOUND) + set(PYTHON_SETUP_PKGS "sirf" CACHE INTERNAL "list of provided python packages") + + # alias sirf.p* -> p* for backward-compatibility + function(python_pkg_alias PY_PKG_NEW PY_PKG_OLD) + list(APPEND PYTHON_SETUP_PKGS ${PY_PKG_NEW}) + set(PYTHON_SETUP_PKGS "${PYTHON_SETUP_PKGS}" PARENT_SCOPE) + set(SETUP_PY_INIT_IN "${CMAKE_CURRENT_SOURCE_DIR}/cmake/__init__.py.in") + set(SETUP_PY_INIT "${PYTHON_DEST}/${PY_PKG_NEW}/__init__.py") + configure_file("${SETUP_PY_INIT_IN}" "${SETUP_PY_INIT}") + # message(STATUS "setup.py:${SETUP_PY_INIT}") + message(STATUS "setup.py:${PY_PKG_NEW}<-${PY_PKG_OLD}") + endfunction(python_pkg_alias) + python_pkg_alias(pGadgetron "sirf.pGadgetron") + python_pkg_alias(pSTIR "sirf.pSTIR") + python_pkg_alias(pUtilities "sirf.pUtilities") + python_pkg_alias(pygadgetron "sirf.pygadgetron") + python_pkg_alias(pystir "sirf.pystir") + python_pkg_alias(pyiutilities "sirf.pyiutilities") + # convert to python CSV tuple for setup.py configure_file + string(REPLACE ";" "', '" PYTHON_SETUP_PKGS_CSV "${PYTHON_SETUP_PKGS}") + set(PYTHON_SETUP_PKGS_CSV "'${PYTHON_SETUP_PKGS_CSV}'") + # message(STATUS "setup.py:pacakges:${PYTHON_SETUP_PKGS_CSV}") + + # Create setup.py + set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup.py.in") + set(SETUP_PY "${PYTHON_DEST}/setup.py") + set(SETUP_PY_INIT "${PYTHON_DEST}/sirf/__init__.py") + message(STATUS "setup.py:${SETUP_PY}") + configure_file("${SETUP_PY_IN}" "${SETUP_PY}") + + # python setup.py build + add_custom_command(OUTPUT "${SETUP_PY_INIT}" + COMMAND "${CMAKE_COMMAND}" -E make_directory "${PYTHON_DEST}/sirf" + COMMAND "${CMAKE_COMMAND}" -E touch "${SETUP_PY_INIT}" + COMMAND "${PYTHON_EXECUTABLE}" setup.py build + DEPENDS "${SETUP_PY_IN}" + WORKING_DIRECTORY "${PYTHON_DEST}") + + add_custom_target(pybuild_sirf ALL DEPENDS ${SETUP_PY_INIT}) + + # python setup.py install + if("${PYTHON_STRATEGY}" STREQUAL "SETUP_PY") + install(CODE "execute_process(COMMAND\n\ + \"${PYTHON_EXECUTABLE}\" setup.py install\n\ + WORKING_DIRECTORY \"${PYTHON_DEST}\")") + endif() +endif(PYTHONINTERP_FOUND)