mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Introduce ruff (eventually replacing autoflake, pyupgrade, flake8) (#86224)
This commit is contained in:
@@ -6,6 +6,7 @@ This is NOT a full CI/linting replacement, only a quick check during development
|
||||
"""
|
||||
import asyncio
|
||||
from collections import namedtuple
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
@@ -115,9 +116,9 @@ async def pylint(files):
|
||||
return res
|
||||
|
||||
|
||||
async def flake8(files):
|
||||
"""Exec flake8."""
|
||||
_, log = await async_exec("pre-commit", "run", "flake8", "--files", *files)
|
||||
async def _ruff_or_flake8(tool, files):
|
||||
"""Exec ruff or flake8."""
|
||||
_, log = await async_exec("pre-commit", "run", tool, "--files", *files)
|
||||
res = []
|
||||
for line in log.splitlines():
|
||||
line = line.split(":")
|
||||
@@ -128,17 +129,33 @@ async def flake8(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)]
|
||||
fres, pres = await asyncio.gather(flake8(files), pylint(files))
|
||||
|
||||
res = fres + pres
|
||||
res.sort(key=lambda item: item.file)
|
||||
res = sorted(
|
||||
itertools.chain(
|
||||
*await asyncio.gather(
|
||||
flake8(files),
|
||||
pylint(files),
|
||||
ruff(files),
|
||||
)
|
||||
),
|
||||
key=lambda item: item.file,
|
||||
)
|
||||
if res:
|
||||
print("Pylint & Flake8 errors:")
|
||||
print("Lint errors:")
|
||||
else:
|
||||
printc(PASS, "Pylint and Flake8 passed")
|
||||
printc(PASS, "Lint passed")
|
||||
|
||||
lint_ok = True
|
||||
for err in res:
|
||||
|
||||
Reference in New Issue
Block a user