Skip to content

Commit

Permalink
make libusb backend default once again for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Nov 19, 2024
1 parent 9dbdd01 commit ca60760
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ def hidapi_src(platform):
return os.path.join(embedded_hidapi_topdir, platform, "hid.c")


def check_deprecated_without_libusb():
# already the default behavior, but accept the old option
if "--without-libusb" in sys.argv:
sys.argv.remove("--without-libusb")
print(
"Without libusb is already a default, '--without-libusb' option is redundant and deprecated"
)


def hid_from_embedded_hidapi():
# TODO: what about MinGW/msys?
if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):
Expand Down Expand Up @@ -130,12 +121,21 @@ def hid_from_embedded_hidapi():

elif sys.platform.startswith("linux"):
modules = []
if "--with-hidraw" in sys.argv:
sys.argv.remove("--with-hidraw")
HIDAPI_WITH_HIDRAW = True
else:
HIDAPI_WITH_HIDRAW = to_bool(os.getenv("HIDAPI_WITH_HIDRAW"))
if "--with-libusb" in sys.argv:
sys.argv.remove("--with-libusb")
HIDAPI_WITH_LIBUSB = True
else:
HIDAPI_WITH_LIBUSB = to_bool(os.getenv("HIDAPI_WITH_LIBUSB"))

# make libusb backend default if none is specified
if not HIDAPI_WITH_HIDRAW and not HIDAPI_WITH_LIBUSB:
HIDAPI_WITH_LIBUSB = True

if HIDAPI_WITH_LIBUSB:
hidraw_module = "hidraw"
modules.append(
Expand All @@ -148,9 +148,10 @@ def hid_from_embedded_hidapi():
libusb_pkgconfig,
)
)
else:
elif HIDAPI_WITH_HIDRAW:
hidraw_module = "hid"
check_deprecated_without_libusb()
else:
raise ValueError("Unknown HIDAPI backend")

modules.append(
Extension(
Expand Down Expand Up @@ -179,22 +180,32 @@ def hid_from_embedded_hidapi():
def hid_from_system_hidapi():
if sys.platform.startswith("linux"):
modules = []
if "--with-hidraw" in sys.argv:
sys.argv.remove("--with-hidraw")
HIDAPI_WITH_HIDRAW = True
else:
HIDAPI_WITH_HIDRAW = to_bool(os.getenv("HIDAPI_WITH_HIDRAW"))
if "--with-libusb" in sys.argv:
sys.argv.remove("--with-libusb")
HIDAPI_WITH_LIBUSB = True
else:
HIDAPI_WITH_LIBUSB = to_bool(os.getenv("HIDAPI_WITH_LIBUSB"))

# make libusb backend default if none is specified
if not HIDAPI_WITH_HIDRAW and not HIDAPI_WITH_LIBUSB:
HIDAPI_WITH_LIBUSB = True

if HIDAPI_WITH_LIBUSB:
hidraw_module = "hidraw"
modules.append(
pkgconfig_configure_extension(
Extension("hid", sources=["hid.pyx"]), hidapi_libusb_pkgconfig
)
)
else:
elif HIDAPI_WITH_HIDRAW:
hidraw_module = "hid"
check_deprecated_without_libusb()
else:
raise ValueError("Unknown HIDAPI backend")

modules.append(
pkgconfig_configure_extension(
Expand Down

0 comments on commit ca60760

Please sign in to comment.