Skip to content

Commit bc3f8f6

Browse files
pmeierNicolasHug
andauthored
add pre-commit hooks for convenient formatting checks (#4387)
* add pre-commit hooks * ignore yamls in packaging/* * add pre-commit to contributing guide lines * Update CONTRIBUTING.md Co-authored-by: Nicolas Hug <[email protected]> * remove some hooks * fix docstrings * fix end of files Co-authored-by: Nicolas Hug <[email protected]>
1 parent c359d8d commit bc3f8f6

File tree

21 files changed

+46
-26
lines changed

21 files changed

+46
-26
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ jobs:
192192
- checkout
193193
- run:
194194
command: |
195-
pip install --user --progress-bar off flake8 typing
196-
flake8 --config=setup.cfg .
195+
pip install --user --progress-bar off pre-commit
196+
pre-commit install-hooks
197+
- run: pre-commit run --all-files
197198

198199
python_type_check:
199200
docker:

.circleci/unittest/linux/scripts/run-clang-format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
SOFTWARE.
24-
"""
25-
"""A wrapper script around clang-format, suitable for linting multiple files
24+
25+
A wrapper script around clang-format, suitable for linting multiple files
2626
and to use for continuous integration.
2727
2828
This is an alternative API for the clang-format command line.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%
1+
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://gitlab.com/pycqa/flake8
3+
rev: 3.9.2
4+
hooks:
5+
- id: flake8
6+
args: [--config=setup.cfg]
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.0.1
9+
hooks:
10+
- id: check-docstring-first
11+
- id: check-toml
12+
- id: check-yaml
13+
exclude: packaging/.*
14+
- id: end-of-file-fixer

CONTRIBUTING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ If you plan to modify the code or documentation, please follow the steps below:
6464
2. If you have modified the code (new feature or bug-fix), please add unit tests.
6565
3. If you have changed APIs, update the documentation. Make sure the documentation builds.
6666
4. Ensure the test suite passes.
67-
5. Make sure your code passes `flake8` formatting check.
67+
5. Make sure your code passes the formatting checks (see below).
6868

6969
For more details about pull requests,
7070
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
@@ -75,9 +75,19 @@ If you would like to contribute a new dataset, please see [here](#New-dataset).
7575

7676
### Code formatting and typing
7777

78-
New code should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please run
78+
Contributions should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please
79+
either run
7980
```bash
80-
flake8 --config=setup.cfg .
81+
pre-commit run --all-files
82+
```
83+
or run
84+
```bash
85+
pre-commit install
86+
```
87+
once to perform these checks automatically before every `git commit`. If `pre-commit` is not available you can install
88+
it with
89+
```
90+
pip install pre-commit
8191
```
8292

8393
The codebase has type annotations, please make sure to add type hints if required. We use `mypy` tool for type checking:

android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ allprojects {
3939
ext.deps = [
4040
jsr305: 'com.google.code.findbugs:jsr305:3.0.1',
4141
]
42-

android/test_app/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
android:background="@android:color/black"
1515
android:textColor="@android:color/white" />
1616

17-
</FrameLayout>
17+
</FrameLayout>

docs/source/_static/css/custom_torchvision.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ torchvision it just hides the links. So we have to put them back here */
99
article.pytorch-article .sphx-glr-download-link-note.admonition.note,
1010
article.pytorch-article .reference.download.internal, article.pytorch-article .sphx-glr-signature {
1111
display: block;
12-
}
12+
}

docs/source/_static/img/pytorch-logo-flame.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/source/feature_extraction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ API Reference
126126

127127
.. autofunction:: create_feature_extractor
128128

129-
.. autofunction:: get_graph_node_names
129+
.. autofunction:: get_graph_node_names

examples/cpp/hello_world/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Once both dependencies are sorted, we can start the CMake fun:
1616

1717
| That's it!
1818
| You should now have a ``hello-world`` executable in your ``build`` folder.
19-
Running it will output a (fairly long) tensor of random values to your terminal.
19+
Running it will output a (fairly long) tensor of random values to your terminal.

examples/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Python examples
22

33
The examples in this directory have been moved online in our [gallery
4-
page](https://pytorch.org/vision/stable/auto_examples/index.html).
4+
page](https://pytorch.org/vision/stable/auto_examples/index.html).

gallery/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Example gallery
22
===============
33

4-
Below is a gallery of examples
4+
Below is a gallery of examples

gallery/assets/imagenet_class_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ios/VisionTestApp/VisionTestApp/ViewController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55

66

77
@end
8-

packaging/vs2017/install_activate.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" (
2727
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
2828
echo popd
2929
)
30-

packaging/vs2019/install_activate.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" (
2727
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
2828
echo popd
2929
)
30-

references/classification/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,3 @@ For post training quant, device is set to CPU. For training, the device is set t
151151
```
152152
python train_quantization.py --device='cpu' --test-only --backend='<backend>' --model='<model_name>'
153153
```
154-

references/detection/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ python -m torch.distributed.launch --nproc_per_node=8 --use_env train.py\
7979
--dataset coco_kp --model keypointrcnn_resnet50_fpn --epochs 46\
8080
--lr-steps 36 43 --aspect-ratio-group-factor 3
8181
```
82-

test/test_video_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
"DecoderResult", "vframes vframe_pts vtimebase aframes aframe_pts atimebase"
113113
)
114114

115-
"""av_seek_frame is imprecise so seek to a timestamp earlier by a margin
116-
The unit of margin is second"""
115+
# av_seek_frame is imprecise so seek to a timestamp earlier by a margin
116+
# The unit of margin is second
117117
seek_frame_margin = 0.25
118118

119119

0 commit comments

Comments
 (0)