Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Fixes #1035: Add black and flake8 as pre-commit hook #1058

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .flake8
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
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
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',
]
36 changes: 36 additions & 0 deletions pre-commit_documentation.md
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>
```
9 changes: 9 additions & 0 deletions pre-push
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
16 changes: 16 additions & 0 deletions pyproject.toml
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 modified requirements.txt
Binary file not shown.