-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from NWChemEx/template
Template
- Loading branch information
Showing
15 changed files
with
297 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2023 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. | ||
# | ||
|
||
name: Pull Request Workflow | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
Test-Cookiecutter: | ||
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@v2 | ||
- name: Install cookecutter | ||
run: | | ||
pip install cookiecutter | ||
shell: bash | ||
- name: Install Zip | ||
run: | | ||
apt-get update && apt-get install -y zip | ||
shell: bash | ||
- name: Zip current state | ||
run: | | ||
# From the Cookiecutter docs | ||
(SOURCE_DIR=$(basename $PWD) ZIP=cookiecutter.zip && | ||
pushd .. && | ||
zip -r $ZIP $SOURCE_DIR --exclude $SOURCE_DIR/$ZIP --quiet && | ||
mv $ZIP $SOURCE_DIR/$ZIP && | ||
popd && | ||
echo "Cookiecutter full path: $PWD/$ZIP") | ||
shell: bash | ||
- name: Test current state | ||
run: | | ||
# Generate the template | ||
cookiecutter ./cookiecutter.zip --no-input | ||
cd new_plugin | ||
# Configure, build, and test | ||
cmake -Bbuild -H. \ | ||
-DCMAKE_TOOLCHAIN_FILE=./default_toolchain.cmake \ | ||
-DCMAKE_INSTALL_PREFIX=./install | ||
cmake --build build --parallel | ||
cd build | ||
ctest -VV | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,4 @@ | ||
# These are directories used by IDEs for storing settings | ||
.idea/ | ||
.vscode/ | ||
|
||
# These are common build directory names | ||
build*/ | ||
docs/build | ||
docs/source/_build | ||
docs/doxyoutput | ||
docs/source/api | ||
*-build-*/ | ||
_build/ | ||
Debug/ | ||
Release/ | ||
|
||
# Users commonly store their specific CMake settings in a toolchain file | ||
toolchain.cmake | ||
|
||
# Users often install under the root directory | ||
install/ | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,61 @@ | ||
Plugin Template | ||
=============== | ||
|
||
This repository is intended to be used as a quickstart for writing a plugin | ||
library consistent with [PluginPlay](https://github.com/NWChemEx/PluginPlay). | ||
|
||
## Generating the New Plugin | ||
|
||
This template is generated with the | ||
[Cookiecutter](https://github.com/cookiecutter/cookiecutter) package: | ||
|
||
```bash | ||
# Install cookiecutter, if not already | ||
$ pip install cookiecutter | ||
# Generate the template | ||
$ cookiecutter https://github.com/NWChemEx/PluginTemplate.git | ||
``` | ||
Follow the resulting to prompts to generate your plugin. The resulting directory | ||
will contain the following: | ||
- `version.txt` - Holds the version of the plugin. Used by `CMakeLists.txt`. | ||
- `default_toolchain.cmake` - A simple CMake toolchain. Ignored by Git. | ||
- `include/{plugin_name}/{plugin_name}.hpp` - An initial courtesy header file. | ||
- `include/{plugin_name}/{plugin_name}_mm.hpp` - A header file declaring the plugin. | ||
- `src/{plugin_name}/{plugin_name}_mm.cpp` - A source file defining the the plugin. | ||
- `tests/unit_tests/test_main.cpp` - A main source file for a Catch2 test. | ||
- `tests/unit_tests/test_load_modules.cpp` - A source file for a test of the `load_modules` function. | ||
|
||
These files constitute a bare plugin library and a simple test for the | ||
`load_modules` function. New modules and property types can be added and | ||
registered following the [PluginPlay tutorials](https://nwchemex.github.io/PluginPlay/tutorials/index.html). | ||
The resulting library will depend on [SimDE](https://github.com/NWChemEx/SimDE). | ||
See [here](https://nwchemex.github.io/SimDE/install.html#simde-dependencies) for | ||
the further info on SimDE's dependencies. You can configure, build, and test the | ||
new plugin as follows: | ||
|
||
```bash | ||
$ cmake -Bbuild -H. -DCMAKE_TOOLCHAIN_FILE=./default_toolchain.cmake -DCMAKE_INSTALL_PREFIX=./install | ||
$ cmake --build build --parallel 2 | ||
$ cd build | ||
$ ctest -VV | ||
``` | ||
|
||
At this point, you can initialize git and set up remotes: | ||
|
||
```bash | ||
$ git init | ||
$ git add . | ||
$ git commit -m "Initial State" | ||
$ git remote add origin {Your Remote Repo} | ||
$ git push -u origin master | ||
``` | ||
|
||
# Contributing | ||
|
||
- [Contributor Guidelines](https://github.com/NWChemEx/.github/blob/1a883d64519f62da7c8ba2b28aabda7c6f196b2c/.github/CONTRIBUTING.md) | ||
- [Contributor License Agreement](https://github.com/NWChemEx/.github/blob/master/.github/CONTRIBUTING.md#contributor-license-agreement-cla) | ||
- [Code of Conduct](https://github.com/NWChemEx/.github/blob/master/.github/CODE_OF_CONDUCT.md) | ||
|
||
# Acknowledgments | ||
|
||
Add... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"project_name": "New Plugin", | ||
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# These are directories used by IDEs for storing settings | ||
.idea/ | ||
.vscode/ | ||
|
||
# These are common build directory names | ||
build*/ | ||
docs/build | ||
docs/source/_build | ||
docs/doxyoutput | ||
docs/source/api | ||
*-build-*/ | ||
_build/ | ||
Debug/ | ||
Release/ | ||
|
||
# Users commonly store their specific CMake settings in a toolchain file | ||
toolchain.cmake | ||
|
||
# Users often install under the root directory | ||
install/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
## Set Project and Version | ||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION) | ||
project({{ cookiecutter.project_slug }} VERSION "${VERSION}" LANGUAGES CXX) | ||
|
||
## Get CMaize | ||
include(cmake/get_cmaize.cmake) | ||
|
||
## Paths ## | ||
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") | ||
|
||
## Options ## | ||
cmaize_option_list( | ||
BUILD_TESTING OFF "Should the tests be built?" | ||
) | ||
|
||
## Find or build dependencies ## | ||
cmaize_find_or_build_dependency( | ||
simde | ||
URL github.com/NWChemEx/SimDE | ||
VERSION master | ||
BUILD_TARGET simde | ||
FIND_TARGET nwx::simde | ||
CMAKE_ARGS BUILD_TESTING=OFF | ||
) | ||
|
||
## Add libraries ## | ||
cmaize_add_library( | ||
${PROJECT_NAME} | ||
SOURCE_DIR "${${PROJECT_NAME}_SOURCE_DIR}/${PROJECT_NAME}" | ||
INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}" | ||
DEPENDS simde | ||
) | ||
|
||
## Build tests ## | ||
if("${BUILD_TESTING}") | ||
## Find or build dependencies for tests | ||
cmaize_find_or_build_dependency( | ||
Catch2 | ||
URL github.com/catchorg/Catch2 | ||
BUILD_TARGET Catch2 | ||
FIND_TARGET Catch2::Catch2 | ||
VERSION v2.x | ||
) | ||
|
||
## Add Tests ## | ||
cmaize_add_tests( | ||
test_${PROJECT_NAME} | ||
SOURCE_DIR "${${PROJECT_NAME}_TESTS_DIR}/unit_tests" | ||
INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}" | ||
DEPENDS Catch2 ${PROJECT_NAME} | ||
) | ||
|
||
endif() | ||
|
||
## Add package ## | ||
cmaize_add_package( | ||
${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}:: | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{ cookiecutter.project_name }} | ||
=============== | ||
|
||
Describe the new plugin here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function(get_cmaize) | ||
|
||
if("${CMAIZE_VERSION}" STREQUAL "") | ||
set(CMAIZE_VERSION v1.1.0 ) | ||
endif() | ||
|
||
# Store whether we are building tests or not, then turn off the tests | ||
if(BUILD_TESTING) | ||
set(build_testing_old "${BUILD_TESTING}") | ||
endif() | ||
set(BUILD_TESTING OFF CACHE BOOL "" FORCE) | ||
|
||
# Download CMakePP and bring it into scope | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
cmaize | ||
GIT_REPOSITORY https://github.com/CMakePP/CMaize | ||
GIT_TAG ${CMAIZE_VERSION} | ||
) | ||
FetchContent_MakeAvailable(cmaize) | ||
|
||
# Restore the previous value, if set | ||
# Unset otherwise | ||
if(build_testing_old) | ||
set(BUILD_TESTING "${build_testing_old}" CACHE BOOL "" FORCE) | ||
else() | ||
unset(BUILD_TESTING CACHE) | ||
endif() | ||
endfunction() | ||
|
||
# Call the function we just wrote to get CMaize | ||
get_cmaize() | ||
|
||
# Include CMaize | ||
include(cmaize/cmaize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(BUILD_TESTING ON) | ||
set(BUILD_SHARED_LIBS ON) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) | ||
set(NWX_MODULE_DIRECTORY ./install/python) |
3 changes: 3 additions & 0 deletions
3
...oject_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include "{{ cookiecutter.project_slug }}_mm.hpp" |
11 changes: 11 additions & 0 deletions
11
...ct_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
#include <pluginplay/plugin/plugin.hpp> | ||
|
||
namespace {{ cookiecutter.project_slug }} { | ||
|
||
/** @brief Loads the modules contained in the plugin into the provided | ||
* ModuleManager instance. | ||
*/ | ||
DECLARE_PLUGIN({{ cookiecutter.project_slug }}); | ||
|
||
} // namespace {{ cookiecutter.project_slug }} |
16 changes: 16 additions & 0 deletions
16
...roject_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#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 | ||
} | ||
|
||
DECLARE_PLUGIN({{ cookiecutter.project_slug }}) { | ||
// Add subcollection load calls here | ||
|
||
// Assign default submodules | ||
set_defaults(mm); | ||
} | ||
|
||
} // namespace {{ cookiecutter.project_slug }} |
7 changes: 7 additions & 0 deletions
7
{{ cookiecutter.project_slug }}/tests/unit_tests/test_load_modules.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <catch2/catch.hpp> | ||
#include <{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp> | ||
|
||
TEST_CASE("load_modules") { | ||
pluginplay::ModuleManager mm; | ||
{{ cookiecutter.project_slug }}::load_modules(mm); | ||
} |
7 changes: 7 additions & 0 deletions
7
{{ cookiecutter.project_slug }}/tests/unit_tests/test_main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define CATCH_CONFIG_RUNNER | ||
#include <catch2/catch.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
int res = Catch::Session().run(argc, argv); | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.0 |