Skip to content

Latest commit

 

History

History
87 lines (70 loc) · 2.3 KB

STYLE_GUIDE.md

File metadata and controls

87 lines (70 loc) · 2.3 KB

C++

C++ code should conform to Google C++ Style Guide.

Addons uses clang-format to check your C/C++ changes. Sometimes you have some manually formatted code that you don’t want clang-format to touch. You can disable formatting like this:

int formatted_code;
// clang-format off
    void    unformatted_code  ;
// clang-format on
void formatted_code_again;

Install Clang-format 9 for Ubuntu:

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - 
sudo add-apt-repository -u 'http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
sudo apt install clang-format-9

format all with:

clang-format-9 -i --style=google ./tensorflow_recommenders_addons/**/*.cc ./tensorflow_recommenders_addons/**/*.h

Install Clang-format for MacOS:

brew update
brew install clang-format

format all with:

clang-format -i --style=google **/*.cc tensorflow_recommenders_addons/**/*.h

Python

Recommenders Addons use Yapf to format our code. The continuous integration check will fail if you do not use it.

Install them with:

pip install yapf

Be sure to run it before you push your commits, otherwise the CI will fail!

yapf --style=./.yapf -ir ./**/*.py

Bazel BUILD

Use buildifier in project bazelbuild/buildtools to format the bazel code.

Install it with:

git clone https://github.com/bazelbuild/buildtools.git
cd buildtools
bazel build //buildifier

Then copy the binary to directory on $PATH. (such as "/usr/local/bin")

cp bazel-bin/buildifier/buildifier_/buildifier /usr/local/bin

Run following commmand to see whether if installation ok:

buildifier --version

Use buildifier

buildifier -mode diff ${your_file_name}

to see formating problem in the BUILD file, or:

buildifier -mode diff ${directory}

for all BUILD files in ${directory}.

TensorFlow Conventions

Follow the guidance in the TensorFlow Style Guide - Conventions.