Skip to content

Commit b287fba

Browse files
authored
MNT Add pre-commit hooks (#807)
* add pre-commit hooks * add to contribuging guides * add a note how to permanently disable hooks
1 parent 8a43817 commit b287fba

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-case-conflict
9+
- id: check-merge-conflict
10+
- repo: https://github.com/psf/black
11+
rev: 22.3.0
12+
hooks:
13+
- id: black
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 4.0.1
16+
hooks:
17+
- id: flake8
18+
types: [file, python]
19+
- repo: https://github.com/PyCQA/isort
20+
rev: 5.10.1
21+
hooks:
22+
- id: isort

CONTRIBUTING.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ file explaining how you may test your code.
7272

7373
## Documentation
7474

75-
The content in the `docs` folder is the official [Hugging Face Hub documentation]. It is not limited to the
75+
The content in the `docs` folder is the official [Hugging Face Hub documentation]. It is not limited to the
7676
Python package `huggingface_hub`, as it includes guides on using the frontend, ho to build Spaces, how to search
7777
efficiently, and others.
7878

@@ -100,7 +100,7 @@ Did not find it? :( So we can act quickly on it, please follow these steps:
100100
**Tensorflow** when applicable;
101101
* A short, self-contained, code snippet that allows us to reproduce the bug in
102102
less than 30s;
103-
* Provide the *full* traceback if an exception is raised by copying the text from your terminal
103+
* Provide the *full* traceback if an exception is raised by copying the text from your terminal
104104
in the issue description.
105105

106106
### Do you want a new feature?
@@ -167,7 +167,7 @@ Follow these steps to start contributing:
167167

168168
**Do not** work on the `master` branch.
169169

170-
4. Set up a development environment by running the following command in a virtual environment a conda or a
170+
4. Set up a development environment by running the following command in a virtual environment a conda or a
171171
virtual environment you've created for working on this library:
172172

173173
```bash
@@ -181,13 +181,13 @@ Follow these steps to start contributing:
181181
5. Develop the features on your branch.
182182

183183
As you work on the features, you should make sure that the test suite
184-
passes. You should run the tests impacted by your changes like this (see
184+
passes. You should run the tests impacted by your changes like this (see
185185
below an explanation regarding the environment variable):
186186

187187
```bash
188188
$ HUGGINGFACE_CO_STAGING=1 pytest tests/<TEST_TO_RUN>.py
189189
```
190-
190+
191191
> For the following commands leveraging the `make` utility, we recommend using the WSL system when running on
192192
> Windows. More information [here](https://docs.microsoft.com/en-us/windows/wsl/about).
193193
@@ -198,8 +198,26 @@ Follow these steps to start contributing:
198198
```
199199

200200
`hugginface_hub` relies on `black` and `isort` to format its source code
201-
consistently. After you make changes, apply automatic style corrections and code verifications
202-
that can't be automated:
201+
consistently. You can install pre-commit hooks so that these styles are
202+
applied and checked on files that you have touched in each commit:
203+
204+
```bash
205+
pip install pre-commit
206+
pre-commit install
207+
```
208+
209+
You only need to do the above once in your repository's environment. If for
210+
any reason you would like to disable pre-commit hooks on a commit, you can
211+
pass `-n` to your `git commit` command to temporarily disable pre-commit
212+
hooks.
213+
214+
To permanently disable hooks, you can run the following command:
215+
```bash
216+
pre-commit uninstall
217+
```
218+
219+
Alternatively, you can apply automatic style corrections and code
220+
verifications manually with the following command:
203221

204222
```bash
205223
$ make style
@@ -225,7 +243,7 @@ Follow these steps to start contributing:
225243
It is a good idea to sync your copy of the code with the original
226244
repository regularly. The following document covers it in length: [github documentation](
227245
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork)
228-
246+
229247
And here's how you can do it quickly from your `git` commandline:
230248

231249
```bash
@@ -255,8 +273,8 @@ Follow these steps to start contributing:
255273
2. If your pull request addresses an issue, please mention the issue number in
256274
the pull request description to make sure they are linked (and people
257275
consulting the issue know you are working on it);
258-
3. To indicate a work in progress please prefix the title with `[WIP]`, or mark
259-
the PR as a draft PR. These are useful to avoid duplicated work, and to differentiate
276+
3. To indicate a work in progress please prefix the title with `[WIP]`, or mark
277+
the PR as a draft PR. These are useful to avoid duplicated work, and to differentiate
260278
it from PRs ready to be merged;
261279
4. Make sure existing tests pass;
262280
5. Add high-coverage tests. No quality testing = no merge.
@@ -272,7 +290,7 @@ An extensive test suite is included to test the library behavior and several exa
272290
the [tests folder](https://github.com/huggingface/huggingface_hub/tree/main/tests).
273291

274292
The `huggingface_hub` library's normal behavior is to work with the production Hugging Face Hub. However,
275-
for tests, we prefer to run on a staging version. In order to do this, it's important to set the
293+
for tests, we prefer to run on a staging version. In order to do this, it's important to set the
276294
`HUGGINGFACE_CO_STAGING` environment variable to `1` when running tests. It is preferred to pass this in when running the tests, than setting a permanent environmental variable, as shown below.
277295

278296
We use `pytest` in order to run the tests for the library . From the root of the

0 commit comments

Comments
 (0)