diff --git a/.github/workflows/lint_fix.yml b/.github/workflows/lint_fix.yml new file mode 100644 index 00000000000..b6da47e2651 --- /dev/null +++ b/.github/workflows/lint_fix.yml @@ -0,0 +1,61 @@ +name: Lint Fix + +on: + pull_request: + branches: + - main + +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + lint-fix: + name: Fix linting issues + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Update pip to the latest version + run: | + python -m pip install --upgrade pip + + - name: Set up Python tools + run: | + make dev + + - name: Run format + run: | + make format + + # Commit and push changes if any + - name: Check for changes + id: git-check + run: | + git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT + git diff --cached --exit-code || echo "changes=true" >> $GITHUB_OUTPUT + + - name: Commit and push if there are changes + if: steps.git-check.outputs.changes == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "github-actions[bot]" + git add -A + git commit -m "🤖 Auto-fix linting issues" || exit 0 + git push + diff --git a/Makefile b/Makefile index 40c80431875..7f226964871 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean deepclean prerequisite dependencies lightgbm rl develop lint docs package test analysis all install dev black pylint flake8 mypy nbqa nbconvert lint build upload docs-gen +.PHONY: clean deepclean prerequisite dependencies lightgbm rl develop lint docs package test analysis all install dev black format pylint flake8 mypy nbqa nbconvert lint build upload docs-gen #You can modify it according to your terminal SHELL := /bin/bash @@ -118,6 +118,11 @@ dev: prerequisite all black: black . -l 120 --check --diff --exclude qlib/_version.py +# Format code with black (auto-fix). +format: + black . -l 120 --exclude qlib/_version.py + nbqa black . -l 120 + # Check code folder with pylint. # TODO: These problems we will solve in the future. Important among them are: W0221, W0223, W0237, E1102 # C0103: invalid-name