1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 22:18:40 +00:00

Switch formatting from black to ruff-format (#102893)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Aarni Koskela
2023-11-27 15:38:59 +02:00
committed by GitHub
parent cf9b0e804f
commit 706add4a57
161 changed files with 530 additions and 607 deletions

View File

@@ -1,10 +1,10 @@
#!/bin/sh
# Format code with black.
# Format code with ruff-format.
cd "$(dirname "$0")/.."
black \
ruff \
format \
--check \
--fast \
--quiet \
homeassistant tests script *.py

View File

@@ -192,6 +192,7 @@ IGNORE_PRE_COMMIT_HOOK_ID = (
"no-commit-to-branch",
"prettier",
"python-typing-update",
"ruff-format", # it's just ruff
)
PACKAGE_REGEX = re.compile(r"^(?:--.+\s)?([-_\.\w\d]+).*==.+$")
@@ -394,7 +395,8 @@ def requirements_test_all_output(reqs: dict[str, list[str]]) -> str:
for requirement, modules in reqs.items()
if any(
# Always install requirements that are not part of integrations
not mdl.startswith("homeassistant.components.") or
not mdl.startswith("homeassistant.components.")
or
# Install tests for integrations that have tests
has_tests(mdl)
for mdl in modules

View File

@@ -2,11 +2,10 @@
from __future__ import annotations
from collections.abc import Collection, Iterable, Mapping
import shutil
import subprocess
from typing import Any
import black
from black.mode import Mode
DEFAULT_GENERATOR = "script.hassfest"
@@ -72,7 +71,14 @@ To update, run python3 -m {generator}
{content}
"""
return black.format_str(content.strip(), mode=Mode())
ruff = shutil.which("ruff")
if not ruff:
raise RuntimeError("ruff not found")
return subprocess.check_output(
[ruff, "format", "-"],
input=content.strip(),
encoding="utf-8",
)
def format_python_namespace(