From 7416e855f1b358aa96e0937d692d861a7d093ed3 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:11:48 +0100 Subject: [PATCH] Fix mypy pre-commit hook on windows (#1081) --- devtools/run-in-env.sh | 18 ++++++++++++++++-- kasa/discover.py | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/devtools/run-in-env.sh b/devtools/run-in-env.sh index 3e67c70e..008d4d28 100755 --- a/devtools/run-in-env.sh +++ b/devtools/run-in-env.sh @@ -1,3 +1,17 @@ -#!/bin/bash -source $(poetry env info --path)/bin/activate +#!/usr/bin/env bash + +OS_KERNEL=$(uname -s) +OS_VER=$(uname -v) +if [[ ( $OS_KERNEL == "Linux" && $OS_VER == *"Microsoft"* ) ]]; then + echo "Pre-commit hook needs git-bash to run. It cannot run in the windows linux subsystem." + echo "Add git bin directory to the front of your path variable, e.g:" + echo "set PATH=C:\Program Files\Git\bin;%PATH%" + exit 1 +fi +if [[ "$(expr substr $OS_KERNEL 1 10)" == "MINGW64_NT" ]]; then + POETRY_PATH=$(poetry.exe env info --path) + source "$POETRY_PATH"\\Scripts\\activate +else + source $(poetry env info --path)/bin/activate +fi exec "$@" diff --git a/kasa/discover.py b/kasa/discover.py index c69933a9..7c147597 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -209,7 +209,8 @@ class _DiscoverProtocol(asyncio.DatagramProtocol): except OSError as ex: # WSL does not support SO_REUSEADDR, see #246 _LOGGER.debug("Unable to set SO_REUSEADDR: %s", ex) - if self.interface is not None: + # windows does not support SO_BINDTODEVICE + if self.interface is not None and hasattr(socket, "SO_BINDTODEVICE"): sock.setsockopt( socket.SOL_SOCKET, socket.SO_BINDTODEVICE, self.interface.encode() )