From e49ca3b64d08582f69bfb2eef3a3304bc1989655 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Tue, 2 Apr 2024 16:24:14 -0500 Subject: [PATCH] add cmake and enable testing --- .github/workflows/pull_request.yaml | 40 ++++++++++++++ CMakeLists.txt | 81 +++++++++++++++++++++++++++++ cmake/get_nwx_cmake.cmake | 31 +++++++++++ src/pluginplayer/plugin_player.py | 10 ++-- src/pluginplayer/tree_manager.py | 4 +- tests/pluginplayer_shell.py | 4 +- tests/test_pluginplayer.py | 5 +- 7 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/get_nwx_cmake.cmake diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 19e1608..2d9bbc4 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -29,3 +29,43 @@ jobs: compilers: '' doc_target: 'sphinx' secrets: inherit + + # PluginPlayer needs pluginplay_examples, which means PluginPlays test have to + # be built. This means that CTest will run both PluginPlayer's and + # PluginPlay's tests, which is not desired. For now, I'm running this job to + # test PluginPlayer using ctest -R to limit the tests. + # TODO: Either refactor the test to not need pluginplay_examples, refactor + # PluginPlay so that pluginplay_examples can be build without the tests, + # or refactor the common workflow to allow for regex specification. + test_library: + needs: Common-Pull-Request + runs-on: ubuntu-latest + container: + image: ghcr.io/nwchemex/nwx_buildenv:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.CONTAINER_REPO_TOKEN }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set ownership + run: | + # Fix for git not liking owner of the checkout dir + chown -R $(id -u):$(id -g) $PWD + - name: Build and Test + env: + CMAIZE_GITHUB_TOKEN: ${{secrets.CMAIZE_GITHUB_TOKEN}} + run: | + toolchain=/toolchains/nwx_gcc-11.cmake + echo 'set(CMAIZE_GITHUB_TOKEN '${CMAIZE_GITHUB_TOKEN}')' >> $toolchain + + cmake -Bbuild -H. -GNinja \ + -DCMAKE_INSTALL_PREFIX=./install \ + -DCMAKE_TOOLCHAIN_FILE="${toolchain}" + + cmake --build build --parallel + + cd build + OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 ctest -VV -R pluginplayer + shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..aa9d3ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,81 @@ +# Copyright 2022 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.14) + +#Downloads common CMake modules used throughout NWChemEx +include(cmake/get_nwx_cmake.cmake) + +#Sets the version to whatever git thinks it is +include(get_version_from_git) +get_version_from_git(pluginplayer_version "${CMAKE_CURRENT_LIST_DIR}") +project(pluginplayer VERSION "${pluginplayer_version}" LANGUAGES CXX) + +include(nwx_versions) +include(get_cmaize) +include(nwx_cxx_api_docs) + +### Files and Paths ### +set(python_src_directory "${CMAKE_CURRENT_LIST_DIR}/src/") + +# # Doxygen docs +nwx_cxx_api_docs("${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/include") + +### Options ### +cmaize_option_list( + BUILD_TESTING OFF "Should we build the tests?" +) + +### Tests need PluginPlay examples ## +if("${BUILD_TESTING}") + set(PP_BUILD_TARGETS pluginplay pluginplay_examples) + set(PP_FIND_TARGETS nwx::pluginplay nwx::pluginplay_depends) + set(PP_BUILD_TESTS ON) +else() + set(PP_BUILD_TARGETS pluginplay) + set(PP_FIND_TARGETS nwx::pluginplay) + set(PP_BUILD_TESTS OFF) +endif() + +## Build FriendZone's dependencies ## +cmaize_find_or_build_dependency( + pluginplay + URL github.com/NWChemEx/PluginPlay + VERSION ${NWX_PLUGINPLAY_VERSION} + BUILD_TARGET ${PP_BUILD_TARGETS} + FIND_TARGET ${PP_FIND_TARGETS} + CMAKE_ARGS BUILD_TESTING=${PP_BUILD_TESTS} + BUILD_PYBIND11_PYBINDINGS=ON +) + +#TOOD: Replace cmaize_add_library when it supports Python +add_library(${PROJECT_NAME} INTERFACE) +target_link_libraries(${PROJECT_NAME} INTERFACE pluginplay) + +if("${BUILD_TESTING}") + include(CTest) + include(nwx_pybind11) + set(PYTHON_TEST_DIR "${CMAKE_CURRENT_LIST_DIR}/tests") + + nwx_pybind11_tests( + py_${PROJECT_NAME} + "${PYTHON_TEST_DIR}/test_pluginplayer.py" + SUBMODULES pluginplay_examples pluginplay parallelzone + ) +endif() + +install( + DIRECTORY "${python_src_directory}/pluginplayer" + DESTINATION "${NWX_MODULE_DIRECTORY}" +) diff --git a/cmake/get_nwx_cmake.cmake b/cmake/get_nwx_cmake.cmake new file mode 100644 index 0000000..c99674d --- /dev/null +++ b/cmake/get_nwx_cmake.cmake @@ -0,0 +1,31 @@ +# Copyright 2024 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include_guard() + +macro(get_nwx_cmake) + include(FetchContent) + FetchContent_Declare( + nwx_cmake + GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake + ) + FetchContent_MakeAvailable(nwx_cmake) + set( + CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${nwx_cmake_SOURCE_DIR}/cmake" + CACHE STRING "" + FORCE + ) +endmacro() + +get_nwx_cmake() diff --git a/src/pluginplayer/plugin_player.py b/src/pluginplayer/plugin_player.py index fc981b3..816f4d8 100644 --- a/src/pluginplayer/plugin_player.py +++ b/src/pluginplayer/plugin_player.py @@ -19,11 +19,11 @@ #helper classes for a PluginPlayer interface import pluginplay as pp -from plugin_manager import PluginManager -from tree_manager import TreeManager -from node_widget_manager import NodeWidgetManager -from node_manager import NodeManager -from utility_manager import UtilityManager +from pluginplayer.plugin_manager import PluginManager +from pluginplayer.tree_manager import TreeManager +from pluginplayer.node_widget_manager import NodeWidgetManager +from pluginplayer.node_manager import NodeManager +from pluginplayer.utility_manager import UtilityManager #kivy helpers from kivy.app import App diff --git a/src/pluginplayer/tree_manager.py b/src/pluginplayer/tree_manager.py index 209516d..6c25643 100644 --- a/src/pluginplayer/tree_manager.py +++ b/src/pluginplayer/tree_manager.py @@ -28,7 +28,9 @@ """ #helper widget classes for a draggable widget representing a module -from node_widget import DraggableImageButton, DraggableWidget, ModuleNode +from pluginplayer.node_widget import DraggableImageButton +from pluginplayer.node_widget import DraggableWidget +from pluginplayer.node_widget import ModuleNode #kivy helpers from kivy.uix.button import Button diff --git a/tests/pluginplayer_shell.py b/tests/pluginplayer_shell.py index 36010d3..6f771f4 100644 --- a/tests/pluginplayer_shell.py +++ b/tests/pluginplayer_shell.py @@ -15,9 +15,9 @@ #pluginplay helpers import pluginplay as pp import pluginplay_examples as ppe -from plugin_manager import PluginInfo +from pluginplayer.plugin_manager import PluginInfo +from pluginplayer.plugin_player import PluginPlayer from unittest.mock import MagicMock -from plugin_player import PluginPlayer class PluginPlayerShell: diff --git a/tests/test_pluginplayer.py b/tests/test_pluginplayer.py index fd84dc1..15fead2 100644 --- a/tests/test_pluginplayer.py +++ b/tests/test_pluginplayer.py @@ -23,8 +23,9 @@ rv = pz.runtime.RuntimeView() my_dir = os.path.dirname(os.path.realpath(__file__)) - root_dir = os.path.dirname(os.path.dirname(os.path.dirname(my_dir))) - src_dir = os.path.join(root_dir, 'tests') + root_dir = os.path.dirname(my_dir) + src_dir = os.path.join(root_dir, 'src') + print(src_dir) sys.path.append(src_dir) loader = unittest.TestLoader()