From 0f5df77cbb956abbc6b0497bd9701f8570f04d01 Mon Sep 17 00:00:00 2001 From: dherrada Date: Sun, 15 Mar 2020 16:19:15 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_rtttl.py | 89 +++++++++++++++------------- docs/conf.py | 110 ++++++++++++++++++++--------------- examples/rtttl_simpletest.py | 16 +++-- setup.py | 50 +++++++--------- 5 files changed, 144 insertions(+), 123 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_rtttl.py b/adafruit_rtttl.py index bc0214e..46499b8 100644 --- a/adafruit_rtttl.py +++ b/adafruit_rtttl.py @@ -39,6 +39,7 @@ try: import audioio from adafruit_waveform import sine + AUDIOIO_AVAILABLE = True try: import audiocore @@ -47,44 +48,47 @@ except ImportError: pass -PIANO = {"4c" : 261.626, - "4c#": 277.183, - "4d" : 293.665, - "4d#": 311.127, - "4e" : 329.628, - "4f" : 349.228, - "4f#": 369.994, - "4g" : 391.995, - "4g#": 415.305, - "4a" : 440, - "4a#": 466.164, - "4b" : 493.883, - "5c" : 523.251, - "5c#": 554.365, - "5d" : 587.330, - "5d#": 622.254, - "5e" : 659.255, - "5f" : 698.456, - "5f#": 739.989, - "5g" : 783.991, - "5g#": 830.609, - "5a" : 880, - "5a#": 932.328, - "5b" : 987.767, - "6c" : 1046.50, - "6c#": 1108.73, - "6d" : 1174.66, - "6d#": 1244.51, - "6e" : 1318.51, - "6f" : 1396.91, - "6f#": 1479.98, - "6g" : 1567.98, - "6g#": 1661.22, - "6a" : 1760, - "6a#": 1864.66, - "6b" : 1975.53, - "7c" : 2093, - "7c#": 2217.46} +PIANO = { + "4c": 261.626, + "4c#": 277.183, + "4d": 293.665, + "4d#": 311.127, + "4e": 329.628, + "4f": 349.228, + "4f#": 369.994, + "4g": 391.995, + "4g#": 415.305, + "4a": 440, + "4a#": 466.164, + "4b": 493.883, + "5c": 523.251, + "5c#": 554.365, + "5d": 587.330, + "5d#": 622.254, + "5e": 659.255, + "5f": 698.456, + "5f#": 739.989, + "5g": 783.991, + "5g#": 830.609, + "5a": 880, + "5a#": 932.328, + "5b": 987.767, + "6c": 1046.50, + "6c#": 1108.73, + "6d": 1174.66, + "6d#": 1244.51, + "6e": 1318.51, + "6f": 1396.91, + "6f#": 1479.98, + "6g": 1567.98, + "6g#": 1661.22, + "6a": 1760, + "6a#": 1864.66, + "6b": 1975.53, + "7c": 2093, + "7c#": 2217.46, +} + def _parse_note(note, duration=2, octave="6"): note = note.strip() @@ -108,6 +112,7 @@ def _parse_note(note, duration=2, octave="6"): piano_note = note_octave + piano_note return piano_note, note_duration + def _get_wave(tune, octave): """Returns the proper waveform to play the song along with the minimum frequency in the song. @@ -121,7 +126,7 @@ def _get_wave(tune, octave): return sine.sine_wave(16000, min_freq), min_freq -#pylint: disable-msg=too-many-arguments +# pylint: disable-msg=too-many-arguments def _play_to_pin(tune, base_tone, min_freq, duration, octave, tempo): """Using the prepared input send the notes to the pin """ @@ -140,8 +145,7 @@ def _play_to_pin(tune, base_tone, min_freq, duration, octave, tempo): sine_wave_sample = audiocore.RawSample(sine_wave) base_tone.play(sine_wave_sample, loop=True) else: - base_tone.frequency = int( - 16000 * (PIANO[piano_note] / min_freq)) + base_tone.frequency = int(16000 * (PIANO[piano_note] / min_freq)) base_tone.play(loop=True) time.sleep(4 / note_duration * 60 / tempo) @@ -151,7 +155,8 @@ def _play_to_pin(tune, base_tone, min_freq, duration, octave, tempo): base_tone.stop() time.sleep(0.02) -#pylint: disable-msg=too-many-arguments + +# pylint: disable-msg=too-many-arguments def play(pin, rtttl, octave=None, duration=None, tempo=None): """Play notes to a digialio pin using ring tone text transfer language (rtttl). :param ~digitalio.DigitalInOut pin: the speaker pin diff --git a/docs/conf.py b/docs/conf.py index f5707cc..57cba99 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,36 +11,39 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] autodoc_mock_imports = ["pulseio"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit RTTTL Library' -copyright = u'2017 Scott Shawcroft' -author = u'Scott Shawcroft' +project = u"Adafruit RTTTL Library" +copyright = u"2017 Scott Shawcroft" +author = u"Scott Shawcroft" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -51,7 +55,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -63,7 +67,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -77,59 +81,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitRTTTLLibrarydoc' +htmlhelp_basename = "AdafruitRTTTLLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitRTTTLLibrary.tex', u'Adafruit RTTTL Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitRTTTLLibrary.tex", + u"Adafruit RTTTL Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -137,8 +144,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitRTTTLlibrary', u'Adafruit RTTTL Library Documentation', - [author], 1) + ( + master_doc, + "adafruitRTTTLlibrary", + u"Adafruit RTTTL Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -147,7 +159,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitRTTTLLibrary', u'Adafruit RTTTL Library Documentation', - author, 'AdafruitRTTTLLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitRTTTLLibrary", + u"Adafruit RTTTL Library Documentation", + author, + "AdafruitRTTTLLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/rtttl_simpletest.py b/examples/rtttl_simpletest.py index 8a4553f..9665c07 100644 --- a/examples/rtttl_simpletest.py +++ b/examples/rtttl_simpletest.py @@ -29,8 +29,14 @@ enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) enable.switch_to_output(value=True) -adafruit_rtttl.play(board.SPEAKER, "itchy:d=8,o=6,b=160:c,a5,4p,c,a,4p,c,a5,c,a5," + \ - "c,a,4p,p,c,d,e,p,e,f,g,4p,d,c,4d,f,4a#,4a,2c7") -adafruit_rtttl.play(board.SPEAKER, "Phantom:d=4,o=5,b=140:c,f,c,d#.,8c#,2c#,a#4," + \ - "d#,8a#4,2c,c,f,c,d#.,8c#,2c#,a#4,d#.,8a#4,2c,p,c,f,g#,c.6,8a#,2a#,a#,d#.6,8a#," + \ - "2c6,p,c6,2f.6,8d#6,8c#6,8c6,8a#,8g#,8g,8f,2e,c#,c#.,8c,2c") +adafruit_rtttl.play( + board.SPEAKER, + "itchy:d=8,o=6,b=160:c,a5,4p,c,a,4p,c,a5,c,a5," + + "c,a,4p,p,c,d,e,p,e,f,g,4p,d,c,4d,f,4a#,4a,2c7", +) +adafruit_rtttl.play( + board.SPEAKER, + "Phantom:d=4,o=5,b=140:c,f,c,d#.,8c#,2c#,a#4," + + "d#,8a#4,2c,c,f,c,d#.,8c#,2c#,a#4,d#.,8a#4,2c,p,c,f,g#,c.6,8a#,2a#,a#,d#.6,8a#," + + "2c6,p,c6,2f.6,8d#6,8c#6,8c6,8a#,8g#,8g,8f,2e,c#,c#.,8c,2c", +) diff --git a/setup.py b/setup.py index 0ac5a3c..5e06219 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-rtttl', - + name="adafruit-circuitpython-rtttl", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for playing RTTTL melodies.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for playing RTTTL melodies.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_RTTTL', - + url="https://github.com/adafruit/Adafruit_CircuitPython_RTTTL", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-waveform'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-waveform"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit rtttl tones melodies hardware micropython circuitpython', - + keywords="adafruit rtttl tones melodies hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_rtttl'], + py_modules=["adafruit_rtttl"], )