Skip to content

Commit

Permalink
Add integration for pre-commit.com (#104)
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
ambv committed Apr 4, 2018
1 parent 0f99987 commit f8e9544
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 8 deletions.
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,19 @@
# Note: don't use this config for your own repositories. Instead, see
# "Version control integration" in README.md.
- repo: local
hooks:
- id: black
name: black
language: system
entry: python3 -m black
files: ^(black|setup|tests/test_black)\.py$
- id: flake8
name: flake8
language: system
entry: flake8
files: ^(black|setup|tests/test_black)\.py$
- id: mypy
name: mypy
language: system
entry: mypy
files: ^(black|setup|tests/test_black)\.py$
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
@@ -0,0 +1,6 @@
- id: black
name: black
entry: black
language: python
language_version: python3.6
types: [python]
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Expand Up @@ -30,6 +30,7 @@ myself and CentOS at work.
Install all development dependencies using:
```
$ pipenv install --dev
$ pre-commit install
```
If you haven't used `pipenv` before but are comfortable with virtualenvs,
just run `pip install pipenv` in the virtualenv you're already using and
Expand All @@ -41,10 +42,6 @@ Before submitting pull requests, run tests with:
$ python setup.py test
```

Also run mypy and flake8 on `black.py` and `test_black.py`. Travis will
run all that for you but if you left any errors here, it will be quicker
and less embarrassing to fix them locally ;-)


## Hygiene

Expand Down
1 change: 1 addition & 0 deletions Pipfile
Expand Up @@ -9,6 +9,7 @@ click = "*"
setuptools = ">=38.6.0"

[dev-packages]
pre-commit = "*"
coverage = "*"
flake8 = "*"
flake8-bugbear = "*"
Expand Down
76 changes: 72 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -357,6 +357,28 @@ affect your use case.
This can be used for example with PyCharm's [File Watchers](https://www.jetbrains.com/help/pycharm/file-watchers.html).


## Version control integration

Use [pre-commit](https://pre-commit.com/). Once you [have it
installed](https://pre-commit.com/#install), add this to the
`.pre-commit-config.yaml` in your repository:
```yaml
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
args: [--line-length=88, --safe]
python-version: python3.6
```
Then run `pre-commit install` and you're ready to go.

`args` in the above config is optional but shows you how you can change
the line length if you really need to. If you're already using Python
3.7, switch the `python-version` accordingly. Finally, `stable` is a tag
that is pinned to the latest release on PyPI. If you'd rather run on
master, this is also an option.

## Testimonials

**Dusty Phillips**, [writer](https://smile.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=dusty+phillips):
Expand Down

0 comments on commit f8e9544

Please sign in to comment.