diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1711ab68fde..042eb94b195 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,7 +20,6 @@ "python.linting.enabled": true, "python.linting.pylintEnabled": true, "python.formatting.blackPath": "/usr/local/bin/black", - "python.linting.flake8Path": "/usr/local/bin/flake8", "python.linting.pycodestylePath": "/usr/local/bin/pycodestyle", "python.linting.pydocstylePath": "/usr/local/bin/pydocstyle", "python.linting.mypyPath": "/usr/local/bin/mypy", diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4ac1075fcb2..f23b28f2c16 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -286,55 +286,6 @@ jobs: shopt -s globstar pre-commit run --hook-stage manual black --files {homeassistant,tests}/components/${{ needs.info.outputs.integrations_glob }}/{*,**/*} --show-diff-on-failure - lint-flake8: - name: Check flake8 - runs-on: ubuntu-22.04 - needs: - - info - - pre-commit - steps: - - name: Check out code from GitHub - uses: actions/checkout@v3.4.0 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v4.5.0 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - check-latest: true - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache/restore@v3.3.1 - with: - path: venv - fail-on-cache-miss: true - key: >- - ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ - needs.info.outputs.pre-commit_cache_key }} - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache/restore@v3.3.1 - with: - path: ${{ env.PRE_COMMIT_CACHE }} - fail-on-cache-miss: true - key: >- - ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ - needs.info.outputs.pre-commit_cache_key }} - - name: Register flake8 problem matcher - run: | - echo "::add-matcher::.github/workflows/matchers/flake8.json" - - name: Run flake8 (fully) - if: needs.info.outputs.test_full_suite == 'true' - run: | - . venv/bin/activate - pre-commit run --hook-stage manual flake8 --all-files - - name: Run flake8 (partially) - if: needs.info.outputs.test_full_suite == 'false' - shell: bash - run: | - . venv/bin/activate - shopt -s globstar - pre-commit run --hook-stage manual flake8 --files {homeassistant,tests}/components/${{ needs.info.outputs.integrations_glob }}/{*,**/*} - lint-ruff: name: Check ruff runs-on: ubuntu-22.04 diff --git a/.github/workflows/matchers/flake8.json b/.github/workflows/matchers/flake8.json deleted file mode 100644 index e059a1cf5f7..00000000000 --- a/.github/workflows/matchers/flake8.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "problemMatcher": [ - { - "owner": "flake8-error", - "severity": "error", - "pattern": [ - { - "regexp": "^(.*):(\\d+):(\\d+):\\s([EF]\\d{3}\\s.*)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4 - } - ] - }, - { - "owner": "flake8-warning", - "severity": "warning", - "pattern": [ - { - "regexp": "^(.*):(\\d+):(\\d+):\\s([CDNW]\\d{3}\\s.*)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4 - } - ] - } - ] -} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af0d3b318e5..8cedb60b8bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,20 +36,6 @@ repos: - --quiet-level=2 exclude_types: [csv, json] exclude: ^tests/fixtures/|homeassistant/generated/ - - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: - - pycodestyle==2.10.0 - - pyflakes==3.0.1 - - flake8-docstrings==1.6.0 - - pydocstyle==6.2.3 - - flake8-comprehensions==3.10.1 - - flake8-noqa==1.3.0 - - mccabe==0.7.0 - exclude: docs/source/conf.py - stages: [manual] - repo: https://github.com/PyCQA/bandit rev: 1.7.4 hooks: diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 849716d7ba8..7af7a426d62 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -42,20 +42,6 @@ }, "problemMatcher": [] }, - { - "label": "Flake8", - "type": "shell", - "command": "pre-commit run flake8 --all-files", - "group": { - "kind": "test", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, - "problemMatcher": [] - }, { "label": "Ruff", "type": "shell", diff --git a/Dockerfile.dev b/Dockerfile.dev index 863ac5690bc..116446d1818 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -5,7 +5,6 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Uninstall pre-installed formatting and linting tools # They would conflict with our pinned versions RUN pipx uninstall black -RUN pipx uninstall flake8 RUN pipx uninstall pydocstyle RUN pipx uninstall pycodestyle RUN pipx uninstall mypy diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 2af959d22fe..02f6e44a700 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -405,7 +405,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: base["params"] = data return base - async def async_handle_light_on_service( + async def async_handle_light_on_service( # noqa: C901 light: LightEntity, call: ServiceCall ) -> None: """Handle turning a light on. diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index cf565b42390..a764b24b2e8 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -99,7 +99,7 @@ async def async_start( # noqa: C901 mqtt_integrations = {} @callback - def async_discovery_message_received(msg: ReceiveMessage) -> None: + def async_discovery_message_received(msg: ReceiveMessage) -> None: # noqa: C901 """Process the received message.""" mqtt_data.last_discovery = time.time() payload = msg.payload diff --git a/pyproject.toml b/pyproject.toml index 082ae3ef2ba..3ee9bc7be5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -292,15 +292,6 @@ keep-runtime-typing = true [tool.ruff.per-file-ignores] -# TODO: these files have functions that are too complex, but flake8's and ruff's -# complexity (and/or nested-function) handling differs; trying to add a noqa doesn't work -# because the flake8-noqa plugin then disagrees on whether there should be a C901 noqa -# on that line. So, for now, we just ignore C901s on these files as far as ruff is concerned. - -"homeassistant/components/light/__init__.py" = ["C901"] -"homeassistant/components/mqtt/discovery.py" = ["C901"] -"homeassistant/components/websocket_api/http.py" = ["C901"] - # Allow for main entry & scripts to write to stdout "homeassistant/__main__.py" = ["T201"] "homeassistant/scripts/*" = ["T201"] diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 0b7c52f85dc..f64f422cc40 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -4,15 +4,7 @@ autoflake==2.0.0 bandit==1.7.4 black==23.1.0 codespell==2.2.2 -flake8-comprehensions==3.10.1 -flake8-docstrings==1.6.0 -flake8-noqa==1.3.0 -flake8==6.0.0 isort==5.12.0 -mccabe==0.7.0 -pycodestyle==2.10.0 -pydocstyle==6.2.3 -pyflakes==3.0.1 pyupgrade==3.3.1 ruff==0.0.256 yamllint==1.28.0 diff --git a/script/lint b/script/lint index 450733cecfd..daafedb2297 100755 --- a/script/lint +++ b/script/lint @@ -12,10 +12,6 @@ if [ -z "$files" ] ; then exit fi printf "%s\n" $files -echo "================" -echo "LINT with flake8" -echo "================" -pre-commit run flake8 --files $files echo "==============" echo "LINT with ruff" echo "==============" diff --git a/script/lint_and_test.py b/script/lint_and_test.py index 630e0eb996e..5a3d448c1f4 100755 --- a/script/lint_and_test.py +++ b/script/lint_and_test.py @@ -116,9 +116,9 @@ async def pylint(files): return res -async def _ruff_or_flake8(tool, files): - """Exec ruff or flake8.""" - _, log = await async_exec("pre-commit", "run", tool, "--files", *files) +async def ruff(files): + """Exec ruff.""" + _, log = await async_exec("pre-commit", "run", "ruff", "--files", *files) res = [] for line in log.splitlines(): line = line.split(":") @@ -129,23 +129,12 @@ async def _ruff_or_flake8(tool, files): return res -async def flake8(files): - """Exec flake8.""" - return await _ruff_or_flake8("flake8", files) - - -async def ruff(files): - """Exec ruff.""" - return await _ruff_or_flake8("ruff", files) - - async def lint(files): """Perform lint.""" files = [file for file in files if os.path.isfile(file)] res = sorted( itertools.chain( *await asyncio.gather( - flake8(files), pylint(files), ruff(files), ) diff --git a/setup.cfg b/setup.cfg index 323c4c10d26..29713b6df46 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,32 +3,3 @@ [metadata] url = https://www.home-assistant.io/ - -[flake8] -exclude = .venv,.git,docs,venv,bin,lib,deps,build -max-complexity = 25 -doctests = True -# To work with Black -# E501: line too long -# W503: Line break occurred before a binary operator -# E203: Whitespace before ':' -# D202 No blank lines allowed after function docstring -# W504 line break after binary operator -ignore = - E501, - W503, - E203, - D202, - W504 -noqa-require-code = True - -# Ignores, that are currently caused by mismatching configurations -# between ruff and flake8 configurations. Once ruff becomes permanent flake8 -# will be removed, including these ignores below. -# In case we decide not to continue with ruff, we should remove these -# and probably need to clean up a couple of noqa comments. -per-file-ignores = - homeassistant/config.py:NQA102 - tests/components/august/mocks.py:NQA102 - tests/components/tts/conftest.py:NQA102 - tests/helpers/test_icon.py:NQA102