This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add black and flake8 as pre-commit hook
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[flake8] | ||
ignore = E203, E266, E501, W503, F403, F401, B009, B011, C812, E741, PIE781, SFS101, SFS301 | ||
max-line-length = 79 | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9 | ||
inline-quotes = double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 19.3b0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-docstring-first | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: double-quote-string-fixer | ||
- id: name-tests-test | ||
- id: requirements-txt-fixer | ||
- id: check-json | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
files: \.py$ | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.8.0 | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: [ | ||
'flake8-blind-except', | ||
'flake8-bugbear', | ||
'flake8-comprehensions', | ||
'flake8-docstrings', | ||
'flake8-implicit-str-concat', | ||
'flake8-quotes', | ||
'flake8-rst-docstrings', | ||
'pydocstyle>=5.0.0', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Integrating black and flake8 as pre-commit hook | ||
|
||
Black and flake8 are two of the most important code formatters. This ensures that every code is well formatted and organized. | ||
|
||
### Setting up the pre-commit hook | ||
##### What does this pre-commit hook do ? | ||
This pre-commit hook ensures that the code is well formatted before a commit is made. | ||
|
||
##### Steps to run this pre-commit hook | ||
1. Update your local, cloned repository | ||
```bash | ||
$ git pull upstream <branch-name> | ||
``` | ||
2. Move the file named : ```pre-push``` to ```.git``` folder. | ||
3. Install the git hook | ||
```bash | ||
$ pre-commit install | ||
``` | ||
###### NOTE: In case you do not have pre-commit,you can simply pip install it and then run step 2. | ||
```bash | ||
pip install pre-commit | ||
``` | ||
4. Now stage your changes and commit them. You will see that the checks will run automatically. | ||
5. If you check the status, you will the code related files have been modified automatically. | ||
```bash | ||
$ git status | ||
``` | ||
If you go and check the files on your local machine/editor, you will see that the code has been formatted. | ||
6. Stage the modified files and follow the normal steps for generating a pull request. | ||
```bash | ||
$ git add <file-name> | ||
... | ||
$ git commit -m "<commit message>" --no-verify | ||
... | ||
$ git push origin <branch-name> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
if [ -f .git/hooks/pre-commit ]; | ||
then | ||
exit 0 | ||
else | ||
echo "Unstage changes and install pre-commit first(COMMAND : $ pre-commit install). Then commit." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[tool.black] | ||
line-length = 79 | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
/( | ||
\.git | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
)/ | ||
''' |
Binary file not shown.