how_to_contribute_en.md 10.9 KB
Newer Older
W
weishengyu 已提交
1 2 3 4
# How to Contribute to the PaddleClas Community

------

W
weishengyu 已提交
5
## Catalogue
W
weishengyu 已提交
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
- [1. How to Contribute Code](#1)
  - [1.1 Branches of PaddleClas](#1.1)
  - [1.2 Commit Code to PaddleClas](#1.2)
    - [1.2.1 Codes of Fork and Clone](#1.2.1)
    - [1.2.2 Connect to the Remote Repository](#1.2.2)
    - [1.2.3 Create the Local Branch](#1.2.3)
    - [1.2.4 Employ Pre-commit Hook](#1.2.4)
    - [1.2.5 Modify and Commit Code](#1.2.5)
    - [1.2.6 Keep the Local Repository Updated](#1.2.6)
    - [1.2.7 Push to Remote Repository](#1.2.7)
    - [1.2.8 Commit Pull Request](#1.2.8)
    - [1.2.9 CLA and Unit Test](#1.2.9)
    - [1.2.10 Delete Branch](#1.2.10)
    - [1.2.11 Conventions](#1.2.11)
- [2. Summary](#2)
- [3. Inferences](#3)
W
weishengyu 已提交
23 24


W
weishengyu 已提交
25
<a name="1"></a>
W
weishengyu 已提交
26 27 28
## 1. How to Contribute Code


W
weishengyu 已提交
29
<a name="1.1"></a>
W
weishengyu 已提交
30 31
### 1.1 Branches of PaddleClas

32
PaddleClas maintains the following two branches:
W
weishengyu 已提交
33

34 35 36 37 38 39 40 41 42 43 44
- release/x.x series: Stable release branches, which are tagged with the release version of Paddle in due course.
The latest and the default branch is the release/2.3, which is compatible with Paddle v2.1.0.
The branch of release/x.x series will continue to grow with future iteration,
and the latest release will be maintained by default, while the former one will fix bugs with no other branches covered.
- develop : developing branch, which is adapted to the develop version of Paddle and is mainly used for
developing new functions. A good choice for secondary development.
To ensure that the develop branch can pull out the release/x.x when needed,
only the API that is valid in Paddle's latest release branch can be adopted for its code.
In other words, if a new API has been developed in this branch but not yet in the release,
please do not use it in PaddleClas. Apart from that, features that do not involve the performance optimizations,
parameter adjustments, and policy updates of the API can be developed normally.
W
weishengyu 已提交
45 46 47

The historical branches of PaddleClas will not be maintained, but will be remained for the existing users.

48 49 50 51 52 53
- release/static: This branch was used for static graph development and testing,
and is currently compatible with >=1.7 versions of Paddle.
It is still practicable for the special need of adapting an old version of Paddle,
but the code will not be updated except for bug fixing.
- dygraph-dev: This branch will no longer be maintained and accept no new code.
Please transfer to the develop branch as soon as possible.
W
weishengyu 已提交
54 55 56 57

PaddleClas welcomes code contributions to the repo, and the basic process is detailed in the next part.


W
weishengyu 已提交
58
<a name="1.2"></a>
W
weishengyu 已提交
59 60 61
### 1.2 Commit the Code to PaddleClas


W
weishengyu 已提交
62
<a name="1.2.1"></a>
W
weishengyu 已提交
63 64
#### 1.2.1 Codes of Fork and Clone

65 66
- Skip to the home page of [PaddleClas GitHub](https://github.com/PaddlePaddle/PaddleClas) and click the
Fork button to generate a repository in your own directory, such as `https://github.com/USERNAME/PaddleClas`.
W
weishengyu 已提交
67

W
dbg  
weishengyu 已提交
68
[](../../images/quick_start/community/001_fork.png)
W
weishengyu 已提交
69 70 71

- Clone the remote repository to local

72
```shell
W
weishengyu 已提交
73 74 75 76 77 78 79
# Pull the code of the develop branch
git clone https://github.com/USERNAME/PaddleClas.git -b develop
cd PaddleClas
```

Obtain the address below

W
dbg  
weishengyu 已提交
80
[](../../images/quick_start/community/002_clone.png)
W
weishengyu 已提交
81 82


W
weishengyu 已提交
83
<a name="1.2.2"></a>
W
weishengyu 已提交
84 85 86 87
#### 1.2.2 Connect to the Remote Repository

First check the current information of the remote repository with `git remote -v`.

88
```shell
W
weishengyu 已提交
89 90 91 92
origin    https://github.com/USERNAME/PaddleClas.git (fetch)
origin    https://github.com/USERNAME/PaddleClas.git (push)
```

93 94
The above information only contains the cloned remote repository,
which is the PaddleClas under your username. Then we create a remote host of the original PaddleClas repository named upstream.
W
weishengyu 已提交
95

96
```shell
W
weishengyu 已提交
97 98 99
git remote add upstream https://github.com/PaddlePaddle/PaddleClas.git
```

100 101
Adopt `git remote -v` to view the current information of the remote repository,
and 2 remote repositories including origin and upstream can be found, as shown below.
W
weishengyu 已提交
102

103
```shell
W
weishengyu 已提交
104 105 106 107 108 109 110 111 112
origin    https://github.com/USERNAME/PaddleClas.git (fetch)
origin    https://github.com/USERNAME/PaddleClas.git (push)
upstream    https://github.com/PaddlePaddle/PaddleClas.git (fetch)
upstream    https://github.com/PaddlePaddle/PaddleClas.git (push)
```

This is mainly to keep the local repository updated when committing a pull request (PR).


W
weishengyu 已提交
113
<a name="1.2.3"></a>
W
weishengyu 已提交
114 115 116 117
#### 1.2.3 Create the Local Branch

Run the following command to create a new local branch based on the current one.

118
```shell
W
weishengyu 已提交
119 120 121 122 123
git checkout -b new_branch
```

Or you can create new ones based on remote or upstream branches.

124
```shell
W
weishengyu 已提交
125 126 127
# Create the new_branch based on the develope of origin (unser remote repository)
git checkout -b new_branch origin/develop
# Create the new_branch base on the develope of upstream
128 129
# If you need to create a new branch from upstream,
# please first employ git fetch upstream to fetch the upstream code
W
weishengyu 已提交
130 131 132
git checkout -b new_branch upstream/develop
```

133
The following output shows that it has switched to the new branch with :
W
weishengyu 已提交
134 135 136 137 138 139 140

```
Branch new_branch set up to track remote branch develop from upstream.
Switched to a new branch 'new_branch'
```


W
weishengyu 已提交
141
<a name="1.2.4"></a>
W
weishengyu 已提交
142 143
#### 1.2.4 Employ Pre-commit Hook

144 145 146
Paddle developers adopt the pre-commit tool to manage Git pre-commit hooks.
It helps us format the source code (C++, Python) and automatically check basic issues before committing
e.g., one EOL per file, no large files added to Git, etc.
W
weishengyu 已提交
147

148 149 150
The pre-commit test is part of the unit tests in Travis-CI,
and PRs that do not satisfy the hook cannot be committed to PaddleClas.
Please install it first and run it in the current directory:
W
weishengyu 已提交
151 152 153 154 155 156 157 158

```
pip install pre-commit
pre-commit install
```

- **Note**

159 160 161
1. Paddle uses clang-format to format C/C++ source code, please make sure `clang-format` has a version of 3.8 or higher.
2. `yapf` installed by `pip install pre-commit` and `conda install -c conda-forge pre-commit` is slightly different,
and the former one is chosen by PaddleClas developers.
W
weishengyu 已提交
162 163


W
weishengyu 已提交
164
<a name="1.2.5"></a>
W
weishengyu 已提交
165 166 167 168 169
#### 1.2.5 Modify and Commit Code

You can check the changed files via `git status`. Follow the steps below to commit the `README.md` of PaddleClas after modification:

```
170 171
git add README.md
pre-commit
W
weishengyu 已提交
172 173 174 175
```

Repeat the above steps until the pre-commit format check does not report an error, as shown below.

W
dbg  
weishengyu 已提交
176
[](../../images/quick_start/community/003_precommit_pass.png)
W
weishengyu 已提交
177 178 179 180 181 182 183 184

Run the following command to commit.

```
git commit -m "your commit info"
```


W
weishengyu 已提交
185
<a name="1.2.6"></a>
W
weishengyu 已提交
186 187
#### 1.2.6 Keep the Local Repository Updated

188 189
Get the latest code for upstream and update the current branch.
The upstream here is from the `Connecting to a remote repository` part in section 1.2.
W
weishengyu 已提交
190 191

```
192 193 194
git fetch upstream
# If you want to commit to another branch, please pull the code from another branch of upstream, in this case it is develop
git pull upstream develop
W
weishengyu 已提交
195 196 197
```


W
weishengyu 已提交
198
<a name="1.2.7"></a>
W
weishengyu 已提交
199 200 201 202 203 204 205
#### 1.2.7 Push to Remote Repository

```
git push origin new_branch
```


W
weishengyu 已提交
206
<a name="1.2.8"></a>
W
weishengyu 已提交
207 208
#### 1.2.8 Commit Pull Request

209 210 211 212
Click new pull request and select the local branch and the target branch,
as shown in the following figure. In the description of the PR, fill out what the PR accomplishes.
Next, wait for the review, and if any changes are required,
update the corresponding branch in origin by referring to the above steps.
W
weishengyu 已提交
213

W
dbg  
weishengyu 已提交
214
[](../../images/quick_start/community/004_create_pr.png)
W
weishengyu 已提交
215 216


W
weishengyu 已提交
217
<a name="1.2.9"></a>
W
weishengyu 已提交
218 219
#### 1.2.9 CLA and Unit Test

220 221 222
- When you first commit a Pull Request to PaddlePaddle,
you are required to sign a CLA (Contributor License Agreement) to ensure that your code can be merged,
please follow the step below to sign CLA:
W
weishengyu 已提交
223

224 225 226 227
1. Please examine the Check section of your PR, find license/cla,
and click the detail on the right side to enter the CLA website
2. Click `Sign in with GitHub to agree` on the CLA website,
and you will be redirected back to your Pull Request page when you are done.
W
weishengyu 已提交
228 229


W
weishengyu 已提交
230
<a name="1.2.10"></a>
W
weishengyu 已提交
231 232 233 234 235 236 237 238 239 240 241 242
#### 1.2.10 Delete Branch

- Delete remote branch

When the PR is merged into the main repository, you can delete the remote branch from the PR page.

You can also delete the remote branch using `git push origin :branch name`, e.g.

```
git push origin :new_branch
```

243
- Delete local branch
W
weishengyu 已提交
244 245

```
246 247 248 249 250
# Switch to the develop branch, otherwise the current branch cannot be deleted
git checkout develop

# Delete new_branch
git branch -D new_branch
W
weishengyu 已提交
251 252 253
```


W
weishengyu 已提交
254
<a name="1.2.11"></a>
W
weishengyu 已提交
255 256
#### 1.2.11 Conventions

257 258
To help official maintainers focus on the code itself when reviewing it,
please adhere to the following conventions each time you commit code:
W
weishengyu 已提交
259

260 261 262
1. Please pass the unit test in Travis-CI first.
Otherwise, the submitted code may have problems and usually receive no official review.
2. Before committing a Pull Request:
W
weishengyu 已提交
263 264
Note the number of commits.

265 266 267
Reason: If only one file is modified but more than a dozen commits are committed with a few changes for each,
this may overwhelm the reviewer for they need to check each and every commit for specific changes,
including the case that the changes between commits overwrite each other.
W
weishengyu 已提交
268

269 270 271
Recommendation: Minimize the number of commits each time, and add the last commit with `git commit --amend`.
For multiple commits that have been pushed to a remote repository, please refer to
[squash commits after push](https://stackoverflow.com/questions/5667884/how-to-squash-commits-in-git-after-they-have-been-pushed).
W
weishengyu 已提交
272

273 274
Please pay attention to the name of each commit:
it should reflect the content of the current commit without being too casual.
W
weishengyu 已提交
275

276 277
3. If an issue is resolved, please add `fix #issue_number` to the first comment box of the Pull Request,
so that the corresponding issue will be closed automatically when the Pull Request is merged. Please choose the appropriate term with keywords such as close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved, please choose the appropriate term. See details in [Closing issues via commit messages](https://help.github.com/articles/closing-issues-via-commit-messages).
W
weishengyu 已提交
278 279 280

In addition, please stick to the following convention to respond to reviewers' comments:

281 282
1. Every review comment from the official maintainer is expected to be answered,
which will better enhance the contribution of the open source community.
W
weishengyu 已提交
283 284 285 286

-  If you agree with the review and finish the corresponding modification, please simply return Done;
-  If you disagree with the review, please give your reasons.

287
2. If there are plenty of review comments,
W
weishengyu 已提交
288 289 290 291 292

- Please present the revision in general.
- Please reply with `start a review` instead of a direct approach, for it may be overwhelming to receive the email of every reply.


W
weishengyu 已提交
293
<a name="2"></a>
W
weishengyu 已提交
294 295
## 2. Summary

296 297
- The open source community relies on the contributions and feedback of developers and users.
We highly appreciate that and look forward to your valuable comments and Pull Requests to PaddleClas in the hope that together we can build a leading practical and comprehensive code repository for image recognition!
W
weishengyu 已提交
298 299


W
weishengyu 已提交
300
<a name="3"></a>
W
weishengyu 已提交
301 302
## 3. References

303 304
1. [Guide to PaddlePaddle Local Development](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/08_contribution/index_en.html)
2. [Committing PR to Open Source Framework](https://blog.csdn.net/vim_wj/article/details/78300239)