Drop flake8 in favor of Ruff (#89863)

This commit is contained in:
Franck Nijhof 2023-03-17 13:30:06 +01:00 committed by GitHub
parent f4de050904
commit b1a3bfb298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 5 additions and 175 deletions

View File

@ -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",

View File

@ -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

View File

@ -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
}
]
}
]
}

View File

@ -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:

14
.vscode/tasks.json vendored
View File

@ -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",

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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"]

View File

@ -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

View File

@ -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 "=============="

View File

@ -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),
)

View File

@ -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