Skip to content

Commit

Permalink
Add auto-formatters as pre-commit hooks (pytorch#147)
Browse files Browse the repository at this point in the history
Summary:
This adds a couple of [`pre-commit` hooks](https://pre-commit.com) for auto-formatting files in the repository. The include mainly [`black`](https://github.com/psf/black) and [`usort`](https://github.com/facebookexperimental/usort) that are run through [`ufmt`](https://ufmt.omnilib.dev/en/stable/) and are fully compatible with Meta internal workflows. In addition, [`flake8`](https://github.com/pycqa/flake8) can also be run through this framework.

To install the hooks `pip install pre-commit first` and afterwards run `pre-commit install` inside the repository. Now, every time you `git commit` something, these hooks will run and make sure the code format is correct. You can also invoke them manually with `pre-commit run`, which will check all staged files.

For now I only included the configuration files. If they are approved, I'll pull the trigger and push all changes that need to be made to the repository to be compatible with the format.

Pull Request resolved: pytorch#147

Reviewed By: VitalyFedyunin

Differential Revision: D33404517

Pulled By: ejguan

fbshipit-source-id: 42ccc8c5a83dc6fc1f674323fb6eed4cb383fe74
  • Loading branch information
pmeier authored and facebook-github-bot committed Jan 5, 2022
1 parent 6b5a959 commit c3ad9c0
Show file tree
Hide file tree
Showing 52 changed files with 583 additions and 483 deletions.
107 changes: 54 additions & 53 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@ name: 🐛 Bug Report
description: Create a report to help us reproduce and fix the bug

body:
- type: markdown
attributes:
value: >
#### Before submitting a bug, please make sure the issue hasn't been already addressed by searching through [the existing and past issues](https://github.com/pytorch/data/issues?q=is%3Aissue+sort%3Acreated-desc+).
- type: textarea
attributes:
label: 🐛 Describe the bug
description: |
Please provide a clear and concise description of what the bug is.
If relevant, add a minimal example so that we can reproduce the error by running the code. It is very important for the snippet to be as succinct (minimal) as possible, so please take time to trim down any irrelevant code to help us debug efficiently. We are going to copy-paste your code and we expect to get the same result as you did: avoid any external data, and include the relevant imports, etc. For example:
```python
# All necessary imports at the beginning
import torch
import torchdata
# A succinct reproducing example trimmed down to the essential parts:
t = torch.rand(5, 10) # Note: the bug is here, we should pass requires_grad=True
t.sum().backward()
```
If the code is too long (hopefully, it isn't), feel free to put it in a public gist and link it in the issue: https://gist.github.com.
Please also paste or describe the results you observe instead of the expected results. If you observe an error, please paste the error message including the **full** traceback of the exception. It may be relevant to wrap error messages in ```` ```triple quotes blocks``` ````.
placeholder: |
A clear and concise description of what the bug is.
```python
Sample code to reproduce the problem
```
```
The error message you got, with the full traceback.
```
validations:
required: true
- type: textarea
attributes:
label: Versions
description: |
Please run the following and paste the output below. Make sure the version numbers of all relevant packages (e.g. torch, torchdata, other domain packages) are included.
```sh
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```
validations:
required: true
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
- type: markdown
attributes:
value: >
#### Before submitting a bug, please make sure the issue hasn't been already addressed by searching through [the
existing and past issues](https://github.com/pytorch/data/issues?q=is%3Aissue+sort%3Acreated-desc+).
- type: textarea
attributes:
label: 🐛 Describe the bug
description: |
Please provide a clear and concise description of what the bug is.
If relevant, add a minimal example so that we can reproduce the error by running the code. It is very important for the snippet to be as succinct (minimal) as possible, so please take time to trim down any irrelevant code to help us debug efficiently. We are going to copy-paste your code and we expect to get the same result as you did: avoid any external data, and include the relevant imports, etc. For example:
```python
# All necessary imports at the beginning
import torch
import torchdata
# A succinct reproducing example trimmed down to the essential parts:
t = torch.rand(5, 10) # Note: the bug is here, we should pass requires_grad=True
t.sum().backward()
```
If the code is too long (hopefully, it isn't), feel free to put it in a public gist and link it in the issue: https://gist.github.com.
Please also paste or describe the results you observe instead of the expected results. If you observe an error, please paste the error message including the **full** traceback of the exception. It may be relevant to wrap error messages in ```` ```triple quotes blocks``` ````.
placeholder: |
A clear and concise description of what the bug is.
```python
Sample code to reproduce the problem
```
```
The error message you got, with the full traceback.
```
validations:
required: true
- type: textarea
attributes:
label: Versions
description: |
Please run the following and paste the output below. Make sure the version numbers of all relevant packages (e.g. torch, torchdata, other domain packages) are included.
```sh
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```
validations:
required: true
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
36 changes: 20 additions & 16 deletions .github/ISSUE_TEMPLATE/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ name: 📚 Documentation
description: Report an issue related to inline documnetation

body:
- type: textarea
attributes:
label: 📚 The doc issue
description: >
A clear and concise description of what content in within the inline documentation has an issue. We should have additional documentation on the PyTorch website soon. If this has to do with the general https://pytorch.org website, please file an issue at https://github.com/pytorch/pytorch.github.io/issues/new/choose instead. If this has to do with https://pytorch.org/tutorials, please file an issue at https://github.com/pytorch/tutorials/issues/new.
validations:
required: true
- type: textarea
attributes:
label: Suggest a potential alternative/fix
description: >
Tell us how we could improve the documentation in this regard.
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
- type: textarea
attributes:
label: 📚 The doc issue
description: >
A clear and concise description of what content in within the inline documentation has an issue. We should have
additional documentation on the PyTorch website soon. If this has to do with the general https://pytorch.org
website, please file an issue at https://github.com/pytorch/pytorch.github.io/issues/new/choose instead. If this
has to do with https://pytorch.org/tutorials, please file an issue at
https://github.com/pytorch/tutorials/issues/new.
validations:
required: true
- type: textarea
attributes:
label: Suggest a potential alternative/fix
description: >
Tell us how we could improve the documentation in this regard.
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
58 changes: 30 additions & 28 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@ name: 🚀 Feature request
description: Submit a proposal/request for a new TorchData feature

body:
- type: textarea
attributes:
label: 🚀 The feature
description: >
A clear and concise description of the feature proposal
validations:
required: true
- type: textarea
attributes:
label: Motivation, pitch
description: >
Please outline the motivation for the proposal. Is your feature request related to a specific problem? e.g., *"I'm working on X and would like Y to be possible"*. If this is related to another GitHub issue, please link here too.
validations:
required: true
- type: textarea
attributes:
label: Alternatives
description: >
A description of any alternative solutions or features you've considered, if any.
- type: textarea
attributes:
label: Additional context
description: >
Add any other context or screenshots about the feature request.
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
- type: textarea
attributes:
label: 🚀 The feature
description: >
A clear and concise description of the feature proposal
validations:
required: true
- type: textarea
attributes:
label: Motivation, pitch
description: >
Please outline the motivation for the proposal. Is your feature request related to a specific problem? e.g.,
*"I'm working on X and would like Y to be possible"*. If this is related to another GitHub issue, please link
here too.
validations:
required: true
- type: textarea
attributes:
label: Alternatives
description: >
A description of any alternative solutions or features you've considered, if any.
- type: textarea
attributes:
label: Additional context
description: >
Add any other context or screenshots about the feature request.
- type: markdown
attributes:
value: >
Thanks for contributing 🎉!
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Fixes #{issue number}

### Changes

-
-
-
-
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:

jobs:
test:
if: ${{ github.repository_owner == 'pytorch' && (github.event.action != 'labeled' || startsWith(github.event.label.name, 'ciflow')) }}
if:
${{ github.repository_owner == 'pytorch' && (github.event.action != 'labeled' ||
startsWith(github.event.label.name, 'ciflow')) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ name: Lint

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
flake8-py3:
style:
if: ${{ github.repository_owner == 'pytorch' }}
runs-on: ubuntu-latest
steps:
- name: Setup Python environment
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.7"
- name: Check out source repository
uses: actions/checkout@v2
- name: Run flake8
uses: py-actions/flake8@v1
- name: Install lint utilities
run: |
pip install pre-commit
pre-commit install-hooks
- name: Lint Python code and config files
run: pre-commit run --all-files
- name: Required modifications
if: ${{ failure() }}
run: git --no-pager diff

mypy:
if: ${{ github.repository_owner == 'pytorch' }}
Expand Down
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-docstring-first
- id: mixed-line-ending
args: [--fix=lf]
- id: end-of-file-fixer

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
- id: prettier
types_or:
- markdown
- toml
- yaml

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/omnilib/ufmt
rev: v1.3.1
hooks:
- id: ufmt
additional_dependencies:
- black == 21.12b0
- usort == 1.0.0

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
2 changes: 2 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proseWrap: always
printWidth: 120
Loading

0 comments on commit c3ad9c0

Please sign in to comment.