Skip to content

Commit

Permalink
add cmake and enable testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaldrop107 committed Apr 2, 2024
1 parent 74757d8 commit e49ca3b
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
81 changes: 81 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}"
)
31 changes: 31 additions & 0 deletions cmake/get_nwx_cmake.cmake
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 5 additions & 5 deletions src/pluginplayer/plugin_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/pluginplayer/tree_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/pluginplayer_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_pluginplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e49ca3b

Please sign in to comment.