From d20e8b07cebeb8338889c666bc8ccf7c8fc94945 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:04:35 -0500 Subject: [PATCH 01/11] Add type hints --- adafruit_rtttl.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index c128f18..dc313cf 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -31,6 +31,12 @@ except ImportError: pass +try: + from typing import Optional, Union, Tuple + from audioio import AudioOut +except ImportError: + pass + PIANO = { "4c": 261.626, "4c#": 277.183, @@ -73,7 +79,7 @@ } -def _parse_note(note, duration=2, octave="6"): +def _parse_note(note: str, duration: int = 2, octave: int = 6) -> Tuple[str, float]: note = note.strip() piano_note = None note_duration = duration @@ -96,7 +102,7 @@ def _parse_note(note, duration=2, octave="6"): return piano_note, note_duration -def _get_wave(tune, octave): +def _get_wave(tune: str, octave: int) -> Tuple[sine.sine_wave, float]: """Returns the proper waveform to play the song along with the minimum frequency in the song. """ @@ -110,7 +116,7 @@ def _get_wave(tune, octave): # pylint: disable-msg=too-many-arguments -def _play_to_pin(tune, base_tone, min_freq, duration, octave, tempo): +def _play_to_pin(tune: str, base_tone: Union[pwmio.PWMOut, AudioOut], min_freq: float, duration: int, octave: int, tempo: int) -> None: """Using the prepared input send the notes to the pin""" pwm = isinstance(base_tone, pwmio.PWMOut) for note in tune.split(","): @@ -139,7 +145,7 @@ def _play_to_pin(tune, base_tone, min_freq, duration, octave, tempo): # pylint: disable-msg=too-many-arguments -def play(pin, rtttl, octave=None, duration=None, tempo=None): +def play(pin, rtttl: str, octave: int = Optional[None], duration: Optional[int] = None, tempo: Optional[int] = None) -> None: """Play notes to a digialio pin using ring tone text transfer language (rtttl). :param ~digitalio.DigitalInOut pin: the speaker pin :param rtttl: string containing rtttl From 02b6e9833c1782bc51180c3ea0c93be67da3eb3e Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:04:52 -0500 Subject: [PATCH 02/11] Add type for rtttl param in play() docstring --- adafruit_rtttl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index dc313cf..19be245 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -148,7 +148,7 @@ def _play_to_pin(tune: str, base_tone: Union[pwmio.PWMOut, AudioOut], min_freq: def play(pin, rtttl: str, octave: int = Optional[None], duration: Optional[int] = None, tempo: Optional[int] = None) -> None: """Play notes to a digialio pin using ring tone text transfer language (rtttl). :param ~digitalio.DigitalInOut pin: the speaker pin - :param rtttl: string containing rtttl + :param str rtttl: string containing rtttl :param int octave: represents octave number (default 6 starts at middle c) :param int duration: length of notes (default 4 quarter note) :param int tempo: how fast (default 63 beats per minute) From a929466f7d4e5c0bf500b535656291d6a8934201 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:05:43 -0500 Subject: [PATCH 03/11] Cast octave to string type I'm fairly certain this was the intention of this line based on reading the code --- adafruit_rtttl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index 19be245..58a6847 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -95,7 +95,7 @@ def _parse_note(note: str, duration: int = 2, octave: int = 6) -> Tuple[str, flo note_duration *= 1.5 if "#" in note: piano_note += "#" - note_octave = octave + note_octave = str(octave) if note[-1].isdigit(): note_octave = note[-1] piano_note = note_octave + piano_note From 0c4c63343e874d92f5f825d94a21325bfd5ede08 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:09:53 -0500 Subject: [PATCH 04/11] Formatted per pre-commit --- adafruit_rtttl.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index 58a6847..a641b3b 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -116,7 +116,14 @@ def _get_wave(tune: str, octave: int) -> Tuple[sine.sine_wave, float]: # pylint: disable-msg=too-many-arguments -def _play_to_pin(tune: str, base_tone: Union[pwmio.PWMOut, AudioOut], min_freq: float, duration: int, octave: int, tempo: int) -> None: +def _play_to_pin( + tune: str, + base_tone: Union[pwmio.PWMOut, AudioOut], + min_freq: float, + duration: int, + octave: int, + tempo: int, +) -> None: """Using the prepared input send the notes to the pin""" pwm = isinstance(base_tone, pwmio.PWMOut) for note in tune.split(","): @@ -145,7 +152,13 @@ def _play_to_pin(tune: str, base_tone: Union[pwmio.PWMOut, AudioOut], min_freq: # pylint: disable-msg=too-many-arguments -def play(pin, rtttl: str, octave: int = Optional[None], duration: Optional[int] = None, tempo: Optional[int] = None) -> None: +def play( + pin, + rtttl: str, + octave: int = Optional[None], + duration: Optional[int] = None, + tempo: Optional[int] = None, +) -> None: """Play notes to a digialio pin using ring tone text transfer language (rtttl). :param ~digitalio.DigitalInOut pin: the speaker pin :param str rtttl: string containing rtttl From d66e75b99365039eb02793de38d7393bf673794c Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:14:26 -0500 Subject: [PATCH 05/11] Add "adafruit_waveform" to mock imports for Sphinx --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 61eb6b6..7610bab 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ "sphinx.ext.viewcode", ] -autodoc_mock_imports = ["pulseio"] +autodoc_mock_imports = ["pulseio", "adafruit_waveform"] intersphinx_mapping = { "python": ("https://docs.python.org/3.4", None), From b6af5a6a1b7930fa19a5055b6adff2d3af3a8530 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:19:36 -0500 Subject: [PATCH 06/11] Revert "Add "adafruit_waveform" to mock imports for Sphinx" This reverts commit d66e75b99365039eb02793de38d7393bf673794c. --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 7610bab..61eb6b6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ "sphinx.ext.viewcode", ] -autodoc_mock_imports = ["pulseio", "adafruit_waveform"] +autodoc_mock_imports = ["pulseio"] intersphinx_mapping = { "python": ("https://docs.python.org/3.4", None), From 4f280798ff3ea71f49a03012278ff699465bce1f Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:19:53 -0500 Subject: [PATCH 07/11] Correct sine_wave typing to List[int] --- adafruit_rtttl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index a641b3b..350e611 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -32,7 +32,7 @@ pass try: - from typing import Optional, Union, Tuple + from typing import Optional, Union, Tuple, List from audioio import AudioOut except ImportError: pass @@ -102,7 +102,7 @@ def _parse_note(note: str, duration: int = 2, octave: int = 6) -> Tuple[str, flo return piano_note, note_duration -def _get_wave(tune: str, octave: int) -> Tuple[sine.sine_wave, float]: +def _get_wave(tune: str, octave: int) -> Tuple[List[int], float]: """Returns the proper waveform to play the song along with the minimum frequency in the song. """ From 88ff35b446419af589f5122d98bccee0a23cb7ae Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:25:38 -0500 Subject: [PATCH 08/11] Add Blinka to docs/requirements.txt --- docs/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..be0837c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,4 +2,5 @@ # # SPDX-License-Identifier: Unlicense +Adafruit-Blinka sphinx>=4.0.0 From a6fa77629edcd25c8a8a267c15694dc5e6d49f24 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:47:38 -0500 Subject: [PATCH 09/11] Revert "Add Blinka to docs/requirements.txt" This reverts commit 88ff35b446419af589f5122d98bccee0a23cb7ae. --- docs/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index be0837c..88e6733 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,4 @@ # # SPDX-License-Identifier: Unlicense -Adafruit-Blinka sphinx>=4.0.0 From f87a6a7425de5393a8c0e6f2cdd4c2f2814e4fc0 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:48:40 -0500 Subject: [PATCH 10/11] Add pwmio to mock imports --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 61eb6b6..9a7655b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ "sphinx.ext.viewcode", ] -autodoc_mock_imports = ["pulseio"] +autodoc_mock_imports = ["pulseio", "pwmio"] intersphinx_mapping = { "python": ("https://docs.python.org/3.4", None), From 0174764960ad189bccd6ea742862cea2635883c8 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 17 Nov 2021 11:54:05 -0500 Subject: [PATCH 11/11] Added audioio to mock imports --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9a7655b..7b280e5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ "sphinx.ext.viewcode", ] -autodoc_mock_imports = ["pulseio", "pwmio"] +autodoc_mock_imports = ["pulseio", "pwmio", "audioio"] intersphinx_mapping = { "python": ("https://docs.python.org/3.4", None),