2021-06-30 20:53:09 +08:00
|
|
|
|
# 参与贡献 OpenMMLab
|
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
欢迎任何类型的贡献,包括但不限于
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
- 修改拼写错误或代码错误
|
|
|
|
|
- 添加文档或将文档翻译成其他语言
|
|
|
|
|
- 添加新功能和新组件
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
|
|
|
|
## 工作流程
|
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
1. fork 并 pull 最新的 OpenMMLab 仓库 (MMClassification)
|
2021-06-30 20:53:09 +08:00
|
|
|
|
2. 签出到一个新分支(不要使用 master 分支提交 PR)
|
|
|
|
|
3. 进行修改并提交至 fork 出的自己的远程仓库
|
|
|
|
|
4. 在我们的仓库中创建一个 PR
|
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
```{note}
|
|
|
|
|
如果你计划添加一些新的功能,并引入大量改动,请尽量首先创建一个 issue 来进行讨论。
|
|
|
|
|
```
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
|
|
|
|
## 代码风格
|
|
|
|
|
|
|
|
|
|
### Python
|
|
|
|
|
|
|
|
|
|
我们采用 [PEP8](https://www.python.org/dev/peps/pep-0008/) 作为统一的代码风格。
|
|
|
|
|
|
|
|
|
|
我们使用下列工具来进行代码风格检查与格式化:
|
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
- [flake8](https://github.com/PyCQA/flake8): Python 官方发布的代码规范检查工具,是多个检查工具的封装
|
|
|
|
|
- [isort](https://github.com/timothycrosley/isort): 自动调整模块导入顺序的工具
|
2021-06-30 20:53:09 +08:00
|
|
|
|
- [yapf](https://github.com/google/yapf): 一个 Python 文件的格式化工具。
|
2022-06-02 15:22:01 +08:00
|
|
|
|
- [codespell](https://github.com/codespell-project/codespell): 检查单词拼写是否有误
|
|
|
|
|
- [mdformat](https://github.com/executablebooks/mdformat): 检查 markdown 文件的工具
|
2021-06-30 20:53:09 +08:00
|
|
|
|
- [docformatter](https://github.com/myint/docformatter): 一个 docstring 格式化工具。
|
|
|
|
|
|
2022-08-31 23:57:51 +08:00
|
|
|
|
yapf 和 isort 的格式设置位于 [setup.cfg](https://github.com/open-mmlab/mmclassification/blob/1.x/setup.cfg)
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
|
|
|
|
我们使用 [pre-commit hook](https://pre-commit.com/) 来保证每次提交时自动进行代
|
2022-06-02 15:22:01 +08:00
|
|
|
|
码检查和格式化,启用的功能包括 `flake8`, `yapf`, `isort`, `trailing whitespaces`, `markdown files`, 修复 `end-of-files`, `double-quoted-strings`,
|
2021-06-30 20:53:09 +08:00
|
|
|
|
`python-encoding-pragma`, `mixed-line-ending`, 对 `requirments.txt`的排序等。
|
2022-08-31 23:57:51 +08:00
|
|
|
|
pre-commit hook 的配置文件位于 [.pre-commit-config](https://github.com/open-mmlab/mmclassification/blob/1.x/.pre-commit-config.yaml)
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
|
|
|
|
在你克隆仓库后,你需要按照如下步骤安装并初始化 pre-commit hook。
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
pip install -U pre-commit
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在仓库文件夹中执行
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
pre-commit install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在此之后,每次提交,代码规范检查和格式化工具都将被强制执行。
|
|
|
|
|
|
2021-09-28 18:05:50 +08:00
|
|
|
|
```{important}
|
|
|
|
|
在创建 PR 之前,请确保你的代码完成了代码规范检查,并经过了 yapf 的格式化。
|
|
|
|
|
```
|
2021-06-30 20:53:09 +08:00
|
|
|
|
|
|
|
|
|
### C++ 和 CUDA
|
|
|
|
|
|
2022-06-02 15:22:01 +08:00
|
|
|
|
C++ 和 CUDA 的代码规范遵从 [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
|