-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit config yaml file to enable automatic code formatting (#…
…5561) * add precommit config * skip running hooks if no matched files found * fix instructions for using pre-commit
- Loading branch information
1 parent
b91070b
commit a940972
Showing
2 changed files
with
47 additions
and
27 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,15 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 23.1.0 | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
types: [python] | ||
stages: [commit] | ||
args: ["--config", "pyproject.toml", "tests", "src", "benchmarks", "metrics"] | ||
- repo: https://github.com/charliermarsh/ruff-pre-commit | ||
rev: 'v0.0.247' | ||
hooks: | ||
- id: ruff | ||
stages: [commit] | ||
args: [ "--config", "pyproject.toml", "tests", "src", "benchmarks", "metrics", "--fix"] |
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 |
---|---|---|
|
@@ -31,54 +31,59 @@ If you want to add a dataset see specific instructions in the section [*How to a | |
|
||
2. Clone your fork to your local disk, and add the base repository as a remote: | ||
|
||
```bash | ||
git clone [email protected]:<your Github handle>/datasets.git | ||
cd datasets | ||
git remote add upstream https://github.com/huggingface/datasets.git | ||
``` | ||
```bash | ||
git clone [email protected]:<your Github handle>/datasets.git | ||
cd datasets | ||
git remote add upstream https://github.com/huggingface/datasets.git | ||
``` | ||
|
||
3. Create a new branch to hold your development changes: | ||
|
||
```bash | ||
git checkout -b a-descriptive-name-for-my-changes | ||
``` | ||
```bash | ||
git checkout -b a-descriptive-name-for-my-changes | ||
``` | ||
|
||
**do not** work on the `main` branch. | ||
**do not** work on the `main` branch. | ||
|
||
4. Set up a development environment by running the following command in a virtual environment: | ||
|
||
```bash | ||
pip install -e ".[dev]" | ||
``` | ||
```bash | ||
pip install -e ".[dev]" | ||
``` | ||
|
||
(If datasets was already installed in the virtual environment, remove | ||
it with `pip uninstall datasets` before reinstalling it in editable | ||
mode with the `-e` flag.) | ||
|
||
5. Develop the features on your branch. | ||
|
||
6. Format your code. Run black and ruff so that your newly added files look nice with the following command: | ||
6. Format your code. Run `black` and `ruff` so that your newly added files look nice with the following command: | ||
|
||
```bash | ||
make style | ||
``` | ||
|
||
7. _(Optional)_ You can also use [`pre-commit`](https://pre-commit.com/) to format your code automatically each time run `git commit`, instead of running `make style` manually. | ||
To do this, install `pre-commit` via `pip install pre-commit` and then run `pre-commit install` in the project's root directory to set up the hooks. | ||
Note that if any files were formatted by `pre-commit` hooks during committing, you have to run `git commit` again . | ||
```bash | ||
make style | ||
``` | ||
7. Once you're happy with your contribution, add your changed files and make a commit to record your changes locally: | ||
8. Once you're happy with your contribution, add your changed files and make a commit to record your changes locally: | ||
|
||
```bash | ||
git add -u | ||
git commit | ||
``` | ||
```bash | ||
git add -u | ||
git commit | ||
``` | ||
|
||
It is a good idea to sync your copy of the code with the original | ||
repository regularly. This way you can quickly account for changes: | ||
It is a good idea to sync your copy of the code with the original | ||
repository regularly. This way you can quickly account for changes: | ||
|
||
```bash | ||
git fetch upstream | ||
git rebase upstream/main | ||
```bash | ||
git fetch upstream | ||
git rebase upstream/main | ||
``` | ||
|
||
8. Once you are satisfied, push the changes to your fork repo using: | ||
9. Once you are satisfied, push the changes to your fork repo using: | ||
|
||
```bash | ||
git push -u origin a-descriptive-name-for-my-changes | ||
|