Enable Ruff PTH for the script directory (#124441)

* Enable Ruff PTH for the script directory

* Address review comments

* Fix translations script

* Update script/hassfest/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Sid 2024-09-06 11:33:01 +02:00 committed by GitHub
parent 7752789c3a
commit 1db68327f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 125 additions and 163 deletions

View file

@ -6,7 +6,6 @@ from __future__ import annotations
import difflib
import importlib
from operator import itemgetter
import os
from pathlib import Path
import pkgutil
import re
@ -82,8 +81,8 @@ URL_PIN = (
)
CONSTRAINT_PATH = os.path.join(
os.path.dirname(__file__), "../homeassistant/package_constraints.txt"
CONSTRAINT_PATH = (
Path(__file__).parent.parent / "homeassistant" / "package_constraints.txt"
)
CONSTRAINT_BASE = """
# Constrain pycryptodome to avoid vulnerability
@ -256,8 +255,7 @@ def explore_module(package: str, explore_children: bool) -> list[str]:
def core_requirements() -> list[str]:
"""Gather core requirements out of pyproject.toml."""
with open("pyproject.toml", "rb") as fp:
data = tomllib.load(fp)
data = tomllib.loads(Path("pyproject.toml").read_text())
dependencies: list[str] = data["project"]["dependencies"]
return dependencies
@ -528,7 +526,7 @@ def diff_file(filename: str, content: str) -> list[str]:
def main(validate: bool, ci: bool) -> int:
"""Run the script."""
if not os.path.isfile("requirements_all.txt"):
if not Path("requirements_all.txt").is_file():
print("Run this from HA root dir")
return 1
@ -590,7 +588,7 @@ def main(validate: bool, ci: bool) -> int:
def _get_hassfest_config() -> Config:
"""Get hassfest config."""
return Config(
root=Path(".").absolute(),
root=Path().absolute(),
specific_integrations=None,
action="validate",
requirements=True,