Skip to content

Commit

Permalink
Tox check with CI on Windows, macOS and Ubuntu (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youw authored Nov 12, 2023
1 parent 814fa59 commit 9cfe0e8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Python package

on:
- push
- pull_request

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.12"]
system-hidapi: ["", "--with-system-hidapi"]
libusb-backend: ["", "--with-libusb"]
exclude:
# TODO: it is non-trivial to install pkg-config and HIDAPI,
# and configure it run work in runtime
- platform: windows-latest
system-hidapi: "--with-system-hidapi"
# libusb backend is not present on Windows/macOS
- platform: macos-latest
libusb-backend: "--with-libusb"
- platform: windows-latest
libusb-backend: "--with-libusb"

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install Ubuntu dependencies
if: matrix.platform == 'ubuntu-latest'
run: sudo apt install libudev-dev libusb-1.0-0-dev

- name: Install Ubuntu HIDAPI
if: ${{ (matrix.platform == 'ubuntu-latest') && (matrix.system-hidapi == '--with-system-hidapi') }}
# the default apt version of libhidapi-dev is too old, need to build the one we know would work
run: |
sudo apt install cmake
mkdir hidapi_build && cd hidapi_build
cmake -B . -S ../hidapi -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
- name: Install macOS HIDAPI
if: ${{ (matrix.platform == 'macos-latest') && (matrix.system-hidapi == '--with-system-hidapi') }}
run: brew install hidapi

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools tox tox-gh-actions
pip install -r requirements.txt --upgrade
- name: Test with tox
env:
HIDAPI_SYSTEM_HIDAPI: ${{ matrix.system-hidapi == '--with-system-hidapi' && '1' || '0' }}
HIDAPI_WITH_LIBUSB: ${{ matrix.libusb-backend == '--with-libusb' && '1' || '0' }}
run: |
pip install .
tox
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
embedded_hidapi_include = os.path.join(embedded_hidapi_topdir, "hidapi")


def to_bool(bool_str):
if str(bool_str).lower() in ["true", "t", "1", "on", "yes", "y"]:
return True
return False


def get_extension_compiler_type():
"""
Returns a compiler to be used by setuptools to build Extensions
Expand Down Expand Up @@ -128,7 +134,7 @@ def hid_from_embedded_hidapi():
sys.argv.remove("--with-libusb")
HIDAPI_WITH_LIBUSB = True
else:
HIDAPI_WITH_LIBUSB = bool(os.getenv("HIDAPI_WITH_LIBUSB"))
HIDAPI_WITH_LIBUSB = to_bool(os.getenv("HIDAPI_WITH_LIBUSB"))

if HIDAPI_WITH_LIBUSB:
hidraw_module = "hidraw"
Expand Down Expand Up @@ -177,7 +183,7 @@ def hid_from_system_hidapi():
sys.argv.remove("--with-libusb")
HIDAPI_WITH_LIBUSB = True
else:
HIDAPI_WITH_LIBUSB = bool(os.getenv("HIDAPI_WITH_LIBUSB"))
HIDAPI_WITH_LIBUSB = to_bool(os.getenv("HIDAPI_WITH_LIBUSB"))

if HIDAPI_WITH_LIBUSB:
hidraw_module = "hidraw"
Expand Down Expand Up @@ -220,7 +226,7 @@ def find_version():
sys.argv.remove("--with-system-hidapi")
HIDAPI_SYSTEM_HIDAPI = True
else:
HIDAPI_SYSTEM_HIDAPI = bool(os.getenv("HIDAPI_SYSTEM_HIDAPI"))
HIDAPI_SYSTEM_HIDAPI = to_bool(os.getenv("HIDAPI_SYSTEM_HIDAPI"))

if HIDAPI_SYSTEM_HIDAPI:
modules = hid_from_system_hidapi()
Expand Down

0 comments on commit 9cfe0e8

Please sign in to comment.