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

@ -9,6 +9,7 @@ from collections import namedtuple
from contextlib import suppress
import itertools
import os
from pathlib import Path
import re
import shlex
import sys
@ -63,7 +64,7 @@ async def async_exec(*args, display=False):
"""Execute, return code & log."""
argsp = []
for arg in args:
if os.path.isfile(arg):
if Path(arg).is_file():
argsp.append(f"\\\n {shlex.quote(arg)}")
else:
argsp.append(shlex.quote(arg))
@ -132,7 +133,7 @@ async def ruff(files):
async def lint(files):
"""Perform lint."""
files = [file for file in files if os.path.isfile(file)]
files = [file for file in files if Path(file).is_file()]
res = sorted(
itertools.chain(
*await asyncio.gather(
@ -164,7 +165,7 @@ async def lint(files):
async def main():
"""Run the main loop."""
# Ensure we are in the homeassistant root
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
os.chdir(Path(__file__).parent.parent)
files = await git()
if not files:
@ -194,7 +195,7 @@ async def main():
gen_req = True # requirements script for components
# Find test files...
if fname.startswith("tests/"):
if "/test_" in fname and os.path.isfile(fname):
if "/test_" in fname and Path(fname).is_file():
# All test helpers should be excluded
test_files.add(fname)
else:
@ -207,7 +208,7 @@ async def main():
else:
parts[-1] = f"test_{parts[-1]}"
fname = "/".join(parts)
if os.path.isfile(fname):
if Path(fname).is_file():
test_files.add(fname)
if gen_req: