Drop flake8 in favor of Ruff (#89863)
parent
f4de050904
commit
b1a3bfb298
|
@ -20,7 +20,6 @@
|
||||||
"python.linting.enabled": true,
|
"python.linting.enabled": true,
|
||||||
"python.linting.pylintEnabled": true,
|
"python.linting.pylintEnabled": true,
|
||||||
"python.formatting.blackPath": "/usr/local/bin/black",
|
"python.formatting.blackPath": "/usr/local/bin/black",
|
||||||
"python.linting.flake8Path": "/usr/local/bin/flake8",
|
|
||||||
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
|
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
|
||||||
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
|
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
|
||||||
"python.linting.mypyPath": "/usr/local/bin/mypy",
|
"python.linting.mypyPath": "/usr/local/bin/mypy",
|
||||||
|
|
|
@ -286,55 +286,6 @@ jobs:
|
||||||
shopt -s globstar
|
shopt -s globstar
|
||||||
pre-commit run --hook-stage manual black --files {homeassistant,tests}/components/${{ needs.info.outputs.integrations_glob }}/{*,**/*} --show-diff-on-failure
|
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:
|
lint-ruff:
|
||||||
name: Check ruff
|
name: Check ruff
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -36,20 +36,6 @@ repos:
|
||||||
- --quiet-level=2
|
- --quiet-level=2
|
||||||
exclude_types: [csv, json]
|
exclude_types: [csv, json]
|
||||||
exclude: ^tests/fixtures/|homeassistant/generated/
|
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
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.7.4
|
rev: 1.7.4
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
@ -42,20 +42,6 @@
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"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",
|
"label": "Ruff",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
|
|
@ -5,7 +5,6 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
# Uninstall pre-installed formatting and linting tools
|
# Uninstall pre-installed formatting and linting tools
|
||||||
# They would conflict with our pinned versions
|
# They would conflict with our pinned versions
|
||||||
RUN pipx uninstall black
|
RUN pipx uninstall black
|
||||||
RUN pipx uninstall flake8
|
|
||||||
RUN pipx uninstall pydocstyle
|
RUN pipx uninstall pydocstyle
|
||||||
RUN pipx uninstall pycodestyle
|
RUN pipx uninstall pycodestyle
|
||||||
RUN pipx uninstall mypy
|
RUN pipx uninstall mypy
|
||||||
|
|
|
@ -405,7 +405,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
base["params"] = data
|
base["params"] = data
|
||||||
return base
|
return base
|
||||||
|
|
||||||
async def async_handle_light_on_service(
|
async def async_handle_light_on_service( # noqa: C901
|
||||||
light: LightEntity, call: ServiceCall
|
light: LightEntity, call: ServiceCall
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle turning a light on.
|
"""Handle turning a light on.
|
||||||
|
|
|
@ -99,7 +99,7 @@ async def async_start( # noqa: C901
|
||||||
mqtt_integrations = {}
|
mqtt_integrations = {}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_discovery_message_received(msg: ReceiveMessage) -> None:
|
def async_discovery_message_received(msg: ReceiveMessage) -> None: # noqa: C901
|
||||||
"""Process the received message."""
|
"""Process the received message."""
|
||||||
mqtt_data.last_discovery = time.time()
|
mqtt_data.last_discovery = time.time()
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
|
|
|
@ -292,15 +292,6 @@ keep-runtime-typing = true
|
||||||
|
|
||||||
[tool.ruff.per-file-ignores]
|
[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
|
# Allow for main entry & scripts to write to stdout
|
||||||
"homeassistant/__main__.py" = ["T201"]
|
"homeassistant/__main__.py" = ["T201"]
|
||||||
"homeassistant/scripts/*" = ["T201"]
|
"homeassistant/scripts/*" = ["T201"]
|
||||||
|
|
|
@ -4,15 +4,7 @@ autoflake==2.0.0
|
||||||
bandit==1.7.4
|
bandit==1.7.4
|
||||||
black==23.1.0
|
black==23.1.0
|
||||||
codespell==2.2.2
|
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
|
isort==5.12.0
|
||||||
mccabe==0.7.0
|
|
||||||
pycodestyle==2.10.0
|
|
||||||
pydocstyle==6.2.3
|
|
||||||
pyflakes==3.0.1
|
|
||||||
pyupgrade==3.3.1
|
pyupgrade==3.3.1
|
||||||
ruff==0.0.256
|
ruff==0.0.256
|
||||||
yamllint==1.28.0
|
yamllint==1.28.0
|
||||||
|
|
|
@ -12,10 +12,6 @@ if [ -z "$files" ] ; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
printf "%s\n" $files
|
printf "%s\n" $files
|
||||||
echo "================"
|
|
||||||
echo "LINT with flake8"
|
|
||||||
echo "================"
|
|
||||||
pre-commit run flake8 --files $files
|
|
||||||
echo "=============="
|
echo "=============="
|
||||||
echo "LINT with ruff"
|
echo "LINT with ruff"
|
||||||
echo "=============="
|
echo "=============="
|
||||||
|
|
|
@ -116,9 +116,9 @@ async def pylint(files):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
async def _ruff_or_flake8(tool, files):
|
async def ruff(files):
|
||||||
"""Exec ruff or flake8."""
|
"""Exec ruff."""
|
||||||
_, log = await async_exec("pre-commit", "run", tool, "--files", *files)
|
_, log = await async_exec("pre-commit", "run", "ruff", "--files", *files)
|
||||||
res = []
|
res = []
|
||||||
for line in log.splitlines():
|
for line in log.splitlines():
|
||||||
line = line.split(":")
|
line = line.split(":")
|
||||||
|
@ -129,23 +129,12 @@ async def _ruff_or_flake8(tool, files):
|
||||||
return res
|
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):
|
async def lint(files):
|
||||||
"""Perform lint."""
|
"""Perform lint."""
|
||||||
files = [file for file in files if os.path.isfile(file)]
|
files = [file for file in files if os.path.isfile(file)]
|
||||||
res = sorted(
|
res = sorted(
|
||||||
itertools.chain(
|
itertools.chain(
|
||||||
*await asyncio.gather(
|
*await asyncio.gather(
|
||||||
flake8(files),
|
|
||||||
pylint(files),
|
pylint(files),
|
||||||
ruff(files),
|
ruff(files),
|
||||||
)
|
)
|
||||||
|
|
29
setup.cfg
29
setup.cfg
|
@ -3,32 +3,3 @@
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
url = https://www.home-assistant.io/
|
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
|
|
||||||
|
|
Loading…
Reference in New Issue