mirror of
https://github.com/esphome/esphome.git
synced 2025-09-01 10:52:19 +01:00
add-black (#1593)
* Add black Update pre commit Update pre commit add empty line * Format with black
This commit is contained in:
committed by
GitHub
parent
2b60b0f1fa
commit
69879920eb
@@ -9,13 +9,14 @@ from esphome.config import get_component, get_platform
|
||||
from esphome.core import CORE
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--check', help="Check if the CODEOWNERS file is up to date.",
|
||||
action='store_true')
|
||||
parser.add_argument(
|
||||
"--check", help="Check if the CODEOWNERS file is up to date.", action="store_true"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# The root directory of the repo
|
||||
root = Path(__file__).parent.parent
|
||||
components_dir = root / 'esphome' / 'components'
|
||||
components_dir = root / "esphome" / "components"
|
||||
|
||||
BASE = """
|
||||
# This file is generated by script/build_codeowners.py
|
||||
@@ -43,16 +44,18 @@ codeowners = defaultdict(list)
|
||||
for path in components_dir.iterdir():
|
||||
if not path.is_dir():
|
||||
continue
|
||||
if not (path / '__init__.py').is_file():
|
||||
if not (path / "__init__.py").is_file():
|
||||
continue
|
||||
|
||||
name = path.name
|
||||
comp = get_component(name)
|
||||
if comp is None:
|
||||
print(f'Cannot find component {name}. Make sure current path is pip installed ESPHome')
|
||||
print(
|
||||
f"Cannot find component {name}. Make sure current path is pip installed ESPHome"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
codeowners[f'esphome/components/{name}/*'].extend(comp.codeowners)
|
||||
codeowners[f"esphome/components/{name}/*"].extend(comp.codeowners)
|
||||
|
||||
for platform_path in path.iterdir():
|
||||
platform_name = platform_path.stem
|
||||
@@ -62,15 +65,17 @@ for path in components_dir.iterdir():
|
||||
|
||||
if platform_path.is_dir():
|
||||
# Sub foldered platforms get their own line
|
||||
if not (platform_path / '__init__.py').is_file():
|
||||
if not (platform_path / "__init__.py").is_file():
|
||||
continue
|
||||
codeowners[f'esphome/components/{name}/{platform_name}/*'].extend(platform.codeowners)
|
||||
codeowners[f"esphome/components/{name}/{platform_name}/*"].extend(
|
||||
platform.codeowners
|
||||
)
|
||||
continue
|
||||
|
||||
# Non-subfoldered platforms add to codeowners at component level
|
||||
if not platform_path.is_file() or platform_path.name == '__init__.py':
|
||||
if not platform_path.is_file() or platform_path.name == "__init__.py":
|
||||
continue
|
||||
codeowners[f'esphome/components/{name}/*'].extend(platform.codeowners)
|
||||
codeowners[f"esphome/components/{name}/*"].extend(platform.codeowners)
|
||||
|
||||
|
||||
for path, owners in sorted(codeowners.items()):
|
||||
@@ -78,16 +83,18 @@ for path, owners in sorted(codeowners.items()):
|
||||
if not owners:
|
||||
continue
|
||||
for owner in owners:
|
||||
if not owner.startswith('@'):
|
||||
print(f"Codeowner {owner} for integration {path} must start with an '@' symbol!")
|
||||
if not owner.startswith("@"):
|
||||
print(
|
||||
f"Codeowner {owner} for integration {path} must start with an '@' symbol!"
|
||||
)
|
||||
sys.exit(1)
|
||||
parts.append(f"{path} {' '.join(owners)}")
|
||||
|
||||
|
||||
# End newline
|
||||
parts.append('')
|
||||
content = '\n'.join(parts)
|
||||
codeowners_file = root / 'CODEOWNERS'
|
||||
parts.append("")
|
||||
content = "\n".join(parts)
|
||||
codeowners_file = root / "CODEOWNERS"
|
||||
|
||||
if args.check:
|
||||
if codeowners_file.read_text() != content:
|
||||
|
Reference in New Issue
Block a user