How to Add New Code¶
This document details the process of adding new code into freud.
Does my code belong in freud?¶
The freud library is not meant to simply wrap or augment external Python libraries. A good rule of thumb is if the code I plan to write does not require C++, it does not belong in freud. There are, of course, exceptions.
Create a new branch¶
You should branch your code from master into a new branch. Do not add
new code directly into the master branch.
Add a New Module¶
If the code you are adding is in a new module, not an existing module, you must do the following:
Create
cpp/moduleNamefolderEdit
freud/__init__.pyAdd
from . import moduleNameso that your module is imported by default.
Edit
freud/_freud.pyxAdd
include "moduleName.pxi". This must be done to have freud include your Python-level code.
Create
freud/moduleName.pxifileThis will house the python-level code.
If you have a .pxd file exposing C++ classes, make sure to import that:
cimport freud._moduleName as moduleName
Create
freud/moduleName.pyfileMake sure there is an import for each C++ class in your module:
from ._freud import MyC++Class
Create
freud/_moduleName.pxdThis file will expose the C++ classes in your module to python.
Edit
setup.pyAdd
cpp/moduleNameto theincludeslist.If there are any helper cc files that will not have a corresponding Cython class, add those files to the
sourceslist inside theextensionslist.
Add line to
doc/source/modules.rstMake sure your new module is referenced in the documentation.
Create
doc/source/moduleName.rst
Add to an Existing Module¶
To add a new class to an existing module, do the following:
Create
cpp/moduleName/SubModule.handcpp/moduleName/SubModule.ccNew classes should be grouped into paired
.h,.ccfiles. There may be a few instances where new classes could be added to an existing.h,.ccpairing.
Edit
freud/moduleName.pyfileAdd a line for each C++ class in your module:
from ._freud import MyC++Class
Expose C++ class in
freud/_moduleName.pxdCreate Python interface in
freud/moduleName.pxi
You must include sphinx-style documentation and unit tests.
Add extra documentation to
doc/source/moduleName.rstAdd unit tests to
freud/tests