diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 3760cdb72..000000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -exclude = .git,.history,.github,config,docs,lib,scripts,src,test -ignore = E401,E203,W503,C901,E501,E722,E302,E303,E306,E741,F841,W605,E721 - -max-complexity=10 diff --git a/.github/workflows/ci-build_test.yaml b/.github/workflows/ci-build_test.yaml index 05a827591..f896b60c0 100644 --- a/.github/workflows/ci-build_test.yaml +++ b/.github/workflows/ci-build_test.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dorny/paths-filter@v2 id: changes diff --git a/.github/workflows/ci-builder.yaml b/.github/workflows/ci-builder.yaml index 14b8f2d4d..edc51cbd9 100644 --- a/.github/workflows/ci-builder.yaml +++ b/.github/workflows/ci-builder.yaml @@ -11,7 +11,7 @@ jobs: timeout-minutes: 15 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to Docker Hub uses: docker/login-action@v2 diff --git a/.github/workflows/ci-static_analysis.yaml b/.github/workflows/ci-static_analysis.yaml index 9aacedd66..d3c8d9bec 100644 --- a/.github/workflows/ci-static_analysis.yaml +++ b/.github/workflows/ci-static_analysis.yaml @@ -1,31 +1,11 @@ # Perform continuous integration tests on pull requests -name: black +name: Ruff on: pull_request jobs: - black: + ruff: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - name: Setup python - - uses: actions/setup-python@v4 - with: - python-version: 3.11 - cache-dependency-path: scripts/requirements_dev.txt - cache: "pip" - - - name: Pip install - run: pip install -r scripts/requirements_dev.txt - - - name: Black - run: | - echo "running black..." - black --version - black klippy --check - - - name: Flake8 - run: | - echo "running flake8..." - flake8 --config .flake8 + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 diff --git a/.github/workflows/klipper3d-deploy.yaml b/.github/workflows/klipper3d-deploy.yaml index 55a92298a..4754cffb8 100644 --- a/.github/workflows/klipper3d-deploy.yaml +++ b/.github/workflows/klipper3d-deploy.yaml @@ -12,12 +12,12 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.10" - uses: actions/cache@v3 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1587d433c..c90a45852 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: '^docs/|config/|lib/' +exclude: "^docs/|config/|lib/" default_stages: [commit] repos: @@ -17,17 +17,9 @@ repos: - id: end-of-file-fixer - id: check-builtin-literals - - repo: https://github.com/psf/black - rev: 22.6.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.5 hooks: - - id: black - - - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 - hooks: - - id: flake8 - - - repo: https://github.com/pre-commit/mirrors-autopep8 - rev: v1.7.0 - hooks: - - id: autopep8 + - id: ruff + args: [--fix] + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 495e09251..399758a68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,23 @@ -[tool.black] +[tool.ruff] line-length = 80 -include = '\.pyi?$' -exclude = ''' -( - \.github/ - | \.history/ - | config/ - | docs/ - | lib/ - | src/ -) -''' +indent-width = 4 +exclude = [ + ".github", + ".history", + "config", + "docs", + "lib", + "src" +] + +[tool.ruff.lint] +ignore = [ + "E401", # Multiple imports on one line + "C901", # Function is too complex + "E501", # Line too long (82 > 79 characters) + "E302", # Expected 2 blank lines, found 0 + "E722", # Do not use bare except, specify exception instead + "E741", # Do not use variables named 'I', 'O', or 'l' + "F841", # Local variable name is assigned to but never used + "E721", # Do not compare types, use 'isinstance()' +] diff --git a/scripts/python-format.sh b/scripts/python-format.sh index da3aa7855..91c424b89 100755 --- a/scripts/python-format.sh +++ b/scripts/python-format.sh @@ -25,10 +25,7 @@ fi set +e # Formatters are allowed to fail -black $BLACK_ARGS "${PYFILES[@]}" -autoflake --in-place "${PYFILES[@]}" -autopep8 --in-place -a -a "${PYFILES[@]}" -black $BLACK_ARGS "${PYFILES[@]}" +ruff check --fix "${PYFILES[@]}" if [ "$AMEND" ]; then git add -u "${PYFILES[@]}" diff --git a/scripts/requirements_dev.txt b/scripts/requirements_dev.txt index d2aebf84b..06d82985f 100644 --- a/scripts/requirements_dev.txt +++ b/scripts/requirements_dev.txt @@ -1,6 +1,3 @@ # This file describes the Python virtualenv package requirements for # klipper CI checks and local development. -black==22.6.0 -flake8==5.0.4 -autopep8==1.7.0 -autoflake==1.4 + ruff==0.4.5