Unverified Commit bc3f8f6c authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

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: default avatarNicolas Hug <contact@nicolas-hug.com>

* remove some hooks

* fix docstrings

* fix end of files
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
parent c359d8d5
...@@ -192,8 +192,9 @@ jobs: ...@@ -192,8 +192,9 @@ jobs:
- checkout - checkout
- run: - run:
command: | command: |
pip install --user --progress-bar off flake8 typing pip install --user --progress-bar off pre-commit
flake8 --config=setup.cfg . pre-commit install-hooks
- run: pre-commit run --all-files
python_type_check: python_type_check:
docker: docker:
......
...@@ -192,8 +192,9 @@ jobs: ...@@ -192,8 +192,9 @@ jobs:
- checkout - checkout
- run: - run:
command: | command: |
pip install --user --progress-bar off flake8 typing pip install --user --progress-bar off pre-commit
flake8 --config=setup.cfg . pre-commit install-hooks
- run: pre-commit run --all-files
python_type_check: python_type_check:
docker: docker:
......
...@@ -21,8 +21,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ...@@ -21,8 +21,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
"""
"""A wrapper script around clang-format, suitable for linting multiple files A wrapper script around clang-format, suitable for linting multiple files
and to use for continuous integration. and to use for continuous integration.
This is an alternative API for the clang-format command line. This is an alternative API for the clang-format command line.
......
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda% start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%
\ No newline at end of file
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
args: [--config=setup.cfg]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-docstring-first
- id: check-toml
- id: check-yaml
exclude: packaging/.*
- id: end-of-file-fixer
...@@ -64,7 +64,7 @@ If you plan to modify the code or documentation, please follow the steps below: ...@@ -64,7 +64,7 @@ If you plan to modify the code or documentation, please follow the steps below:
2. If you have modified the code (new feature or bug-fix), please add unit tests. 2. If you have modified the code (new feature or bug-fix), please add unit tests.
3. If you have changed APIs, update the documentation. Make sure the documentation builds. 3. If you have changed APIs, update the documentation. Make sure the documentation builds.
4. Ensure the test suite passes. 4. Ensure the test suite passes.
5. Make sure your code passes `flake8` formatting check. 5. Make sure your code passes the formatting checks (see below).
For more details about pull requests, For more details about pull requests,
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request). 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). ...@@ -75,9 +75,19 @@ If you would like to contribute a new dataset, please see [here](#New-dataset).
### Code formatting and typing ### Code formatting and typing
New code should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please run Contributions should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please
either run
```bash ```bash
flake8 --config=setup.cfg . pre-commit run --all-files
```
or run
```bash
pre-commit install
```
once to perform these checks automatically before every `git commit`. If `pre-commit` is not available you can install
it with
```
pip install pre-commit
``` ```
The codebase has type annotations, please make sure to add type hints if required. We use `mypy` tool for type checking: The codebase has type annotations, please make sure to add type hints if required. We use `mypy` tool for type checking:
......
...@@ -39,4 +39,3 @@ allprojects { ...@@ -39,4 +39,3 @@ allprojects {
ext.deps = [ ext.deps = [
jsr305: 'com.google.code.findbugs:jsr305:3.0.1', jsr305: 'com.google.code.findbugs:jsr305:3.0.1',
] ]
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
android:background="@android:color/black" android:background="@android:color/black"
android:textColor="@android:color/white" /> android:textColor="@android:color/white" />
</FrameLayout> </FrameLayout>
\ No newline at end of file
...@@ -9,4 +9,4 @@ torchvision it just hides the links. So we have to put them back here */ ...@@ -9,4 +9,4 @@ torchvision it just hides the links. So we have to put them back here */
article.pytorch-article .sphx-glr-download-link-note.admonition.note, article.pytorch-article .sphx-glr-download-link-note.admonition.note,
article.pytorch-article .reference.download.internal, article.pytorch-article .sphx-glr-signature { article.pytorch-article .reference.download.internal, article.pytorch-article .sphx-glr-signature {
display: block; display: block;
} }
\ No newline at end of file
...@@ -30,4 +30,4 @@ ...@@ -30,4 +30,4 @@
style="fill:#9e529f" style="fill:#9e529f"
id="path4698" id="path4698"
d="m 24.075479,-7.6293945e-7 c -0.5,0 -1.8,2.49999996293945 -1.8,3.59999996293945 0,1.5 1,2 1.8,2 0.8,0 1.8,-0.5 1.8,-2 -0.1,-1.1 -1.4,-3.59999996293945 -1.8,-3.59999996293945 z" d="m 24.075479,-7.6293945e-7 c -0.5,0 -1.8,2.49999996293945 -1.8,3.59999996293945 0,1.5 1,2 1.8,2 0.8,0 1.8,-0.5 1.8,-2 -0.1,-1.1 -1.4,-3.59999996293945 -1.8,-3.59999996293945 z"
class="st1" /></svg> class="st1" /></svg>
\ No newline at end of file
...@@ -126,4 +126,4 @@ API Reference ...@@ -126,4 +126,4 @@ API Reference
.. autofunction:: create_feature_extractor .. autofunction:: create_feature_extractor
.. autofunction:: get_graph_node_names .. autofunction:: get_graph_node_names
\ No newline at end of file
...@@ -16,4 +16,4 @@ Once both dependencies are sorted, we can start the CMake fun: ...@@ -16,4 +16,4 @@ Once both dependencies are sorted, we can start the CMake fun:
| That's it! | That's it!
| You should now have a ``hello-world`` executable in your ``build`` folder. | You should now have a ``hello-world`` executable in your ``build`` folder.
Running it will output a (fairly long) tensor of random values to your terminal. Running it will output a (fairly long) tensor of random values to your terminal.
\ No newline at end of file
# Python examples # Python examples
The examples in this directory have been moved online in our [gallery The examples in this directory have been moved online in our [gallery
page](https://pytorch.org/vision/stable/auto_examples/index.html). page](https://pytorch.org/vision/stable/auto_examples/index.html).
\ No newline at end of file
Example gallery Example gallery
=============== ===============
Below is a gallery of examples Below is a gallery of examples
\ No newline at end of file
This diff is collapsed.
...@@ -5,4 +5,3 @@ ...@@ -5,4 +5,3 @@
@end @end
...@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" ( ...@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" (
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo popd echo popd
) )
...@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" ( ...@@ -27,4 +27,3 @@ IF "%cross_compiler_target_platform%" == "win-64" (
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
echo popd echo popd
) )
...@@ -151,4 +151,3 @@ For post training quant, device is set to CPU. For training, the device is set t ...@@ -151,4 +151,3 @@ For post training quant, device is set to CPU. For training, the device is set t
``` ```
python train_quantization.py --device='cpu' --test-only --backend='<backend>' --model='<model_name>' python train_quantization.py --device='cpu' --test-only --backend='<backend>' --model='<model_name>'
``` ```
...@@ -79,4 +79,3 @@ python -m torch.distributed.launch --nproc_per_node=8 --use_env train.py\ ...@@ -79,4 +79,3 @@ python -m torch.distributed.launch --nproc_per_node=8 --use_env train.py\
--dataset coco_kp --model keypointrcnn_resnet50_fpn --epochs 46\ --dataset coco_kp --model keypointrcnn_resnet50_fpn --epochs 46\
--lr-steps 36 43 --aspect-ratio-group-factor 3 --lr-steps 36 43 --aspect-ratio-group-factor 3
``` ```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment