From b6d25f6102f8097813a80d03ba7524ade5871fbc Mon Sep 17 00:00:00 2001 From: "Ryan M. Richard" Date: Sun, 10 Nov 2024 22:18:22 -0600 Subject: [PATCH] documentation and fix CI? --- .github/workflows/build_plugin_template.yaml | 9 ++++- .../CMakeLists.txt | 27 +++++++-------- .../cmake/get_cmake_modules.cmake | 5 ++- .../{{ cookiecutter.project_slug }}.hpp | 2 +- ...export_{{ cookiecutter.project_slug }}.cpp | 0 .../{{ cookiecutter.project_slug }}_mm.cpp | 9 +++-- .../test_{{ cookiecutter.project_slug }}.py | 16 --------- .../__init__.py | 0 .../test_example.py | 11 ++++++- .../test_{{ cookiecutter.project_slug }}.py | 33 +++++++++++++++++++ 10 files changed, 69 insertions(+), 43 deletions(-) rename {{ cookiecutter.project_slug }}/src/{{{ cookiecutter.project_slug }} => }/python/export_{{ cookiecutter.project_slug }}.cpp (100%) delete mode 100644 {{ cookiecutter.project_slug }}/tests/integration_tests/test_{{ cookiecutter.project_slug }}.py rename {{ cookiecutter.project_slug }}/tests/integration_tests/{ => {{cookiecutter.project_slug}}}/py_{{ cookiecutter.project_slug }}/__init__.py (100%) rename {{ cookiecutter.project_slug }}/tests/integration_tests/{ => {{cookiecutter.project_slug}}}/py_{{ cookiecutter.project_slug }}/test_example.py (71%) create mode 100644 {{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/test_{{ cookiecutter.project_slug }}.py diff --git a/.github/workflows/build_plugin_template.yaml b/.github/workflows/build_plugin_template.yaml index f5bf343..e9ae3a7 100644 --- a/.github/workflows/build_plugin_template.yaml +++ b/.github/workflows/build_plugin_template.yaml @@ -9,7 +9,11 @@ on: project_slug: required: false type: string - default: "new_project" + default: "new_plugin" + nwx_cmake: + required: false + type: bool + default: true secrets: CONTAINER_REPO_TOKEN: required: true @@ -49,10 +53,13 @@ jobs: run: | echo "default_context:" > configure.yaml echo " project_name: ${PROJECT_NAME}" >> configure.yaml + echo " project_slug: ${PROJECT_SLUG}" >> configure.yaml + echo " nwx_cmake: ${NWX_CMAKE}" >> configure.yaml shell: bash env: PROJECT_NAME: ${{ inputs.project_name }} PROJECT_SLUG: ${{ inputs.project_slug }} + NWX_CMAKE: ${{ inputs.nwx_cmake }} - name: Test current state run: | diff --git a/{{ cookiecutter.project_slug }}/CMakeLists.txt b/{{ cookiecutter.project_slug }}/CMakeLists.txt index 4309e94..b73ff54 100644 --- a/{{ cookiecutter.project_slug }}/CMakeLists.txt +++ b/{{ cookiecutter.project_slug }}/CMakeLists.txt @@ -4,18 +4,13 @@ cmake_minimum_required(VERSION 3.14) include(cmake/get_cmake_modules.cmake) ## Set Project and Version - -{%- if cookiecutter.nwx_cmake -%} - +{% if cookiecutter.nwx_cmake %} # TODO: Uncomment when you have a git tag #include(get_version_from_git) #get_version_from_git(VERSION "${CMAKE_CURRENT_LIST_DIR}") set(VERSION "0.0.1") # Delete this line if you uncomment line above - -{%- else -%} - -set(VERSION "0.0.1") - +{% else %} +set(VERSION "0.0.1") # Change this to your plugin's actual version {% endif %} project({{ cookiecutter.project_slug }} VERSION "${VERSION}" LANGUAGES CXX) @@ -24,8 +19,7 @@ set(${PROJECT_NAME}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") set(${PROJECT_NAME}_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") set(${PROJECT_NAME}_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests") -{%- if cookiecutter.nwx_cmake -%} - +{% if cookiecutter.nwx_cmake %} include(nwx_versions) {% endif %} include(get_cmaize) @@ -54,8 +48,7 @@ cmaize_add_library( DEPENDS simde ) -{%- if cookiecutter.nwx_cmake -%} - +{% if cookiecutter.nwx_cmake %} include(nwx_pybind11) nwx_add_pybind11_module( ${PROJECT_NAME} @@ -76,16 +69,16 @@ if("${BUILD_TESTING}") VERSION v2.x ) + set(UNIT_TEST_DIR "${${PROJECT_NAME}_TESTS_DIR}/unit_tests") ## Add Tests ## cmaize_add_tests( test_${PROJECT_NAME} - SOURCE_DIR "${${PROJECT_NAME}_TESTS_DIR}/unit_tests/${PROJECT_NAME}" + SOURCE_DIR "${UNIT_TEST_DIR}/${PROJECT_NAME}" INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}" DEPENDS Catch2 ${PROJECT_NAME} ) - {%- if cookiecutter.nwx_cmake -%} - + {% if cookiecutter.nwx_cmake %} if("${INTEGRATION_TESTING}") cmaize_find_or_build_dependency( nwchemex @@ -95,9 +88,11 @@ if("${BUILD_TESTING}") CMAKE_ARGS BUILD_TESTING=OFF ) + + set(INTEGRATION_DIR "${${PROJECT_NAME}_TESTS_DIR}/integration_tests") nwx_pybind11_tests( py_${PROJECT_NAME} - "${${PROJECT_NAME}_TESTS_DIR}/integration_tests/test_${PROJECT_NAME}.py" + "${INTEGRATION_DIR}/${PROJECT_NAME}/test_${PROJECT_NAME}.py" DEPENDS nwchemex SUBMODULES simde chemist pluginplay parallelzone friendzone chemcache nwchemex diff --git a/{{ cookiecutter.project_slug }}/cmake/get_cmake_modules.cmake b/{{ cookiecutter.project_slug }}/cmake/get_cmake_modules.cmake index 2d2f237..613f9d5 100644 --- a/{{ cookiecutter.project_slug }}/cmake/get_cmake_modules.cmake +++ b/{{ cookiecutter.project_slug }}/cmake/get_cmake_modules.cmake @@ -3,7 +3,7 @@ include_guard() macro(get_cmake_modules) include(FetchContent) - {%- if cookiecutter.nwx_cmake -%} + {% if cookiecutter.nwx_cmake %} FetchContent_Declare( nwx_cmake GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake @@ -14,8 +14,7 @@ macro(get_cmake_modules) CACHE STRING "" FORCE ) - {%- else -%} - + {% else %} if("${CMAIZE_VERSION}" STREQUAL "") set(CMAIZE_VERSION v1.1.0 ) endif() diff --git a/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp index f28db52..36ecda2 100644 --- a/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp +++ b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp @@ -1,3 +1,3 @@ #pragma once -#include "{{ cookiecutter.project_slug }}_mm.hpp" +#include <{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp> diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/python/export_{{ cookiecutter.project_slug }}.cpp b/{{ cookiecutter.project_slug }}/src/python/export_{{ cookiecutter.project_slug }}.cpp similarity index 100% rename from {{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/python/export_{{ cookiecutter.project_slug }}.cpp rename to {{ cookiecutter.project_slug }}/src/python/export_{{ cookiecutter.project_slug }}.cpp diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp index 434a850..26b43c8 100644 --- a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp +++ b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp @@ -1,15 +1,14 @@ -#include "{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp" +#include <{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp> namespace {{ cookiecutter.project_slug }} { -inline void set_defaults(pluginplay::ModuleManager& mm) { - // Default submodules between collections can be set here +inline void set_defaults(pluginplay::ModuleManager & mm) { + // Set your modules' default submodules here } DECLARE_PLUGIN({{ cookiecutter.project_slug }}) { - // Add subcollection load calls here + // Add your modules to mm here - // Assign default submodules set_defaults(mm); } diff --git a/{{ cookiecutter.project_slug }}/tests/integration_tests/test_{{ cookiecutter.project_slug }}.py b/{{ cookiecutter.project_slug }}/tests/integration_tests/test_{{ cookiecutter.project_slug }}.py deleted file mode 100644 index 230153b..0000000 --- a/{{ cookiecutter.project_slug }}/tests/integration_tests/test_{{ cookiecutter.project_slug }}.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import parallelzone as pz -import sys -import unittest - -if __name__ == '__main__': - - rv = pz.runtime.RuntimeView() - - my_dir = os.path.dirname(os.path.realpath(__file__)) - - loader = unittest.TestLoader() - tests = loader.discover(my_dir) - testrunner = unittest.runner.TextTestRunner() - ret = not testrunner.run(tests).wasSuccessful() - sys.exit(ret) diff --git a/{{ cookiecutter.project_slug }}/tests/integration_tests/py_{{ cookiecutter.project_slug }}/__init__.py b/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/py_{{ cookiecutter.project_slug }}/__init__.py similarity index 100% rename from {{ cookiecutter.project_slug }}/tests/integration_tests/py_{{ cookiecutter.project_slug }}/__init__.py rename to {{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/py_{{ cookiecutter.project_slug }}/__init__.py diff --git a/{{ cookiecutter.project_slug }}/tests/integration_tests/py_{{ cookiecutter.project_slug }}/test_example.py b/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/py_{{ cookiecutter.project_slug }}/test_example.py similarity index 71% rename from {{ cookiecutter.project_slug }}/tests/integration_tests/py_{{ cookiecutter.project_slug }}/test_example.py rename to {{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/py_{{ cookiecutter.project_slug }}/test_example.py index 8eed752..77ccd5c 100644 --- a/{{ cookiecutter.project_slug }}/tests/integration_tests/py_{{ cookiecutter.project_slug }}/test_example.py +++ b/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/py_{{ cookiecutter.project_slug }}/test_example.py @@ -1,8 +1,14 @@ +""" Example of how to use the full NWX ecosystem in a test. + +In the setUp method for this test we load ALL of the released NWX plugins. We +then load this plugin, i.e., the plugin we are testing. +""" + import nwchemex as nwx import simde import pluginplay import unittest - +import {{ cookiecutter.project_slug }} class AnExampleIntegrationTest(unittest.TestCase): @@ -24,4 +30,7 @@ def testMoleculeFromString(self): def setUp(self): self.mm = pluginplay.ModuleManager() + nwx.load_modules(self.mm) + {{ cookiecutter.project_slug}}.load_modules(self.mm) + diff --git a/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/test_{{ cookiecutter.project_slug }}.py b/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/test_{{ cookiecutter.project_slug }}.py new file mode 100644 index 0000000..6dd9c45 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/tests/integration_tests/{{cookiecutter.project_slug}}/test_{{ cookiecutter.project_slug }}.py @@ -0,0 +1,33 @@ +"""Driver for integration tests. + +This file drives your integration tests. To run the integration tests (assuming +your Python path is setup correctly) simply type: + +.. code-block:: terminal + + python test_{{ cookiecutter.project_slug }}.py + + +The driver assumes that your integration tests live in importable Python +modules next to this file. +""" + +import os +import parallelzone as pz +import sys +import unittest + +if __name__ == '__main__': + + # Ensure a RuntimeView object persists through all tests + rv = pz.runtime.RuntimeView() + + # Works out the path to the directory containing the driver + my_dir = os.path.dirname(os.path.realpath(__file__)) + + #Find and run the tests, then return the result + loader = unittest.TestLoader() + tests = loader.discover(my_dir) + testrunner = unittest.runner.TextTestRunner() + ret = not testrunner.run(tests).wasSuccessful() + sys.exit(ret)