From c2f7780a09b9eda38f76b41b00ff1d4bbbab988a Mon Sep 17 00:00:00 2001 From: KepingYan Date: Fri, 5 Jan 2024 16:12:58 +0800 Subject: [PATCH] add pre-commit, port from https://github.com/intel-sandbox/llm-ray/pull/185 --- .github/workflows/workflow_lint.yml | 22 +++++++++++++++ .github/workflows/workflow_orders_on_pr.yml | 2 ++ .pre-commit-config.yaml | 30 +++++++++++++++++++++ format.sh | 24 +++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 .github/workflows/workflow_lint.yml create mode 100644 .pre-commit-config.yaml create mode 100644 format.sh diff --git a/.github/workflows/workflow_lint.yml b/.github/workflows/workflow_lint.yml new file mode 100644 index 000000000..f2547310f --- /dev/null +++ b/.github/workflows/workflow_lint.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/workflow_orders_on_pr.yml b/.github/workflows/workflow_orders_on_pr.yml index 2c8f93f3d..1d8db2d29 100644 --- a/.github/workflows/workflow_orders_on_pr.yml +++ b/.github/workflows/workflow_orders_on_pr.yml @@ -16,6 +16,8 @@ on: - 'pyproject.toml' jobs: + call-lint: + uses: ./.github/workflows/workflow_lint.yml call-inference: uses: ./.github/workflows/workflow_inference.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bce469086 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 \ No newline at end of file diff --git a/format.sh b/format.sh new file mode 100644 index 000000000..1ebf0f653 --- /dev/null +++ b/format.sh @@ -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 $? \ No newline at end of file