Skip to content

Commit

Permalink
add pre-commit, port from intel-sandbox/llm-ray#185
Browse files Browse the repository at this point in the history
  • Loading branch information
KepingYan committed Jan 5, 2024
1 parent 91f3756 commit c2f7780
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/workflow_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on:
workflow_call:
inputs:
ci_type:
type: string
default: 'pr'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-ft
cancel-in-progress: true

jobs:
lint:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run Lint
run: ./format.sh -a
2 changes: 2 additions & 0 deletions .github/workflows/workflow_orders_on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
- 'pyproject.toml'

jobs:
call-lint:
uses: ./.github/workflows/workflow_lint.yml

call-inference:
uses: ./.github/workflows/workflow_inference.yml
Expand Down
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

# Black needs to be ran after ruff with --fix
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.950"
hooks:
- id: mypy
# NOTE: Exclusions are handled in pyproject.toml
exclude: tests
additional_dependencies:
- mypy-extensions
- pydantic==1.10.0
- types-cachetools
- types-filelock
- types-PyYAML
- types-redis
- types-requests
24 changes: 24 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# Formats the files by running pre-commit hooks.

while getopts 'ah' opt; do
case "$opt" in
a)
pip install -q pre-commit
pre-commit install
pre-commit run --all-files
exit $?
;;

"?"|h)
echo -e "Usage: $(basename "$0") [-a]\n\t-a\trun on all files\n\t-h\tshow this help message"
exit 1
;;
esac
done
shift "$((OPTIND -1))"

pip install -q pre-commit
pre-commit install
pre-commit run
exit $?

0 comments on commit c2f7780

Please sign in to comment.