-
Notifications
You must be signed in to change notification settings - Fork 184
Developer Guide
To be described
Crocoddyl CI also checks code format (for both c++ and Python code) as effort to maximize readability and maintainability. Depending on the language, c++ or Python, we use different format policies which are tested with Gepetto/linters repository. For c++ code, Crocoddyl uses Google format convention, instead for Python code it follows flake8 rules with a maximum length of 119 characters.
Despite that Crocoddyl follows the strict code format, you don't need to learn each specific details of these formatting rules. For that, you have two options:
- configuration your IDE to lint your code automatically (or check it), and
- let our linter to adjust your code.
Here we explain how to do the later. For this, you can either use the provided docker image (subsection 1), or manually setup your environment by yourself (subsection 2).
docker run --rm -v $PWD:/app -w /app -it gepetto/linters
This will not work if the root user doesn't have the right to go into your current working directory.
And if your current working directory is accessed through symlinks, you might need to replace $PWD
by $(pwd -P)
.
Before starting with it, you need to clone Gepetto/linter repository, i.e.
git clone [email protected]:Gepetto/linters.git
sudo apt install clang-format-6.0
pip install --user flake8, isort, yapf
Then, you need to install the configuration files in the current working directory (beware of git if doing so) or in a parent directory. Your home might be a good choice:
cd ${YOUR_CROCCODDYL_SOURCE_PATH}
ln -s ${YOUR_GEPETTO_LINTER_PATH}/clang-format .clang-format
ln -s ${YOUR_GEPETTO_LINTER_PATH}/isort.cfg .isort.cfg
For flake8 & yapf, you need to use the standard configuration directory:
cd ~/.config
ln -s ${YOUR_GEPETTO_LINTER_PATH}/flake8 .flake8
mkdir yapf
cd yapf
ln -s ${YOUR_GEPETTO_LINTER_PATH}/yapf.style style
Please note that with the following instructions your current code will be updated
cd ${YOUR_CROCCODDYL_SOURCE_PATH}
clang-format-6.0 -i $(find . -path ./cmake -prune -o -iregex '.*\.\(h\|c\|hh\|cc\|hpp\|cpp\|hxx\|cxx\)$' -print)
cd ${YOUR_CROCCODDYL_SOURCE_PATH}
flake8 .
yapf -ri .