SINGA代码库在CPP和Python代码中都遵循Google风格。
强制执行Google编码风格的一个简单方法是使用Visual Studio Code编辑器中的linting和格式化工具:
安装扩展后,编辑settings.json
文件:
{ "[cpp]": { "editor.defaultFormatter": "xaver.clang-format" }, "cpplint.cpplintPath": "path/to/cpplint", "editor.formatOnSave": true, "python.formatting.provider": "yapf", "python.linting.enabled": true, "python.linting.lintOnSave": true, "clang-format.language.cpp.style": "google", "python.formatting.yapfArgs": ["--style", "{based_on_style: google}"] }
根据您的操作系统,用户设置文件位于以下位置:
配置是在相应的配置文件中指定的。而这些工具会自动查找项目根目录下的配置文件,比如.pylintrc
。
最理想的情况是所有贡献者都使用相同版本的代码格式化工具(clang-format 9.0.0和yapf 0.29.0),这样在不同PR中的代码格式化就会完全相同,从而摆脱github pull request冲突。
首先,安装LLVM 9.0,它提供了clang-format 9.0.0版本,LLVM的下载页面如下:
Ubuntu系统:
sudo apt-get install clang-format-9
Windows系统,下载预编译包并安装。
然后,安装cpplint, pylint和yapf
Ubuntu或OSX:
$ sudo pip install cpplint $ which cpplint /path/to/cpplint $ pip install yapf==0.29.0 $ pip install pylint
Windows: 安装Anaconda进行包管理
$ pip install cpplint $ where cpplint C:/path/to/cpplint.exe $ pip install yapf==0.29.0 $ pip install pylint
PROBLEMS
面板中列出。Shift+Ctrl+P
,OS X中为Shift+Command+P
)并输入Format Document
来完成。修正格式错误以后就可以提交pull request了。
推荐使用Visual Studio Code作为编辑器。可以安装Python、C/C++、代码拼写检查器、autoDocstring、vim、远程开发等扩展。这些扩展的参考配置(即settings.json
)可以在这里查看。
如果更新CPP代码,需要从源文件重新编译SINGA。建议使用*-devel Docker
镜像中的原生构建工具或使用conda build
。
如果要只更新Python代码,您可以安装一次SINGA,然后复制更新后的Python文件来替换Python安装文件夹中的文件。
cp python/singa/xx.py <path to conda>/lib/python3.7/site-packages/singa/
请参阅git工作流程页面.