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

0 commit comments

Comments
 (0)