[script] Make pre-commit and helpers work on Windows (#16260)

Co-authored-by: Jonathan Swoboda <swoboda1337@users.noreply.github.com>
This commit is contained in:
Jonathan Swoboda
2026-05-06 08:11:06 -04:00
committed by GitHub
parent 85f33978e7
commit 29db5fa4bb
3 changed files with 11 additions and 4 deletions

View File

@@ -55,7 +55,7 @@ repos:
hooks:
- id: pylint
name: pylint
entry: python3 script/run-in-env.py pylint
entry: python script/run-in-env.py pylint
language: system
types: [python]
files: ^esphome/.+\.py$
@@ -68,5 +68,5 @@ repos:
additional_dependencies: []
- id: ci-custom
name: ci-custom
entry: python3 script/run-in-env.py script/ci-custom.py
entry: python script/run-in-env.py script/ci-custom.py
language: system

View File

@@ -250,7 +250,7 @@ def lint_ext_check(fname):
]
)
def lint_executable_bit(fname: Path) -> str | None:
ex = EXECUTABLE_BIT[str(fname)]
ex = EXECUTABLE_BIT[fname.as_posix()]
if ex != 100644:
return (
f"File has invalid executable bit {ex}. If running from a windows machine please "

View File

@@ -44,7 +44,14 @@ def find_and_activate_virtualenv():
def run_command():
# Execute the remaining arguments in the new environment
if len(sys.argv) > 1:
result = subprocess.run(sys.argv[1:], check=False, close_fds=False)
args = sys.argv[1:]
# Windows CreateProcess doesn't follow shebangs, so prepend the
# current interpreter when the entry is a .py script. Using
# sys.executable also pins the nested call to the same Python that
# ran us — no ambiguous PATH lookup for "python".
if args[0].endswith(".py"):
args = [sys.executable, *args]
result = subprocess.run(args, check=False, close_fds=False)
sys.exit(result.returncode)
else:
print(