From 54a7de558ceb5cbc2c309fb56acc74dc10f3fe00 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Mon, 26 Aug 2024 09:27:08 +0200 Subject: [PATCH] Fix CI/CD and make the script runnable outside of the CI/CD --- .github/workflows/node-hub-ci-cd.yml | 19 +----- .github/workflows/node_hub_test.sh | 20 ++++++ .../tests/test_placeholder.py} | 0 node-hub/dora-keyboard/dora_keyboard/main.py | 2 +- .../tests/test_placeholder.py} | 0 .../dora-microphone/dora_microphone/main.py | 1 + .../dora_microphone_save/__init__.py | 11 ---- .../dora_microphone_save/main.py | 61 ------------------- .../tests/test_placeholder.py} | 0 .../tests/test_placeholder.py} | 0 .../pyarrow-sender/tests/test_placeholder.py | 2 + .../terminal-input/terminal_input/main.py | 3 +- .../terminal-input/tests/test_placeholder.py | 2 + 13 files changed, 29 insertions(+), 92 deletions(-) create mode 100755 .github/workflows/node_hub_test.sh rename node-hub/{dora-microphone/tests/test_arrow_sender.py => dora-echo/tests/test_placeholder.py} (100%) rename node-hub/{pyarrow-assert/tests/test_opencv_plot.py => dora-keyboard/tests/test_placeholder.py} (100%) delete mode 100644 node-hub/dora-microphone/dora_microphone_save/__init__.py delete mode 100644 node-hub/dora-microphone/dora_microphone_save/main.py rename node-hub/{pyarrow-sender/tests/test_arrow_sender.py => dora-microphone/tests/test_placeholder.py} (100%) rename node-hub/{terminal-input/tests/test.py => pyarrow-assert/tests/test_placeholder.py} (100%) create mode 100644 node-hub/pyarrow-sender/tests/test_placeholder.py create mode 100644 node-hub/terminal-input/tests/test_placeholder.py diff --git a/.github/workflows/node-hub-ci-cd.yml b/.github/workflows/node-hub-ci-cd.yml index fe984fa6..cf44cd02 100644 --- a/.github/workflows/node-hub-ci-cd.yml +++ b/.github/workflows/node-hub-ci-cd.yml @@ -37,23 +37,8 @@ jobs: - name: Run Linting and Tests run: | - for dir in node-hub/*/ ; do - if [ -d "$dir" ]; then - if [ -f "$dir/pyproject.toml" ]; then - echo "Running linting and tests for Python project in $dir..." - (cd "$dir" && pip install .) - (cd "$dir" && poetry run black --check .) - (cd "$dir" && poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py) - (cd "$dir" && poetry run pytest) - fi - - if [ -f "$dir/Cargo.toml" ]; then - echo "Running build and tests for Rust project in $dir..." - (cd "$dir" && cargo build) - (cd "$dir" && cargo test) - fi - fi - done + chmod +x .github/workflows/node_hub_test.sh + .github/workflows/node_hub_test.sh publish: needs: [ci] diff --git a/.github/workflows/node_hub_test.sh b/.github/workflows/node_hub_test.sh new file mode 100755 index 00000000..524ca1ca --- /dev/null +++ b/.github/workflows/node_hub_test.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo + +for dir in node-hub/*/ ; do +if [ -d "$dir" ]; then + if [ -f "$dir/pyproject.toml" ]; then + echo "Running linting and tests for Python project in $dir..." + (cd "$dir" && pip install .) + (cd "$dir" && poetry run black --check .) + (cd "$dir" && poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py) + (cd "$dir" && poetry run pytest) + fi + + if [ -f "$dir/Cargo.toml" ]; then + echo "Running build and tests for Rust project in $dir..." + (cd "$dir" && cargo build) + (cd "$dir" && cargo test) + fi +fi +done diff --git a/node-hub/dora-microphone/tests/test_arrow_sender.py b/node-hub/dora-echo/tests/test_placeholder.py similarity index 100% rename from node-hub/dora-microphone/tests/test_arrow_sender.py rename to node-hub/dora-echo/tests/test_placeholder.py diff --git a/node-hub/dora-keyboard/dora_keyboard/main.py b/node-hub/dora-keyboard/dora_keyboard/main.py index 6ba2b49b..599e580e 100644 --- a/node-hub/dora-keyboard/dora_keyboard/main.py +++ b/node-hub/dora-keyboard/dora_keyboard/main.py @@ -1,5 +1,5 @@ from pynput import keyboard -from pynput.keyboard import Key, Events +from pynput.keyboard import Events import pyarrow as pa from dora import Node diff --git a/node-hub/pyarrow-assert/tests/test_opencv_plot.py b/node-hub/dora-keyboard/tests/test_placeholder.py similarity index 100% rename from node-hub/pyarrow-assert/tests/test_opencv_plot.py rename to node-hub/dora-keyboard/tests/test_placeholder.py diff --git a/node-hub/dora-microphone/dora_microphone/main.py b/node-hub/dora-microphone/dora_microphone/main.py index dc05554d..5cd2a174 100644 --- a/node-hub/dora-microphone/dora_microphone/main.py +++ b/node-hub/dora-microphone/dora_microphone/main.py @@ -32,6 +32,7 @@ def main(): silence_start_time = tm.time() node = Node() + # pylint: disable=unused-argument def callback(indata, frames, time, status): nonlocal buffer, state, silence_start_time, node diff --git a/node-hub/dora-microphone/dora_microphone_save/__init__.py b/node-hub/dora-microphone/dora_microphone_save/__init__.py deleted file mode 100644 index ac3cbef9..00000000 --- a/node-hub/dora-microphone/dora_microphone_save/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -# Define the path to the README file relative to the package directory -readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md") - -# Read the content of the README file -try: - with open(readme_path, "r", encoding="utf-8") as f: - __doc__ = f.read() -except FileNotFoundError: - __doc__ = "README file not found." diff --git a/node-hub/dora-microphone/dora_microphone_save/main.py b/node-hub/dora-microphone/dora_microphone_save/main.py deleted file mode 100644 index ad3e9741..00000000 --- a/node-hub/dora-microphone/dora_microphone_save/main.py +++ /dev/null @@ -1,61 +0,0 @@ -import sounddevice as sd -import numpy as np -import pyarrow as pa -import time as tm -from enum import Enum - -from dora import Node - - -class RecordingState(Enum): - """Enum for recording states.""" - - PENDING = 0 - RUNNING = 1 - SILENCE = 2 - - -def detect_speech(audio_data, threshold): - """Check if the amplitude of the audio signal exceeds the threshold.""" - return np.any(np.abs(audio_data) > threshold) - - -def main(): - # Parameters - threshold = 500 # Threshold for detecting speech (adjust this as needed) - SAMPLE_RATE = 16000 - silence_duration = 4 # Duration of silence before stopping the recording - - # Initialize buffer and recording flag - buffer = [] - state = RecordingState.PENDING - silence_start_time = tm.time() - node = Node() - - def callback(indata, frames, time, status): - nonlocal buffer, state, silence_start_time, node - - is_speaking = detect_speech(indata[:, 0], threshold) - if is_speaking: - if state == RecordingState.PENDING: - buffer = [] - state = RecordingState.RUNNING - buffer.extend(indata[:, 0]) - elif not is_speaking and state == RecordingState.RUNNING: - silence_start_time = tm.time() # Reset silence timer - buffer.extend(indata[:, 0]) - state = RecordingState.SILENCE - elif not is_speaking and state == RecordingState.SILENCE: - if tm.time() - silence_start_time > silence_duration: - audio_data = np.array(buffer).ravel().astype(np.float32) / 32768.0 - node.send_output("audio", pa.array(audio_data)) - state = RecordingState.PENDING - else: - buffer.extend(indata[:, 0]) - - # Start recording - with sd.InputStream( - callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE - ): - while True: - sd.sleep(int(100 * 1000)) diff --git a/node-hub/pyarrow-sender/tests/test_arrow_sender.py b/node-hub/dora-microphone/tests/test_placeholder.py similarity index 100% rename from node-hub/pyarrow-sender/tests/test_arrow_sender.py rename to node-hub/dora-microphone/tests/test_placeholder.py diff --git a/node-hub/terminal-input/tests/test.py b/node-hub/pyarrow-assert/tests/test_placeholder.py similarity index 100% rename from node-hub/terminal-input/tests/test.py rename to node-hub/pyarrow-assert/tests/test_placeholder.py diff --git a/node-hub/pyarrow-sender/tests/test_placeholder.py b/node-hub/pyarrow-sender/tests/test_placeholder.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/node-hub/pyarrow-sender/tests/test_placeholder.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass diff --git a/node-hub/terminal-input/terminal_input/main.py b/node-hub/terminal-input/terminal_input/main.py index 2ca726d3..da85b52d 100644 --- a/node-hub/terminal-input/terminal_input/main.py +++ b/node-hub/terminal-input/terminal_input/main.py @@ -44,9 +44,8 @@ def main(): ) try: data = ast.literal_eval(data) - except Exception: + except ValueError: print("Passing input as string") - pass if isinstance(data, list): data = pa.array(data) # initialize pyarrow array elif isinstance(data, str): diff --git a/node-hub/terminal-input/tests/test_placeholder.py b/node-hub/terminal-input/tests/test_placeholder.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/node-hub/terminal-input/tests/test_placeholder.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass