From 7f7b9c6747ecb62f4fe0e1ef7b62a9af886f38cc Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 07:49:04 +0200 Subject: [PATCH 1/8] CI: do no refer to unavailable and EOL python versions Signed-off-by: Sami Salonen --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 455cf00..9877185 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,7 +9,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: [3.5, 3.6, 3.7] + python-version: [3.7, 3.8, 3.9, 3.10, 3.11] steps: - uses: actions/checkout@v1 From 622abb79e272576066b9c6523d7bb04775926066 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 07:51:25 +0200 Subject: [PATCH 2/8] Run CI with PRs Signed-off-by: Sami Salonen --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 9877185..5c92576 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -1,6 +1,6 @@ name: Python package -on: [push] +on: [push, pull_request] jobs: build: From c7e309f17970cc2817e53e938ebdb2c3373ae4f9 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 07:52:27 +0200 Subject: [PATCH 3/8] Version as strings to avoid conversion to number Signed-off-by: Sami Salonen --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 5c92576..e89f801 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,7 +9,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: [3.7, 3.8, 3.9, 3.10, 3.11] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v1 From 96110e801386a635bb6716dccb8b38fef7fe7a48 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 08:03:13 +0200 Subject: [PATCH 4/8] Fixes for pytest to pass Signed-off-by: Sami Salonen --- hifiberrydsp/__init__.py | 1 + hifiberrydsp/conftest.py | 4 ++++ hifiberrydsp/hardware/spi.py | 21 +++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 hifiberrydsp/conftest.py diff --git a/hifiberrydsp/__init__.py b/hifiberrydsp/__init__.py index 2390dc1..2b5eb8e 100644 --- a/hifiberrydsp/__init__.py +++ b/hifiberrydsp/__init__.py @@ -1 +1,2 @@ __version__ = "0.20" +_called_from_test = False \ No newline at end of file diff --git a/hifiberrydsp/conftest.py b/hifiberrydsp/conftest.py new file mode 100644 index 0000000..9660b10 --- /dev/null +++ b/hifiberrydsp/conftest.py @@ -0,0 +1,4 @@ + +def pytest_configure(config): + import hifiberrydsp + hifiberrydsp._called_from_test = True \ No newline at end of file diff --git a/hifiberrydsp/hardware/spi.py b/hifiberrydsp/hardware/spi.py index e00d388..6280263 100644 --- a/hifiberrydsp/hardware/spi.py +++ b/hifiberrydsp/hardware/spi.py @@ -20,16 +20,21 @@ SOFTWARE. ''' import logging +import hifiberrydsp - -def init_spi(): +def init_spi(): import spidev - spi = spidev.SpiDev() - spi.open(0, 0) - spi.bits_per_word = 8 - spi.max_speed_hz = 1000000 - spi.mode = 0 - logging.debug("spi initialized %s", spi) + if not hifiberrydsp._called_from_test: + # only open the device when not running tests + spi = spidev.SpiDev() + spi.open(0, 0) + spi.bits_per_word = 8 + spi.max_speed_hz = 1000000 + spi.mode = 0 + logging.debug("spi initialized %s", spi) + else: + spi = None + logging.debug("spi not initialized since running tests") return spi From ed73f6b57e5bf981a35b4371e040e78642b3f355 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 08:03:45 +0200 Subject: [PATCH 5/8] Run pytest in CI Signed-off-by: Sami Salonen --- .github/workflows/pythonpackage.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e89f801..a346a40 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -29,7 +29,7 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# - name: Test with pytest -# run: | -# pip install pytest -# pytest + - name: Test with pytest + run: | + pip install pytest + pytest From 825cb66b5d7e220b6070ec4f5d80c0d24b029332 Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 08:08:05 +0200 Subject: [PATCH 6/8] spidev fix in tests Signed-off-by: Sami Salonen --- hifiberrydsp/hardware/spi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hifiberrydsp/hardware/spi.py b/hifiberrydsp/hardware/spi.py index 6280263..b27cae1 100644 --- a/hifiberrydsp/hardware/spi.py +++ b/hifiberrydsp/hardware/spi.py @@ -22,10 +22,10 @@ import logging import hifiberrydsp -def init_spi(): - import spidev +def init_spi(): if not hifiberrydsp._called_from_test: # only open the device when not running tests + import spidev spi = spidev.SpiDev() spi.open(0, 0) spi.bits_per_word = 8 From 0ce017cdf5cc1942bb8f1bdc2b84107bdbe284af Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 08:16:10 +0200 Subject: [PATCH 7/8] Caching pip dependencies Signed-off-by: Sami Salonen --- .github/workflows/pythonpackage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a346a40..a9475c4 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -17,6 +17,7 @@ jobs: uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} + cache: 'pip' # caching pip dependencies - name: Install dependencies run: | sudo apt install gcc libasound-dev From a5ebc1f2dfc5294d3fb9befef05e788b813d295c Mon Sep 17 00:00:00 2001 From: Sami Salonen Date: Thu, 2 Mar 2023 08:23:18 +0200 Subject: [PATCH 8/8] Fix REW Parsing of Notch filters. Fixes #42 Signed-off-by: Sami Salonen --- hifiberrydsp/parser/rew.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hifiberrydsp/parser/rew.py b/hifiberrydsp/parser/rew.py index b29a2b3..82e3303 100644 --- a/hifiberrydsp/parser/rew.py +++ b/hifiberrydsp/parser/rew.py @@ -46,7 +46,7 @@ def readfilters(filename, fs=48000): fc = float(parts[5]) gain = float(parts[8]) q = float(parts[11]) - logging.info("Filter EQ fc=%s, q=%s, gaion=%s, fs=%s", + logging.info("Filter EQ fc=%s, q=%s, gain=%s, fs=%s", fc, q, gain, fs) filters.append( Biquad.peaking_eq(fc, q, gain, fs)) @@ -109,7 +109,7 @@ def readfilters(filename, fs=48000): parts[4] == "Fc" and parts[6] == "Hz": fc = float(parts[5]) q = 0.707 - logging.info("Filter NO fc=%s", fc, db) + logging.info("Filter NO fc=%s q=%s", fc, q) filters.append( Biquad.notch(fc, q, fs))