Skip to content

Commit

Permalink
Pre-commit (#448)
Browse files Browse the repository at this point in the history
* Pre-commit

* modify CI

* modify make file

* temporarily disable codespell

* update make file

* update contribution guide

* pushc changes
  • Loading branch information
vwxyzjn authored Jun 23, 2023
1 parent b56e8b3 commit 82c8f20
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 36 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ on:
branches: [ main ]

jobs:

check_code_quality:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v2
with:
python-version: "3.8"
cache: "pip"
cache-dependency-path: |
setup.py
requirements.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Check quality
run: |
make quality
fetch-depth: 0
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: pre-commit/action@v2.0.3
with:
extra_args: --all-files

tests:
needs: check_code_quality
Expand Down
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --profile=black
- --skip-glob=wandb/**/*
- --thirdparty=wandb
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- -r
- --exclude=wandb,__init__.py
- --in-place
- --remove-unused-variables
- --remove-all-unused-imports
- repo: https://github.com/python/black
rev: 22.3.0
hooks:
- id: black
args:
- --line-length=119
- --target-version=py38
- --exclude=wandb
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args:
- --ignore=E203,E501,W503,E128
- --max-line-length=119

# - repo: https://github.com/codespell-project/codespell
# rev: v2.1.0
# hooks:
# - id: codespell
# args:
# - --ignore-words-list=nd,reacher,thist,ths,magent,ba
# - --skip=docs/css/termynal.css,docs/js/termynal.js
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ First you want to make sure that all the tests pass:
make test
```

Then before submitting your PR make sure the code quality follows the standards. You can run the following command to format and test:
Then before submitting your PR make sure the code quality follows the standards. You can run the following command to format:

```bash
make style && make quality
make commit
```

## Do you want to contribute to the documentation?
Expand Down
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
.PHONY: quality style test
.PHONY: test precommit

check_dirs := examples tests trl

test:
python -m pytest -n auto --dist=loadfile -s -v ./tests/

quality:
black --check --line-length 119 --target-version py38 $(check_dirs)
isort --check-only $(check_dirs)
flake8 $(check_dirs)

style:
black --line-length 119 --target-version py38 $(check_dirs)
isort $(check_dirs)
precommit:
pre-commit run --all-files
7 changes: 4 additions & 3 deletions scripts/stale.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
Script to close stale issue. Taken in part from the AllenNLP repository.
https://github.com/allenai/allennlp.
"""
from datetime import datetime as dt
import os
from datetime import datetime as dt

from github import Github

Expand All @@ -37,7 +37,8 @@ def main():
comments = sorted([comment for comment in issue.get_comments()], key=lambda i: i.created_at, reverse=True)
last_comment = comments[0] if len(comments) > 0 else None
if (
last_comment is not None and last_comment.user.login == "github-actions[bot]"
last_comment is not None
and last_comment.user.login == "github-actions[bot]"
and (dt.utcnow() - issue.updated_at).days > 7
and (dt.utcnow() - issue.created_at).days >= 30
and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
Expand All @@ -56,4 +57,4 @@ def main():


if __name__ == "__main__":
main()
main()
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ line_length = 119
lines_after_imports = 2
multi_line_output = 3
use_parentheses = True

[flake8]
ignore = E203, E501, W503
max-line-length = 119
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
Then push the change with a message 'set dev version'
"""

from setuptools import setup, find_packages
from setuptools import find_packages, setup


__version__ = "0.4.7.dev0" # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)

Expand All @@ -68,7 +69,7 @@
EXTRAS = {
"test": ["parameterized", "pytest", "pytest-xdist", "accelerate", "peft"],
"peft": ["peft>=0.2.0"],
"dev": ["parameterized", "pytest", "pytest-xdist", "black", "isort", "flake8>=3.8.3", "peft>=0.2.0"],
"dev": ["parameterized", "pytest", "pytest-xdist", "pre-commit", "peft>=0.2.0"],
}

setup(
Expand Down

0 comments on commit 82c8f20

Please sign in to comment.