Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make python component part of build, not install #524

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,35 @@ file( COPY ncepbufr utils DESTINATION . )

# Library installation directory
set(_PYVER "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}")
set(_install_dir "${CMAKE_INSTALL_FULL_LIBDIR}/python${_PYVER}/site-packages")
set(_build_dir "${CMAKE_CURRENT_BINARY_DIR}/site-packages")

# Build the extension module for use in install tree
install(CODE "message(\"Building Python extension modules:
${Python3_EXECUTABLE} setup.py build\")
execute_process(COMMAND ${Python3_EXECUTABLE} setup.py build
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
add_custom_target(python_mod ALL)
add_dependencies(python_mod bufr_4)

# Call distutils for installation
install(CODE "if( NOT \$ENV{DESTDIR} STREQUAL \"\" )
set( __root \"--root=\$ENV{DESTDIR}\" )
endif()
message(\"Installing Python modules:
${Python3_EXECUTABLE} setup.py install \${__root}
--install-lib=${_install_dir}
--prefix=${CMAKE_INSTALL_PREFIX}
--record=${CMAKE_BINARY_DIR}/extra_install.txt\")
execute_process(COMMAND ${Python3_EXECUTABLE} setup.py install
\${__root}
--prefix=${CMAKE_INSTALL_PREFIX}
--install-lib=${_install_dir}
--record=${CMAKE_BINARY_DIR}/extra_install.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
if( NOT \$ENV{DESTDIR} STREQUAL \"\" )
set( __root \"--root=\$ENV{DESTDIR}\" )
endif()
add_custom_command(
TARGET python_mod
COMMAND ${Python3_EXECUTABLE} setup.py install
\${__root}
--prefix=${CMAKE_INSTALL_PREFIX}
--install-lib=${_build_dir}
--record=${CMAKE_BINARY_DIR}/extra_install.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS setup.py.in
)

if(ENABLE_DOCS)
# Uses pdoc (https://github.com/BurntSushi/pdoc)
find_program(PDOC_EXECUTABLE pdoc REQUIRED)
install(CODE "message(\"Building Python API documentation:
${PDOC_EXECUTABLE} -o ../docs/html/python' ./ncepbufr\")
set(ENV{PYTHONPATH} ${_install_dir})
execute_process(COMMAND ${PDOC_EXECUTABLE} -o ../docs/html/python ./ncepbufr
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
set(ENV{PYTHONPATH} ${_build_dir})
add_custom_command(COMMAND ${PDOC_EXECUTABLE} -o ../docs/html/python ./ncepbufr WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()

install(DIRECTORY ${_build_dir} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/python${_PYVER})

# Add tests
add_test(NAME test_pyncepbufr_checkpoint
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_checkpoint.py
Expand Down Expand Up @@ -81,5 +76,5 @@ list(APPEND _python_tests test_pyncepbufr_test)

foreach(_test ${_python_tests})
set_tests_properties(${_test}
PROPERTIES ENVIRONMENT "PYTHONPATH=${_install_dir}:$ENV{PYTHONPATH}")
PROPERTIES ENVIRONMENT "PYTHONPATH=${_build_dir}:$ENV{PYTHONPATH}")
endforeach()