Skip to content

Commit

Permalink
Use cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaldrop107 committed Feb 7, 2024
1 parent 7de31c5 commit fa60358
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 181 deletions.
18 changes: 1 addition & 17 deletions .gitignore
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
71 changes: 42 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,54 @@ 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).

The primary contents of this repo are as follows:
- `README.md` - This file.
- `setup_new_plugin.sh` - The main component of this repo, used to generate the
starting files for the new plugin. More on this below.
- `cmake/get_cmaize.cmake` - A CMake function to retrieve and include the
[CMaize](https://github.com/CMakePP/CMaize) library.
- `CMakeLists.txt` - The CMakeLists file for the new plugin produced by the
running `setup_new_plugin.sh`.

## Generating the New Plugin
After cloning this repo, the first step is to run `setup_new_plugin.sh`. The
name of the new plugin (`plugin_name`) can either be passed as an argument when
the script is called or you will be prompted for the name when the script runs.
After running the script, eight files should be produced:
- `plugin_name.txt` - Holds the name of the plugin. Used by `CMakeLists.txt`.

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`.
- `toolchain.cmake` - A simple CMake toolchain. Ignored by Git.
- `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
`load_modules` function of the plugin.
- `src/{plugin_name}/{plugin_name}_mm.cpp` - A source file defining the
`load_modules` function of the plugin.
- `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.
- `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 shoudl be added and
registered following the [PluginPlay tutorials](https://nwchemex.github.io/PluginPlay/tutorials/index.html).
`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).You can configure, build, and test the new plugin as follows:

## Clean-Up
Once the new plugin has been generated, the developers will want to change the
git `origin` associated with the repo to one corresponding to the new plugin.
This is accomplished with the command
```bash
$ cmake -Bbuild -H. -DCMAKE_TOOLCHAIN_FILE=./default_toolchain.cmake -DCMAKE_INSTALL_PREFIX=./install
$ cmake --build build --parallel 2
$ cd build
$ ctest -VV
```
git remote set-url origin {your_url_here}

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
```
Also, this markdown file should be modified to represent the new plugin.

# 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...
4 changes: 4 additions & 0 deletions cookiecutter.json
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(' ', '_') }}"
}
126 changes: 0 additions & 126 deletions setup_new_plugin.sh

This file was deleted.

20 changes: 20 additions & 0 deletions {{ cookiecutter.project_slug }}/.gitignore
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/
17 changes: 8 additions & 9 deletions CMakeLists.txt → ...okiecutter.project_slug }}/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
cmake_minimum_required(VERSION 3.14)

## Set Project and Version
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/plugin_name.txt" PLUGIN_NAME)
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION)
project("${PLUGIN_NAME}" VERSION "${VERSION}" LANGUAGES CXX)
project({{ cookiecutter.project_slug }} VERSION "${VERSION}" LANGUAGES CXX)

## Get CMaize
include(cmake/get_cmaize.cmake)

## Paths ##
set(PLUGIN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(PLUGIN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PLUGIN_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
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(
Expand All @@ -31,8 +30,8 @@ cmaize_find_or_build_dependency(
## Add libraries ##
cmaize_add_library(
${PROJECT_NAME}
SOURCE_DIR "${PLUGIN_SOURCE_DIR}/${PROJECT_NAME}"
INCLUDE_DIRS "${PLUGIN_INCLUDE_DIR}/${PROJECT_NAME}"
SOURCE_DIR "${${PROJECT_NAME}_SOURCE_DIR}/${PROJECT_NAME}"
INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}"
DEPENDS simde
)

Expand All @@ -50,8 +49,8 @@ if("${BUILD_TESTING}")
## Add Tests ##
cmaize_add_tests(
test_${PROJECT_NAME}
SOURCE_DIR "${PLUGIN_TESTS_DIR}/unit_tests"
INCLUDE_DIRS "${PLUGIN_INCLUDE_DIR}/${PROJECT_NAME}"
SOURCE_DIR "${${PROJECT_NAME}_TESTS_DIR}/unit_tests"
INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}"
DEPENDS Catch2 ${PROJECT_NAME}
)

Expand Down
4 changes: 4 additions & 0 deletions {{ cookiecutter.project_slug }}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ cookiecutter.project_name }}
===============

Describe the new plugin here.
File renamed without changes.
4 changes: 4 additions & 0 deletions {{ cookiecutter.project_slug }}/default_toolchain.cmake
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "{{ cookiecutter.project_slug }}_mm.hpp"
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 }}
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 }}
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);
}
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;
}
1 change: 1 addition & 0 deletions {{ cookiecutter.project_slug }}/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0

0 comments on commit fa60358

Please sign in to comment.