Skip to content

Ruff lints the whole repo #729

@lpozo

Description

@lpozo

ℹ️ Please note that the best way to get support for Real Python courses & articles is to join one of our weekly Office Hours calls or in the RP Community Slack.

You can report issues and problems here, but we typically won't be able to provide 1:1 support outside the channels listed above.

Describe the bug

Currently, Ruff lints all the files in the repo, which can be inefficient.

To Reproduce
Steps to reproduce the behavior:

  1. Open a PR and take a look at the Ruff check details.

Expected behavior
Lint only the modified Python files.

Additional context
Proposed update to file .github/workflows/linters.yaml

- name: Check code style
      run: |
        . venv/bin/activate
        if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
          git fetch origin ${{ github.base_ref }}
          CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.sha }} -- '*.py')
        else
          CHANGED_FILES=$(git diff --name-only HEAD^ -- '*.py')
        fi
        if [ -n "$CHANGED_FILES" ]; then
          python -m ruff format --check $CHANGED_FILES
          python -m ruff check $CHANGED_FILES
        fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions