Skip to content

Commit 477583a

Browse files
authored
Implement black code formatting as pre-commit hook (DistrictDataLabs#1269)
1 parent 9da4bff commit 477583a

File tree

7 files changed

+84
-8
lines changed

7 files changed

+84
-8
lines changed

.github/workflows/ci.yml

+26-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,29 @@ jobs:
127127
- name: Run Sphinx
128128
uses: ammaraskar/sphinx-action@master
129129
with:
130-
docs-folder: "docs/"
130+
docs-folder: "docs/"
131+
132+
# Run pre-commit checks on the files changed
133+
linting:
134+
runs-on: ubuntu-latest
135+
name: Linting
136+
steps:
137+
- name: Checkout Code
138+
uses: actions/checkout@v2
139+
with:
140+
fetch-depth: 0
141+
142+
- name: Set up Python
143+
uses: actions/setup-python@v2
144+
with:
145+
python-version: 3.9
146+
147+
- name: Install Dependencies
148+
run: |
149+
python -m pip install --upgrade pip
150+
pip install pre-commit
151+
pre-commit install
152+
153+
- name: Run Checks
154+
run: |
155+
pre-commit run --from-ref origin/${{ github.base_ref }} --to-ref HEAD --show-diff-on-failure

.pre-commit-config.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v3.2.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- id: check-json
12+
- id: check-merge-conflict
13+
- repo: https://github.com/psf/black
14+
rev: 22.6.0
15+
hooks:
16+
- id: black
17+
- repo: https://github.com/PyCQA/flake8
18+
rev: 5.0.4
19+
hooks:
20+
- id: flake8
21+
- repo: https://github.com/pre-commit/pygrep-hooks
22+
rev: v1.9.0
23+
hooks:
24+
- id: rst-backticks
25+
- id: rst-directive-colons
26+
- id: rst-inline-touching-normal

CONTRIBUTING.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ Once forked, use the following steps to get your development environment set up
9494
$ pip install -r docs/requirements.txt
9595
```
9696
97-
4. Switch to the develop branch.
97+
4. (Optional) Set up pre-commit hooks.
98+
99+
When opening a PR in the Yellowbrick repository, a series of checks will be run on your contribution, some of which lint and look at the formatting of your code. These may indicate some changes that need to be made before your contribution can be reviewed. You can set up pre-commit hooks to run these checks locally upon running `git commit` to ensure your contribution will pass formatting and linting checks. To set this up, you will need to uncomment the pre-commit line in `requirements.txt` and then run the following commands:
100+
101+
```
102+
$ pip install -r requirements.txt
103+
$ pre-commit install
104+
```
105+
106+
The next time you run `git commit` in the Yellowbrick repository, the checks will automatically run.
107+
108+
5. Switch to the develop branch.
98109
99110
The Yellowbrick repository has a `develop` branch that is the primary working branch for contributions. It is probably already the branch you're on, but you can make sure and switch to it as follows::
100111

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Language Grade: Python](https://img.shields.io/lgtm/grade/python/g/DistrictDataLabs/yellowbrick.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/DistrictDataLabs/yellowbrick/context:python)
88
[![PyPI version](https://badge.fury.io/py/yellowbrick.svg)](https://badge.fury.io/py/yellowbrick)
99
[![Documentation Status](https://readthedocs.org/projects/yellowbrick/badge/?version=latest)](http://yellowbrick.readthedocs.io/en/latest/?badge=latest)
10+
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1011
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1206239.svg)](https://doi.org/10.5281/zenodo.1206239)
1112
[![JOSS](http://joss.theoj.org/papers/10.21105/joss.01075/status.svg)](https://doi.org/10.21105/joss.01075)
1213
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/DistrictDataLabs/yellowbrick/develop?filepath=examples%2Fexamples.ipynb)

docs/contributing/getting_started.rst

+14-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We believe that *contribution is collaboration* and therefore emphasize *communi
1919

2020
Once you have a good sense of how you are going to implement the new feature (or fix the bug!), you can reach out for feedback from the maintainers by creating a `pull request <https://github.com/DistrictDataLabs/yellowbrick/pulls>`_. Ideally, any pull request should be capable of resolution within 6 weeks of being opened. This timeline helps to keep our pull request queue small and allows Yellowbrick to maintain a robust release schedule to give our users the best experience possible. However, the most important thing is to keep the dialogue going! And if you're unsure whether you can complete your idea within 6 weeks, you should still go ahead and open a PR and we will be happy to help you scope it down as needed.
2121

22-
If we have comments or questions when we evaluate your pull request and receive no response, we will also close the PR after this period of time. Please know that this does not mean we don't value your contribution, just that things go stale. If in the future you want to pick it back up, feel free to address our original feedback and to reference the original PR in a new pull request.
22+
If we have comments or questions when we evaluate your pull request and receive no response, we will also close the PR after this period of time. Please know that this does not mean we don't value your contribution, just that things go stale. If in the future you want to pick it back up, feel free to address our original feedback and to reference the original PR in a new pull request.
2323

2424
.. note:: Please note that if we feel your solution has not been thought out in earnest, or if the PR is not aligned with our `current milestone <https://github.com/districtdatalabs/yellowbrick/milestones>`_ goals, we may reach out to ask that you close the PR so that we can prioritize reviewing the most critical feature requests and bug fixes.
2525

@@ -54,22 +54,31 @@ Once forked, use the following steps to get your development environment set up
5454
$ pip install -e .
5555

5656
This will add Yellowbrick to your PYTHONPATH so that you don't need to reinstall it each time you make a change during development.
57-
57+
5858
Note that there may be other dependencies required for development and testing; you can simply install them with ``pip``. For example to install
5959
the additional dependencies for building the documentation or to run the
6060
test suite, use the ``requirements.txt`` files in those directories::
6161

6262
$ pip install -r tests/requirements.txt
6363
$ pip install -r docs/requirements.txt
6464

65-
4. Switch to the develop branch.
65+
4. (Optional) Set up pre-commit hooks.
66+
67+
When opening a PR in the Yellowbrick repository, a series of checks will be run on your contribution, some of which lint and look at the formatting of your code. These may indicate some changes that need to be made before your contribution can be reviewed. You can set up pre-commit hooks to run these checks locally upon running ``git commit`` to ensure your contribution will pass formatting and linting checks. To set this up, you will need to uncomment the pre-commit line in ``requirements.txt`` and then run the following commands::
68+
69+
$ pip install -r requirements.txt
70+
$ pre-commit install
71+
72+
The next time you run ``git commit`` in the Yellowbrick repository, the checks will automatically run.
73+
74+
5. Switch to the develop branch.
6675

6776
The Yellowbrick repository has a ``develop`` branch that is the primary working branch for contributions. It is probably already the branch you're on, but you can make sure and switch to it as follows::
6877

6978
$ git fetch
7079
$ git checkout develop
7180

72-
At this point you're ready to get started writing code.
81+
At this point you're ready to get started writing code.
7382

7483
Branching Convention
7584
--------------------
@@ -89,7 +98,7 @@ We also recommend setting up an ``upstream`` remote so that you can easily pull
8998
upstream https://github.com/DistrictDataLabs/yellowbrick.git (fetch)
9099
upstream https://github.com/DistrictDataLabs/yellowbrick.git (push)
91100

92-
When you're ready, request a code review for your pull request.
101+
When you're ready, request a code review for your pull request.
93102

94103
Pull Requests
95104
-------------

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ cycler>=0.10.0
2525
## Build Requirements (uncomment for deployment)
2626
# wheel>=0.35
2727
# twine>=3.3
28+
29+
## Pre-Commit Requirements (uncomment to use pre-commit hooks)
30+
# pre-commit>=2.20.0

setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ filterwarnings =
3232
[flake8]
3333
# match black maximum line length
3434
max-line-length = 88
35+
extend-ignore = E203
3536
per-file-ignores =
3637
__init__.py:F401
3738
test_*.py:F405,F403
38-
conftest.py:F841
39+
conftest.py:F841

0 commit comments

Comments
 (0)