diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad82bd8e5d..da5fb94d5e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/script/ci-custom.py b/script/ci-custom.py index b257a3818b..8cd8fd7544 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -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 " diff --git a/script/run-in-env.py b/script/run-in-env.py index 9283ba9940..996db60554 100755 --- a/script/run-in-env.py +++ b/script/run-in-env.py @@ -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(