Skip to content

Developer Guide

Carlos Mastalli edited this page Apr 26, 2019 · 15 revisions

I. Design pattern

To be described

II. Code Format

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:

  1. configuration your IDE to lint your code automatically (or check it), and
  2. 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).

1. Direct use of the provided docker image

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).

2. Manual use of each tool

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

2.1. Formatting your c++ code

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)

2.2. Formatting your Python code

cd ${YOUR_CROCCODDYL_SOURCE_PATH}
flake8 .
yapf -ri .
Clone this wiki locally