From a53c2bcf0e4f9d1cfcdda157e850ae286dd8b77d Mon Sep 17 00:00:00 2001 From: Asher Lieber Date: Fri, 28 Jul 2017 15:23:22 -0400 Subject: [PATCH 001/131] map_range function comparable to arduino's map() (#14) Add map_range to mimic Arduino's map(). --- simpleio.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simpleio.py b/simpleio.py index a8068f9..a7b9273 100644 --- a/simpleio.py +++ b/simpleio.py @@ -159,3 +159,12 @@ def __getitem__(self, index): def __len__(self): return len(self.buf) // self.bpp + +def map_range(x, in_min, in_max, out_min, out_max): + """ + Maps a number from one range to another. + Note: This implementation handles values < in_min differently than arduino's map function does. + :return: Returns value mapped to new range + :rtype: float + """ + return max(min((x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min, out_max), out_min) From 6a804851d66e7dfbf362be81739b76107312f881 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Jul 2017 15:52:44 -0700 Subject: [PATCH 002/131] Remove NeoPixel in favor of a suped up neopixel module. --- simpleio.py | 92 ----------------------------------------------------- 1 file changed, 92 deletions(-) diff --git a/simpleio.py b/simpleio.py index a7b9273..926e765 100644 --- a/simpleio.py +++ b/simpleio.py @@ -68,98 +68,6 @@ def value(self): def value(self, value): raise AttributeError("Cannot set the value on a digital input.") -class NeoPixel: - """ - A sequence of neopixels. - - :param ~microcontroller.Pin pin: The pinto output neopixel data on. - :param int n: The number of neopixels in the chain - :param bool rgbw: True if the neopixels are RGBW - - Example for Circuit Playground Express: - - .. code-block:: python - - import simpleio - from board import * - - RED = 0x100000 - - with simpleio.NeoPixel(NEOPIXEL, 10) as pixels: - for i in len(pixels): - pixels[i] = RED - """ - def __init__(self, pin, n, rgbw=False): - self.pin = digitalio.DigitalInOut(pin) - self.pin.switch_to_output() - self.bpp = 3 - if rgbw: - self.bpp = 4 - self.buf = bytearray(n * self.bpp) - - def __enter__(self): - return self - - def __exit__(self, exception_type, exception_value, traceback): - # Blank out the neopixels. - for i in range(len(self.buf)): - self.buf[i] = 0 - neopixel_write(self.pin, self.buf) - self.pin.deinit() - - def __repr__(self): - return "[" + ", ".join(["0x%06x" % (x,) for x in self]) + "]" - - def _set_item(self, index, value): - offset = index * self.bpp - r = value >> 16 - g = (value >> 8) & 0xff - b = value & 0xff - w = 0 - # If all components are the same and we have a white pixel then use it - # instead of the individual components. - if self.bpp == 4 and r == g and g == b: - w = r - r = 0 - g = 0 - b = 0 - self.buf[offset + 1] = r - self.buf[offset] = g - self.buf[offset + 2] = b - if self.bpp == 4: - self.buf[offset + 3] = w - - def __setitem__(self, index, val): - if isinstance(index, slice): - start, stop, step = index.indices(len(self.buf) // self.bpp) - length = stop - start - if step != 0: - length = math.ceil(length / step) - if len(val) != length: - raise ValueError("Slice and input sequence size do not match.") - for val_i, in_i in enumerate(range(start, stop, step)): - self._set_item(in_i, val[val_i]) - else: - self._set_item(index, val) - - neopixel_write(self.pin, self.buf) - - def __getitem__(self, index): - if isinstance(index, slice): - out = [] - for in_i in range(*index.indices(len(self.buf) // self.bpp)): - out.append(self[in_i]) - return out - offset = index * self.bpp - if self.bpp == 4: - w = self.buf[offset + 3] - if w != 0: - return w << 16 | w << 8 | w - return self.buf[offset + 1] << 16 | self.buf[offset] << 8 | self.buf[offset + 2] - - def __len__(self): - return len(self.buf) // self.bpp - def map_range(x, in_min, in_max, out_min, out_max): """ Maps a number from one range to another. From d59428891eca11b436d740b1b1d4038cb064e3a3 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Jul 2017 16:03:18 -0700 Subject: [PATCH 003/131] Fixup the docs. --- .gitignore | 3 +++ README.rst | 10 ++++++---- api.rst | 2 +- conf.py | 16 +++++++++------- simpleio.py | 5 ----- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 72364f9..be5e140 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,6 @@ ENV/ # Rope project settings .ropeproject + +# ReadTheDocs +_build diff --git a/README.rst b/README.rst index 6e09ef7..afcace9 100644 --- a/README.rst +++ b/README.rst @@ -2,15 +2,17 @@ Introduction ============ -.. image:: https://readthedocs.org/projects/adafruit-circuitpython-simpleio2/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/simpleio2/en/latest/ +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-simpleio/badge/?version=latest + :target: https://circuitpython.readthedocs.io/projects/simpleio/en/latest/ :alt: Documentation Status .. image :: https://badges.gitter.im/adafruit/circuitpython.svg :target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge :alt: Gitter -TODO +SimpleIO features a number of helpers to simplify hardware interactions. Many +of the functions and classes are inspired by Arduino APIs to make it easier to +move to CircuitPython from Arduino. Dependencies ============= @@ -31,7 +33,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. API Reference diff --git a/api.rst b/api.rst index 93307a3..67c1b45 100644 --- a/api.rst +++ b/api.rst @@ -1,5 +1,5 @@ .. If you created a package, create one automodule per module in the package. -.. automodule:: adafruit_simpleio2 +.. automodule:: simpleio :members: diff --git a/conf.py b/conf.py index 5ca8ef3..476c76c 100644 --- a/conf.py +++ b/conf.py @@ -15,6 +15,8 @@ 'sphinx.ext.viewcode', ] +autodoc_mock_imports = ["digitalio", "neopixel_write"] + 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. @@ -26,7 +28,7 @@ master_doc = 'README' # General information about the project. -project = u'Adafruit SIMPLEIO2 Library' +project = u'Adafruit CircuitPython SimpleIO Library' copyright = u'2017 Scott Shawcroft' author = u'Scott Shawcroft' @@ -91,7 +93,7 @@ html_static_path = ['_static'] # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitSIMPLEIO2Librarydoc' +htmlhelp_basename = 'AdafruitSimpleIOLibrarydoc' # -- Options for LaTeX output --------------------------------------------- @@ -117,8 +119,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitSIMPLEIO2Library.tex', u'Adafruit SIMPLEIO2 Library Documentation', - u'Phiilip Moyer', 'manual'), + (master_doc, 'AdafruitSimpleIOLibrary.tex', u'Adafruit SimpleIO Library Documentation', + u'Scott Shawcroft', 'manual'), ] # -- Options for manual page output --------------------------------------- @@ -126,7 +128,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitSIMPLEIO2library', u'Adafruit SIMPLEIO2 Library Documentation', + (master_doc, 'adafruitSimpleIOlibrary', u'Adafruit SimpleIO Library Documentation', [author], 1) ] @@ -136,7 +138,7 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitSIMPLEIO2Library', u'Adafruit SIMPLEIO2 Library Documentation', - author, 'AdafruitSIMPLEIO2Library', 'One line description of project.', + (master_doc, 'AdafruitSimpleIOLibrary', u'Adafruit SimpleIO Library Documentation', + author, 'AdafruitSimpleIOLibrary', 'One line description of project.', 'Miscellaneous'), ] diff --git a/simpleio.py b/simpleio.py index 926e765..3515536 100644 --- a/simpleio.py +++ b/simpleio.py @@ -23,16 +23,11 @@ `simpleio` - Simple, beginner friendly IO. ================================================= -.. module:: simpleio - :synopsis: Simple, beginner friendly IO. - :platform: SAMD21, ESP8266 - The `simpleio` module contains classes to provide simple access to IO. """ import digitalio import math -from neopixel_write import neopixel_write class DigitalOut: """ From 1f54b1f98fb4ece4c6132757b0efb8550b9d7b8e Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Jul 2017 16:05:06 -0700 Subject: [PATCH 004/131] Add an extra line to fix rST --- simpleio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/simpleio.py b/simpleio.py index 3515536..4d553fc 100644 --- a/simpleio.py +++ b/simpleio.py @@ -67,6 +67,7 @@ def map_range(x, in_min, in_max, out_min, out_max): """ Maps a number from one range to another. Note: This implementation handles values < in_min differently than arduino's map function does. + :return: Returns value mapped to new range :rtype: float """ From 6e488afebd25b297d0fe2ba155267ff5348d6bb4 Mon Sep 17 00:00:00 2001 From: brentrubell Date: Mon, 31 Jul 2017 21:08:10 -0400 Subject: [PATCH 005/131] shift_in/shift_out (#11) Add `shift_in` and `shift_out` modeled after Arduino's `shiftIn` and `shiftOut`. --- simpleio.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/simpleio.py b/simpleio.py index 4d553fc..da0ab95 100644 --- a/simpleio.py +++ b/simpleio.py @@ -28,6 +28,72 @@ import digitalio import math +import time + +def shift_in(dataPin, clock, msb_first=True): + """ + Shifts in a byte of data one bit at a time. Starts from either the LSB or + MSB. + + :param ~digitalio.DigitalInOut dataPin: pin on which to input each bit + :param ~digitalio.DigitalInOut clock: toggles to signal dataPin reads + :param bool msb_first: True when the first bit is most significant + :return: returns the value read + :rtype: int + """ + + value = 0 + i = 0 + + for i in range(0, 8): + clock.value = True + if msb_first: + value |= ((dataPin.value) << (7-i)) + else: + value |= ((dataPin.value) << i) + clock.value = False + i+=1 + return value + +def shift_out(dataPin, clock, value, msb_first=True): + """ + Shifts out a byte of data one bit at a time. Data gets written to a data + pin. Then, the clock pulses hi then low + + :param ~digitalio.DigitalInOut dataPin: value bits get output on this pin + :param ~digitalio.DigitalInOut clock: toggled once the data pin is set + :param bool msb_first: True when the first bit is most significant + :param int value: byte to be shifted + + Example for Metro M0 Express: + + .. code-block:: python + + import digitalio + import simpleio + from board import * + clock = digitalio.DigitalInOut(D12) + dataPin = digitalio.DigitalInOut(D11) + clock.direction = digitalio.Direction.OUTPUT + dataPin.direction = digitalio.Direction.OUTPUT + + while True: + valueSend = 500 + # shifting out least significant bits + shift_out(dataPin, clock, (valueSend>>8), msb_first = False) + shift_out(dataPin, clock, valueSend, msb_first = False) + # shifting out most significant bits + shift_out(dataPin, clock, (valueSend>>8)) + shift_out(dataPin, clock, valueSend) + """ + value = value&0xFF + for i in range(0, 8): + if msb_first: + tmpval = bool(value & (1 << (7-i))) + dataPin.value = tmpval + else: + tmpval = bool((value & (1 << i))) + dataPin.value = tmpval class DigitalOut: """ From d16f97dd0193d342d2b5615dada129b6b718ebd6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 31 Jul 2017 18:17:17 -0700 Subject: [PATCH 006/131] Remove the neopixel mock since the module has been moved. --- conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.py b/conf.py index 476c76c..a9f5ca2 100644 --- a/conf.py +++ b/conf.py @@ -15,7 +15,7 @@ 'sphinx.ext.viewcode', ] -autodoc_mock_imports = ["digitalio", "neopixel_write"] +autodoc_mock_imports = ["digitalio"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 50dd6c354bc9082ea96fcaa82f9a1974e6bc2cd5 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 31 Jul 2017 18:23:44 -0700 Subject: [PATCH 007/131] Correct example in docs and add warning about pin order. --- simpleio.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/simpleio.py b/simpleio.py index da0ab95..1c4f0f7 100644 --- a/simpleio.py +++ b/simpleio.py @@ -35,6 +35,9 @@ def shift_in(dataPin, clock, msb_first=True): Shifts in a byte of data one bit at a time. Starts from either the LSB or MSB. + .. warning:: Data and clock are swapped compared to other CircuitPython libraries + in order to match Arduino. + :param ~digitalio.DigitalInOut dataPin: pin on which to input each bit :param ~digitalio.DigitalInOut clock: toggles to signal dataPin reads :param bool msb_first: True when the first bit is most significant @@ -60,6 +63,9 @@ def shift_out(dataPin, clock, value, msb_first=True): Shifts out a byte of data one bit at a time. Data gets written to a data pin. Then, the clock pulses hi then low + .. warning:: Data and clock are swapped compared to other CircuitPython libraries + in order to match Arduino. + :param ~digitalio.DigitalInOut dataPin: value bits get output on this pin :param ~digitalio.DigitalInOut clock: toggled once the data pin is set :param bool msb_first: True when the first bit is most significant @@ -80,11 +86,11 @@ def shift_out(dataPin, clock, value, msb_first=True): while True: valueSend = 500 # shifting out least significant bits - shift_out(dataPin, clock, (valueSend>>8), msb_first = False) - shift_out(dataPin, clock, valueSend, msb_first = False) + simpleio.shift_out(dataPin, clock, (valueSend>>8), msb_first = False) + simpleio.shift_out(dataPin, clock, valueSend, msb_first = False) # shifting out most significant bits - shift_out(dataPin, clock, (valueSend>>8)) - shift_out(dataPin, clock, valueSend) + simpleio.shift_out(dataPin, clock, (valueSend>>8)) + simpleio.shift_out(dataPin, clock, valueSend) """ value = value&0xFF for i in range(0, 8): From f4d2736d307d6bcda00debf686bd9a7d7a7c43ed Mon Sep 17 00:00:00 2001 From: brentrubell Date: Tue, 8 Aug 2017 17:10:46 -0400 Subject: [PATCH 008/131] Servo (#15) Added easy control for hobby servos --- simpleio.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/simpleio.py b/simpleio.py index 1c4f0f7..a967bc3 100644 --- a/simpleio.py +++ b/simpleio.py @@ -27,6 +27,7 @@ """ import digitalio +import pulseio import math import time @@ -101,6 +102,57 @@ def shift_out(dataPin, clock, value, msb_first=True): tmpval = bool((value & (1 << i))) dataPin.value = tmpval +class Servo: + """ + Easy control for hobby (3-wire) servos + + :param ~microcontroller.Pin pin: PWM pin where the servo is located. + :param int min_pulse: Pulse width (microseconds) corresponding to 0 degrees. + :param int max_pulse: Pulse width (microseconds) corresponding to 180 degrees. + + Example for Metro M0 Express: + + .. code-block:: python + + import simpleio + import time + from board import * + + pwm = simpleio.Servo(D9) + + while True: + pwm.angle = 0 + print("Angle: ", pwm.angle) + time.sleep(2) + pwm.angle = pwm.microseconds_to_angle(2500) + print("Angle: ", pwm.angle) + time.sleep(2) + """ + def __init__(self, pin, min_pulse = 0.5, max_pulse = 2.5): + self.pwm = pulseio.PWMOut(pin, frequency = 50) + self.min_pulse = min_pulse + self.max_pulse = max_pulse + + @property + def angle(self): + return self._angle + + @angle.setter + def angle(self, degrees): + """Writes a value in degrees to the servo""" + self._angle = max(min(180, degrees), 0) + pulseWidth = 0.5 + (self._angle / 180) * (self.max_pulse - self.min_pulse) + dutyPercent = pulseWidth / 20.0 + self.pwm.duty_cycle = int(dutyPercent * 65535) + + def microseconds_to_angle(self, us): + """Converts microseconds to a degree value""" + return map_range(us, 500, 2500, 0, 180) + + def deinit(self): + """Detaches servo object from pin, frees pin""" + self.pwm.deinit() + class DigitalOut: """ Simple digital output that is valid until soft reset. From f38e5509f60d8280d499ec5c778b96f63cadf638 Mon Sep 17 00:00:00 2001 From: brentrubell Date: Wed, 9 Aug 2017 14:57:04 -0400 Subject: [PATCH 009/131] Introduced tone helper modeled after arduino's tone. Works on digital and analog pins. (#12) Fixes #2 --- simpleio.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index a967bc3..38f5419 100644 --- a/simpleio.py +++ b/simpleio.py @@ -25,12 +25,39 @@ The `simpleio` module contains classes to provide simple access to IO. """ - +import audioio +import array import digitalio import pulseio import math import time +def tone(pin, frequency, duration = 1): + """ + Generates a square wave of the specified frequency (50% duty cycle) + on a pin + + :param ~microcontroller.Pin Pin: Pin on which to output the tone + :param int frequency: Frequency of tone in Hz + :param int duration: Duration of tone in seconds (optional) + """ + try: + length = 4000 // frequency + square_wave = array.array("H", [0] * length) + for i in range(length): + if i < length / 2: + square_wave.append(0xFFFF) + else: + square_wave.append(0x00) + with audioio.AudioOut(pin, square_wave) as waveform: + waveform.play(loop=True) + time.sleep(duration) + waveform.stop() + except ValueError: + with pulseio.PWMOut(pin, frequency = frequency, variable_frequency = False) as pwm: + pwm.duty_cycle = 0x8000 + time.sleep(duration) + def shift_in(dataPin, clock, msb_first=True): """ Shifts in a byte of data one bit at a time. Starts from either the LSB or From 49e181eb108af1a4e01793378e41bcc013be7fe3 Mon Sep 17 00:00:00 2001 From: profbrady Date: Sun, 15 Oct 2017 20:47:14 -0400 Subject: [PATCH 010/131] Update simpleio.py added clock pin toggle for shift_out --- simpleio.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simpleio.py b/simpleio.py index 38f5419..6fd51cc 100644 --- a/simpleio.py +++ b/simpleio.py @@ -122,12 +122,14 @@ def shift_out(dataPin, clock, value, msb_first=True): """ value = value&0xFF for i in range(0, 8): + clock.value = True if msb_first: tmpval = bool(value & (1 << (7-i))) dataPin.value = tmpval else: tmpval = bool((value & (1 << i))) dataPin.value = tmpval + clock.value = False class Servo: """ From 4b389e66fdc205cc786196a03aab79fcdb1826ea Mon Sep 17 00:00:00 2001 From: profbrady Date: Mon, 16 Oct 2017 11:23:51 -0400 Subject: [PATCH 011/131] Update simpleio.py Update for timing of clock toggle in shift_in and shift_out. Add bitWrite function similar to Arduino. --- simpleio.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 6fd51cc..bb80a7b 100644 --- a/simpleio.py +++ b/simpleio.py @@ -58,6 +58,24 @@ def tone(pin, frequency, duration = 1): pwm.duty_cycle = 0x8000 time.sleep(duration) +def bitWrite(x,n,b): + """ + Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. + The return value is the original value with the changed bit. + This function is written for use with 8-bit shift registers + + :param x: numeric value + :param n: position to change starting with least-significant (right-most) bit as 0 + :param b: value to write (0 or 1) + """ + if b==1: + x |= 1<>8), msb_first = False) + latchPin.value = True + time.sleep(1.0) + latchPin.value = False simpleio.shift_out(dataPin, clock, valueSend, msb_first = False) + latchPin.value = True + time.sleep(1.0) + # shifting out most significant bits + latchPin.value = False simpleio.shift_out(dataPin, clock, (valueSend>>8)) + latchPin.value = True + time.sleep(1.0) + latchpin.value = False simpleio.shift_out(dataPin, clock, valueSend) + latchpin.value = True + time.sleep(1.0) """ value = value&0xFF for i in range(0, 8): - clock.value = True if msb_first: tmpval = bool(value & (1 << (7-i))) dataPin.value = tmpval else: tmpval = bool((value & (1 << i))) dataPin.value = tmpval + # toggle clock pin True/False + clock.value = True clock.value = False class Servo: From 7b144cee8d5b9368fa1f785c4d23c5a8a8212dc6 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 16 Oct 2017 15:34:40 -0400 Subject: [PATCH 012/131] fix for gemma/trinket and other non-audio boards --- simpleio.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index bb80a7b..a79174f 100644 --- a/simpleio.py +++ b/simpleio.py @@ -25,7 +25,10 @@ The `simpleio` module contains classes to provide simple access to IO. """ -import audioio +try: + import audioio +except ImportError: + pass # not always supported by every board! import array import digitalio import pulseio @@ -53,7 +56,7 @@ def tone(pin, frequency, duration = 1): waveform.play(loop=True) time.sleep(duration) waveform.stop() - except ValueError: + except (NameError, ValueError): with pulseio.PWMOut(pin, frequency = frequency, variable_frequency = False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) From db9762a3e88157adb4d1dea428af720cbbfafd91 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Wed, 13 Dec 2017 15:57:11 -0700 Subject: [PATCH 013/131] add pylint to project and updated code --- .gitignore | 3 + .pylintrc | 432 ++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 63 +++---- readthedocs.yml | 3 +- simpleio.py | 87 +++++----- 5 files changed, 501 insertions(+), 87 deletions(-) create mode 100644 .pylintrc diff --git a/.gitignore b/.gitignore index be5e140..0763dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,6 @@ ENV/ # ReadTheDocs _build + +build* +bundles diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..946d694 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,432 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +# jobs=1 +jobs=2 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= +expected-line-ending-format=LF + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma,dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[BASIC] + +# Naming hint for argument names +argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct argument names +argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for attribute names +attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct attribute names +attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming hint for class names +# class-name-hint=[A-Z_][a-zA-Z0-9]+$ +class-name-hint=[A-Z_][a-zA-Z0-9_]+$ + +# Regular expression matching correct class names +# class-rgx=[A-Z_][a-zA-Z0-9]+$ +class-rgx=[A-Z_][a-zA-Z0-9_]+$ + +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming hint for function names +function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct function names +function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Good variable names which should always be accepted, separated by a comma +# good-names=i,j,k,ex,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming hint for method names +method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct method names +method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming hint for variable names +variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct variable names +variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +# max-attributes=7 +max-attributes=11 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=1 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/.travis.yml b/.travis.yml index 9afc2c3..31e1c7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,53 +1,30 @@ -# Travis CI configuration for automated .mpy file generation. -# Author: Tony DiCola -# License: Public Domain -# This configuration will work with Travis CI (travis-ci.org) to automacially -# build .mpy files for CircuitPython when a new tagged release is created. This -# file is relatively generic and can be shared across multiple repositories by -# following these steps: -# 1. Copy this file into a .travis.yml file in the root of the repository. -# 2. Change the deploy > file section below to list each of the .mpy files -# that should be generated. The config will automatically look for -# .py files with the same name as the source for generating the .mpy files. -# Note that the .mpy extension should be lower case! -# 3. Commit the .travis.yml file and push it to GitHub. -# 4. Go to travis-ci.org and find the repository (it needs to be setup to access -# your github account, and your github account needs access to write to the -# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis -# docs for more details: https://docs.travis-ci.com/user/getting-started/ -# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or -# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/ -# Keep this token safe and secure! Anyone with the token will be able to -# access and write to your GitHub repositories. Travis will use the token -# to attach the .mpy files to the release. -# 6. In the Travis CI settings for the repository that was enabled find the -# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings -# Add an environment variable named GITHUB_TOKEN and set it to the value -# of the GitHub personal access token above. Keep 'Display value in build -# log' flipped off. -# 7. That's it! Tag a release and Travis should go to work to add .mpy files -# to the release. It takes about a 2-3 minutes for a worker to spin up, -# build mpy-cross, and add the binaries to the release. -language: generic +# This is a common .travis.yml for generating library release zip files for +# CircuitPython library releases using circuitpython-build-tools. +# See https://github.com/adafruit/circuitpython-build-tools for detailed setup +# instructions. -sudo: true +dist: trusty +sudo: false +language: python +python: + - "3.6" + +cache: + pip: true deploy: provider: releases api_key: $GITHUB_TOKEN - file: - - "simpleio.mpy" + file_glob: true + file: bundles/* skip_cleanup: true on: tags: true -before_install: -- sudo apt-get -yqq update -- sudo apt-get install -y build-essential git python python-pip -- git clone https://github.com/adafruit/circuitpython.git -- make -C circuitpython/mpy-cross -- export PATH=$PATH:$PWD/circuitpython/mpy-cross/ -- sudo pip install shyaml +install: + - pip install pylint circuitpython-build-tools -before_deploy: -- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross +script: + - pylint simpleio.py + - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) + - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location . diff --git a/readthedocs.yml b/readthedocs.yml index a3a16c1..f4243ad 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -1,2 +1,3 @@ +python: + version: 3 requirements_file: requirements.txt - diff --git a/simpleio.py b/simpleio.py index a79174f..278baca 100644 --- a/simpleio.py +++ b/simpleio.py @@ -25,6 +25,7 @@ The `simpleio` module contains classes to provide simple access to IO. """ +import time try: import audioio except ImportError: @@ -32,10 +33,8 @@ import array import digitalio import pulseio -import math -import time -def tone(pin, frequency, duration = 1): +def tone(pin, frequency, duration=1): """ Generates a square wave of the specified frequency (50% duty cycle) on a pin @@ -57,29 +56,29 @@ def tone(pin, frequency, duration = 1): time.sleep(duration) waveform.stop() except (NameError, ValueError): - with pulseio.PWMOut(pin, frequency = frequency, variable_frequency = False) as pwm: + with pulseio.PWMOut(pin, frequency=frequency, variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) -def bitWrite(x,n,b): +def bitWrite(x, n, b): #pylint: disable-msg=invalid-name """ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. The return value is the original value with the changed bit. This function is written for use with 8-bit shift registers - + :param x: numeric value :param n: position to change starting with least-significant (right-most) bit as 0 :param b: value to write (0 or 1) """ - if b==1: + if b == 1: x |= 1<>8), msb_first = False) + simpleio.shift_out(data_pin, clock, (valueSend>>8), msb_first = False) latchPin.value = True time.sleep(1.0) latchPin.value = False - simpleio.shift_out(dataPin, clock, valueSend, msb_first = False) + simpleio.shift_out(data_pin, clock, valueSend, msb_first = False) latchPin.value = True time.sleep(1.0) - + # shifting out most significant bits latchPin.value = False - simpleio.shift_out(dataPin, clock, (valueSend>>8)) + simpleio.shift_out(data_pin, clock, (valueSend>>8)) latchPin.value = True time.sleep(1.0) latchpin.value = False - simpleio.shift_out(dataPin, clock, valueSend) + simpleio.shift_out(data_pin, clock, valueSend) latchpin.value = True time.sleep(1.0) """ @@ -163,10 +162,10 @@ def shift_out(dataPin, clock, value, msb_first=True): for i in range(0, 8): if msb_first: tmpval = bool(value & (1 << (7-i))) - dataPin.value = tmpval + data_pin.value = tmpval else: tmpval = bool((value & (1 << i))) - dataPin.value = tmpval + data_pin.value = tmpval # toggle clock pin True/False clock.value = True clock.value = False @@ -197,24 +196,26 @@ class Servo: print("Angle: ", pwm.angle) time.sleep(2) """ - def __init__(self, pin, min_pulse = 0.5, max_pulse = 2.5): - self.pwm = pulseio.PWMOut(pin, frequency = 50) + def __init__(self, pin, min_pulse=0.5, max_pulse=2.5): + self.pwm = pulseio.PWMOut(pin, frequency=50) self.min_pulse = min_pulse self.max_pulse = max_pulse + self._angle = None @property def angle(self): + """Get and set the servo angle in degrees""" return self._angle @angle.setter def angle(self, degrees): """Writes a value in degrees to the servo""" self._angle = max(min(180, degrees), 0) - pulseWidth = 0.5 + (self._angle / 180) * (self.max_pulse - self.min_pulse) - dutyPercent = pulseWidth / 20.0 - self.pwm.duty_cycle = int(dutyPercent * 65535) + pulse_width = 0.5 + (self._angle / 180) * (self.max_pulse - self.min_pulse) + duty_percent = pulse_width / 20.0 + self.pwm.duty_cycle = int(duty_percent * 65535) - def microseconds_to_angle(self, us): + def microseconds_to_angle(self, us): #pylint: disable-msg=no-self-use, invalid-name """Converts microseconds to a degree value""" return map_range(us, 500, 2500, 0, 180) @@ -227,33 +228,33 @@ class DigitalOut: Simple digital output that is valid until soft reset. """ def __init__(self, pin): - self.io = digitalio.DigitalInOut(pin) - self.io.switch_to_output() + self.iopin = digitalio.DigitalInOut(pin) + self.iopin.switch_to_output() @property def value(self): """The digital logic level of the output pin.""" - return self.io.value + return self.iopin.value @value.setter def value(self, value): - self.io.value = value + self.iopin.value = value class DigitalIn: """ Simple digital input that is valid until soft reset. """ def __init__(self, pin): - self.io = digitalio.DigitalInOut(pin) - self.io.switch_to_input() + self.iopin = digitalio.DigitalInOut(pin) + self.iopin.switch_to_input() @property def value(self): """The digital logic level of the input pin.""" - return self.io.value + return self.iopin.value @value.setter - def value(self, value): + def value(self, value): #pylint: disable-msg=no-self-use, unused-argument raise AttributeError("Cannot set the value on a digital input.") def map_range(x, in_min, in_max, out_min, out_max): From 3bf083da497365de19f44d2960f00c44ee68c21f Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 23 Dec 2017 15:03:37 -0500 Subject: [PATCH 014/131] handle reversed range on output --- simpleio.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 278baca..f91151d 100644 --- a/simpleio.py +++ b/simpleio.py @@ -265,4 +265,9 @@ def map_range(x, in_min, in_max, out_min, out_max): :return: Returns value mapped to new range :rtype: float """ - return max(min((x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min, out_max), out_min) + t = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min + if out_min <= out_max: + return max(min(t, out_max), out_min) + else: + return min(max(t, out_max), out_min) + From 10cd9446e2e942baa82eb6ab1bec6fc962a4c0e1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 26 Dec 2017 10:15:31 -0800 Subject: [PATCH 015/131] Make lint happy --- simpleio.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/simpleio.py b/simpleio.py index f91151d..a79daf4 100644 --- a/simpleio.py +++ b/simpleio.py @@ -265,9 +265,7 @@ def map_range(x, in_min, in_max, out_min, out_max): :return: Returns value mapped to new range :rtype: float """ - t = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min + mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min if out_min <= out_max: - return max(min(t, out_max), out_min) - else: - return min(max(t, out_max), out_min) - + return max(min(mapped, out_max), out_min) + return min(max(mapped, out_max), out_min) From 253dc704092f322ddded54ff8cba0138ff992787 Mon Sep 17 00:00:00 2001 From: brentrubell Date: Fri, 5 Jan 2018 14:47:07 -0500 Subject: [PATCH 016/131] Changes to the tone function (#24) * Changes to the tone function: - uses a fixed length square wave as default (can be variable) like in the mega demo - frequency is now a float instead of an int linted and added example --- examples/tone_demo.py | 15 +++++++++++++++ simpleio.py | 35 ++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 examples/tone_demo.py diff --git a/examples/tone_demo.py b/examples/tone_demo.py new file mode 100644 index 0000000..60f80be --- /dev/null +++ b/examples/tone_demo.py @@ -0,0 +1,15 @@ +""" +'tone_demo.py'. + +================================================= +a short piezo song using tone() +""" +import time +import board +import simpleio + + +while True: + for f in (262, 294, 330, 349, 392, 440, 494, 523): + simpleio.tone(board.A0, f, 0.25) + time.sleep(1) diff --git a/simpleio.py b/simpleio.py index a79daf4..cd9e032 100644 --- a/simpleio.py +++ b/simpleio.py @@ -34,31 +34,32 @@ import digitalio import pulseio -def tone(pin, frequency, duration=1): +def tone(pin, frequency, duration=1, length=100): """ - Generates a square wave of the specified frequency (50% duty cycle) - on a pin + Generates a square wave of the specified frequency on a pin :param ~microcontroller.Pin Pin: Pin on which to output the tone - :param int frequency: Frequency of tone in Hz + :param float frequency: Frequency of tone in Hz + :param int length: Variable size buffer (optional) :param int duration: Duration of tone in seconds (optional) """ try: - length = 4000 // frequency - square_wave = array.array("H", [0] * length) - for i in range(length): - if i < length / 2: - square_wave.append(0xFFFF) - else: - square_wave.append(0x00) - with audioio.AudioOut(pin, square_wave) as waveform: - waveform.play(loop=True) - time.sleep(duration) - waveform.stop() - except (NameError, ValueError): - with pulseio.PWMOut(pin, frequency=frequency, variable_frequency=False) as pwm: + with pulseio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) + except ValueError: + sample_length = length + square_wave = array.array("H", [0] * sample_length) + for i in range(sample_length / 2): + square_wave[i] = 0xFFFF + sample_tone = audioio.AudioOut(pin, square_wave) + sample_tone.frequency = int(len(square_wave) * frequency) + if not sample_tone.playing: + sample_tone.play(loop=True) + time.sleep(duration) + sample_tone.stop() + + def bitWrite(x, n, b): #pylint: disable-msg=invalid-name """ From 471570a2f647a162c0774f2b07c022e5af4a0e06 Mon Sep 17 00:00:00 2001 From: inventhouse Date: Sun, 28 Jan 2018 09:04:59 -0800 Subject: [PATCH 017/131] pulse_width needs to use min_pulse Angle setter had hardcoded 0.5 where it should have used self.min_pulse --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index cd9e032..629c3f2 100644 --- a/simpleio.py +++ b/simpleio.py @@ -212,7 +212,7 @@ def angle(self): def angle(self, degrees): """Writes a value in degrees to the servo""" self._angle = max(min(180, degrees), 0) - pulse_width = 0.5 + (self._angle / 180) * (self.max_pulse - self.min_pulse) + pulse_width = self.min_pulse + (self._angle / 180) * (self.max_pulse - self.min_pulse) duty_percent = pulse_width / 20.0 self.pwm.duty_cycle = int(duty_percent * 65535) From 6e12c33246a7e448d9adcfcf7393743e129b9f52 Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 31 Jan 2018 11:13:08 -0500 Subject: [PATCH 018/131] updated variables for pylint --- examples/map_range_demo.py | 22 ++++++++++++++++++++++ examples/shift_in_out_demo.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 examples/map_range_demo.py create mode 100644 examples/shift_in_out_demo.py diff --git a/examples/map_range_demo.py b/examples/map_range_demo.py new file mode 100644 index 0000000..0fcdef5 --- /dev/null +++ b/examples/map_range_demo.py @@ -0,0 +1,22 @@ +""" +'map_range_demo.py'. + +================================================= +maps a number from one range to another +""" +import time +import simpleio + +while True: + sensor_value = 150 + + # Map the sensor's range from 0<=sensor_value<=255 to 0<=sensor_value<=1023 + print('original sensor value: ', sensor_value) + mapped_value = simpleio.map_range(sensor_value, 0, 255, 0, 1023) + print('mapped sensor value: ', mapped_value) + time.sleep(2) + + # Map the new sensor value back to the old range + sensor_value = simpleio.map_range(mapped_value, 0, 1023, 0, 255) + print('original value returned: ', sensor_value) + time.sleep(2) diff --git a/examples/shift_in_out_demo.py b/examples/shift_in_out_demo.py new file mode 100644 index 0000000..5b6d978 --- /dev/null +++ b/examples/shift_in_out_demo.py @@ -0,0 +1,35 @@ +""" +'shift_in_out_demo.py'. + +================================================= +shifts data into and out of a data pin +""" + +import time +import board +import digitalio +import simpleio + +# set up clock, data, and latch pins +clk = digitalio.DigitalInOut(board.D12) +data = digitalio.DigitalInOut(board.D11) +latch = digitalio.DigitalInOut(board.D10) +clk.direction = digitalio.Direction.OUTPUT +latch.direction = digitalio.Direction.OUTPUT + +while True: + data_to_send = 256 + # shifting 256 bits out of data pin + latch.value = False + data.direction = digitalio.Direction.OUTPUT + print('shifting out...') + simpleio.shift_out(data, clk, data_to_send, msb_first=False) + latch.value = True + time.sleep(3) + + # shifting 256 bits into the data pin + latch.value = False + data.direction = digitalio.Direction.INPUT + print('shifting in...') + simpleio.shift_in(data, clk) + time.sleep(3) From 21fed8ebd3b6e84c635c7095aa8c4b8f51dcb7e8 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 19 Jan 2018 16:26:34 -0500 Subject: [PATCH 019/131] added examples for map_range and shift_in/shift_out --- examples/map_range_demo.py | 22 ++++++++++++++++++++++ examples/shift_in_out_demo.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 examples/map_range_demo.py create mode 100644 examples/shift_in_out_demo.py diff --git a/examples/map_range_demo.py b/examples/map_range_demo.py new file mode 100644 index 0000000..b7036e7 --- /dev/null +++ b/examples/map_range_demo.py @@ -0,0 +1,22 @@ +""" +'map_range_demo.py'. + +================================================= +maps a number from one range to another +""" +import time +import simpleio + +while True: + SENSOR_VALUE = 150 + + # Map the sensor's range from 0<=SENSOR_VALUE<=255 to 0<=SENSOR_VALUE<=1023 + print('original sensor value: ', SENSOR_VALUE) + MAPPED_VALUE = simpleio.map_range(SENSOR_VALUE, 0, 255, 0, 1023) + print('mapped sensor value: ', MAPPED_VALUE) + time.sleep(2) + + # Map the new sensor value back to the old range + SENSOR_VALUE = simpleio.map_range(MAPPED_VALUE, 0, 1023, 0, 255) + print('original value returned: ', SENSOR_VALUE) + time.sleep(2) diff --git a/examples/shift_in_out_demo.py b/examples/shift_in_out_demo.py new file mode 100644 index 0000000..0727dfb --- /dev/null +++ b/examples/shift_in_out_demo.py @@ -0,0 +1,35 @@ +""" +'shift_in_out_demo.py'. + +================================================= +shifts data into and out of a data pin +""" + +import time +import board +import digitalio +import simpleio + +# set up clock, data, and latch pins +CLK = digitalio.DigitalInOut(board.D12) +CLK.direction = digitalio.Direction.OUTPUT +DATA = digitalio.DigitalInOut(board.D11) +LATCH = digitalio.DigitalInOut(board.D10) +LATCH.direction = digitalio.Direction.OUTPUT + +while True: + DATA_TO_SEND = 256 + # shifting 256 bits out of DATA pin + LATCH.value = False + DATA.direction = digitalio.Direction.OUTPUT + print('shifting out...') + simpleio.shift_out(DATA, CLK, DATA_TO_SEND, msb_first=False) + LATCH.value = True + time.sleep(3) + + # shifting 256 bits into the DATA pin + LATCH.value = False + DATA.direction = digitalio.Direction.INPUT + print('shifting in...') + simpleio.shift_in(DATA, CLK) + time.sleep(3) From fbfe6e3945cde84f29b20aa7f95824594b009bbf Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 31 Jan 2018 17:53:45 -0500 Subject: [PATCH 020/131] fixed variables in examples --- examples/map_range_demo.py | 14 +++++++------- examples/shift_in_out_demo.py | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/map_range_demo.py b/examples/map_range_demo.py index b7036e7..0fcdef5 100644 --- a/examples/map_range_demo.py +++ b/examples/map_range_demo.py @@ -8,15 +8,15 @@ import simpleio while True: - SENSOR_VALUE = 150 + sensor_value = 150 - # Map the sensor's range from 0<=SENSOR_VALUE<=255 to 0<=SENSOR_VALUE<=1023 - print('original sensor value: ', SENSOR_VALUE) - MAPPED_VALUE = simpleio.map_range(SENSOR_VALUE, 0, 255, 0, 1023) - print('mapped sensor value: ', MAPPED_VALUE) + # Map the sensor's range from 0<=sensor_value<=255 to 0<=sensor_value<=1023 + print('original sensor value: ', sensor_value) + mapped_value = simpleio.map_range(sensor_value, 0, 255, 0, 1023) + print('mapped sensor value: ', mapped_value) time.sleep(2) # Map the new sensor value back to the old range - SENSOR_VALUE = simpleio.map_range(MAPPED_VALUE, 0, 1023, 0, 255) - print('original value returned: ', SENSOR_VALUE) + sensor_value = simpleio.map_range(mapped_value, 0, 1023, 0, 255) + print('original value returned: ', sensor_value) time.sleep(2) diff --git a/examples/shift_in_out_demo.py b/examples/shift_in_out_demo.py index 0727dfb..5b6d978 100644 --- a/examples/shift_in_out_demo.py +++ b/examples/shift_in_out_demo.py @@ -11,25 +11,25 @@ import simpleio # set up clock, data, and latch pins -CLK = digitalio.DigitalInOut(board.D12) -CLK.direction = digitalio.Direction.OUTPUT -DATA = digitalio.DigitalInOut(board.D11) -LATCH = digitalio.DigitalInOut(board.D10) -LATCH.direction = digitalio.Direction.OUTPUT +clk = digitalio.DigitalInOut(board.D12) +data = digitalio.DigitalInOut(board.D11) +latch = digitalio.DigitalInOut(board.D10) +clk.direction = digitalio.Direction.OUTPUT +latch.direction = digitalio.Direction.OUTPUT while True: - DATA_TO_SEND = 256 - # shifting 256 bits out of DATA pin - LATCH.value = False - DATA.direction = digitalio.Direction.OUTPUT + data_to_send = 256 + # shifting 256 bits out of data pin + latch.value = False + data.direction = digitalio.Direction.OUTPUT print('shifting out...') - simpleio.shift_out(DATA, CLK, DATA_TO_SEND, msb_first=False) - LATCH.value = True + simpleio.shift_out(data, clk, data_to_send, msb_first=False) + latch.value = True time.sleep(3) - # shifting 256 bits into the DATA pin - LATCH.value = False - DATA.direction = digitalio.Direction.INPUT + # shifting 256 bits into the data pin + latch.value = False + data.direction = digitalio.Direction.INPUT print('shifting in...') - simpleio.shift_in(DATA, CLK) + simpleio.shift_in(data, clk) time.sleep(3) From 705fc1960db20f6cc635a79f7097c92ec6c50630 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 23 Feb 2018 14:15:04 -0500 Subject: [PATCH 021/131] Fix autodoc --- conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.py b/conf.py index a9f5ca2..f8999f4 100644 --- a/conf.py +++ b/conf.py @@ -15,7 +15,7 @@ 'sphinx.ext.viewcode', ] -autodoc_mock_imports = ["digitalio"] +autodoc_mock_imports = ["digitalio", "audioio", "pulseio"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 564c40d62e166a46f2f50002b3cd95f4f14edd0c Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 6 Mar 2018 20:01:32 -0600 Subject: [PATCH 022/131] setup docs folder --- docs/_static/favicon.ico | Bin 0 -> 4414 bytes api.rst => docs/api.rst | 0 conf.py => docs/conf.py | 15 ++++++++++--- docs/examples.rst | 16 ++++++++++++++ docs/index.rst | 45 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 docs/_static/favicon.ico rename api.rst => docs/api.rst (100%) rename conf.py => docs/conf.py (90%) create mode 100644 docs/examples.rst create mode 100644 docs/index.rst diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5aca98376a1f7e593ebd9cf41a808512c2135635 GIT binary patch literal 4414 zcmd^BX;4#F6n=SG-XmlONeGrD5E6J{RVh+e928U#MG!$jWvO+UsvWh`x&VqGNx*en zx=qox7Dqv{kPwo%fZC$dDwVpRtz{HzTkSs8QhG0)%Y=-3@Kt!4ag|JcIo?$-F|?bXVS9UDUyev>MVZQ(H8K4#;BQW-t2CPorj8^KJrMX}QK zp+e<;4ldpXz~=)2GxNy811&)gt-}Q*yVQpsxr@VMoA##{)$1~=bZ1MmjeFw?uT(`8 z^g=09<=zW%r%buwN%iHtuKSg|+r7HkT0PYN*_u9k1;^Ss-Z!RBfJ?Un4w(awqp2b3 z%+myoFis_lTlCrGx2z$0BQdh+7?!JK#9K9@Z!VrG zNj6gK5r(b4?YDOLw|DPRoN7bdP{(>GEG41YcN~4r_SUHU2hgVtUwZG@s%edC;k7Sn zC)RvEnlq~raE2mY2ko64^m1KQL}3riixh?#J{o)IT+K-RdHae2eRX91-+g!y`8^># z-zI0ir>P%Xon)!@xp-BK2bDYUB9k613NRrY6%lVjbFcQc*pRqiK~8xtkNPLxt}e?&QsTB}^!39t_%Qb)~Ukn0O%iC;zt z<&A-y;3h++)>c1br`5VFM~5(83!HKx$L+my8sW_c#@x*|*vB1yU)_dt3vH;2hqPWx zAl^6@?ipx&U7pf`a*>Yq6C85nb+B=Fnn+(id$W#WB^uHAcZVG`qg;rWB}ubvi(Y>D z$ei>REw$#xp0SHAd^|1hq&9HJ=jKK8^zTH~nk)G?yUcmTh9vUM6Y0LMw4(gYVY$D$ zGl&WY&H<)BbJ&3sYbKjx1j^=3-0Q#f^}(aP1?8^`&FUWMp|rmtpK)bLQ1Zo?^s4jqK=Lfg*9&geMGVQ z#^-*!V`fG@;H&{M9S8%+;|h&Qrxym0Ar>WT4BCVLR8cGXF=JmEYN(sNT(9vl+S|%g z8r7nXQ(95i^`=+XHo|){$vf2$?=`F$^&wFlYXyXg$B{a>$-Fp+V}+D;9k=~Xl~?C4 zAB-;RKXdUzBJE{V&d&%R>aEfFe;vxqI$0@hwVM}gFeQR@j}a>DDxR+n+-*6|_)k%% z*mSpDV|=5I9!&VC&9tD%fcVygWZV!iIo2qFtm#!*(s|@ZT33*Ad;+<|3^+yrp*;oH zBSYLV(H1zTU?2WjrCQoQW)Z>J2a=dTriuvezBmu16`tM2fm7Q@d4^iqII-xFpwHGI zn9CL}QE*1vdj2PX{PIuqOe5dracsciH6OlAZATvE8rj6ykqdIjal2 z0S0S~PwHb-5?OQ-tU-^KTG@XNrEVSvo|HIP?H;7ZhYeZkhSqh-{reE!5di;1zk$#Y zCe7rOnlzFYJ6Z#Hm$GoidKB=2HBCwm`BbZVeZY4ukmG%1uz7p2URs6c9j-Gjj^oQV zsdDb3@k2e`C$1I5ML5U0Qs0C1GAp^?!*`=|Nm(vWz3j*j*8ucum2;r0^-6Aca=Gv) zc%}&;!+_*S2tlnnJnz0EKeRmw-Y!@9ob!XQBwiv}^u9MkaXHvM=!<3YX;+2#5Cj5pp?FEK750S3BgeSDtaE^ zXUM@xoV6yBFKfzvY20V&Lr0yC + CircuitPython Reference Documentation + CircuitPython Support Forum + Discord Chat + Adafruit Learning System + Adafruit Blog + Adafruit Store + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` From 82841b8fd4dd9a8db5ebabc39378b386ea537bfc Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 6 Mar 2018 20:02:56 -0600 Subject: [PATCH 023/131] updated .travis & .readthedocs yml --- readthedocs.yml => .readthedocs.yml | 0 .travis.yml | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) rename readthedocs.yml => .readthedocs.yml (100%) diff --git a/readthedocs.yml b/.readthedocs.yml similarity index 100% rename from readthedocs.yml rename to .readthedocs.yml diff --git a/.travis.yml b/.travis.yml index 31e1c7c..4e400dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,15 +16,17 @@ deploy: provider: releases api_key: $GITHUB_TOKEN file_glob: true - file: bundles/* + file: $TRAVIS_BUILD_DIR/bundles/* skip_cleanup: true + overwrite: true on: tags: true install: - - pip install pylint circuitpython-build-tools + - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme script: - pylint simpleio.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location . + - cd docs && sphinx-build -E -W -b html . _build/html \ No newline at end of file From 510acf6434f6e147d91df2b33ab8cff7f568066c Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 6 Mar 2018 20:05:04 -0600 Subject: [PATCH 024/131] updated README --- README.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index afcace9..454148b 100644 --- a/README.rst +++ b/README.rst @@ -6,9 +6,13 @@ Introduction :target: https://circuitpython.readthedocs.io/projects/simpleio/en/latest/ :alt: Documentation Status -.. image :: https://badges.gitter.im/adafruit/circuitpython.svg - :target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge - :alt: Gitter +.. image :: https://img.shields.io/discord/327254708534116352.svg + :target: https://discord.gg/nBQh6qu + :alt: Discord + +.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_SimpleIO.svg?branch=master + :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_SimpleIO + :alt: Build Status SimpleIO features a number of helpers to simplify hardware interactions. Many of the functions and classes are inspired by Arduino APIs to make it easier to @@ -27,7 +31,7 @@ This is easily achieved by downloading Usage Example ============= -TODO +See the examples in the `examples/` folder for usage. Contributing ============ @@ -36,10 +40,50 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -API Reference -============= +Building locally +================ + +To build this library locally you'll need to install the +`circuitpython-build-tools `_ package. + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install circuitpython-build-tools + +Once installed, make sure you are in the virtual environment: + +.. code-block:: shell + + source .env/bin/activate + +Then run the build: + +.. code-block:: shell + + circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location . + +Sphinx documentation +----------------------- + +Sphinx is used to build the documentation based on rST files and comments in the code. First, +install dependencies (feel free to reuse the virtual environment from above): + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install Sphinx sphinx-rtd-theme + +Now, once you have the virtual environment activated: + +.. code-block:: shell + + cd docs + sphinx-build -E -W -b html . _build/html -.. toctree:: - :maxdepth: 2 +This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to +view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to +locally verify it will pass. - api From b26ae3128753cb79a7b6fc5acd28263e41080e73 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 6 Mar 2018 20:07:09 -0600 Subject: [PATCH 025/131] updated info docsrting --- simpleio.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simpleio.py b/simpleio.py index 629c3f2..60870c9 100644 --- a/simpleio.py +++ b/simpleio.py @@ -24,6 +24,8 @@ ================================================= The `simpleio` module contains classes to provide simple access to IO. + +* Author(s): Scott Shawcroft """ import time try: From 4efb12424509292323e60572f88f4770150c2e96 Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Tue, 15 May 2018 15:14:22 -0400 Subject: [PATCH 026/131] https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/issues/10 - pass any submitted parameters supported by the underlying call --- simpleio.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/simpleio.py b/simpleio.py index 60870c9..5343039 100644 --- a/simpleio.py +++ b/simpleio.py @@ -230,9 +230,12 @@ class DigitalOut: """ Simple digital output that is valid until soft reset. """ - def __init__(self, pin): + def __init__(self, pin, value=None, drive_mode=None): + """ + """ + kwargs = {k: v for k, v in (('value', value), ('drive_mode', drive_mode)) if not v is None} self.iopin = digitalio.DigitalInOut(pin) - self.iopin.switch_to_output() + self.iopin.switch_to_output(**kwargs) @property def value(self): @@ -247,9 +250,10 @@ class DigitalIn: """ Simple digital input that is valid until soft reset. """ - def __init__(self, pin): + def __init__(self, pin, pull=None): + kwargs = {k: v for k, v in (('pull', pull),) if not v is None} self.iopin = digitalio.DigitalInOut(pin) - self.iopin.switch_to_input() + self.iopin.switch_to_input(**kwargs) @property def value(self): From b40cdbce742a5cf4d53c35d9261b2cd669c52c2a Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Tue, 15 May 2018 15:27:57 -0400 Subject: [PATCH 027/131] update docstring --- simpleio.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simpleio.py b/simpleio.py index 5343039..9e23a82 100644 --- a/simpleio.py +++ b/simpleio.py @@ -232,6 +232,8 @@ class DigitalOut: """ def __init__(self, pin, value=None, drive_mode=None): """ + value and drive_mode: if passed in will be passed to switch_to_output + see digitalio.DigitalInOut.switch_to_output for more details """ kwargs = {k: v for k, v in (('value', value), ('drive_mode', drive_mode)) if not v is None} self.iopin = digitalio.DigitalInOut(pin) @@ -251,6 +253,10 @@ class DigitalIn: Simple digital input that is valid until soft reset. """ def __init__(self, pin, pull=None): + """ + pull: if passed in will be passed to switch_to_input + see digitalio.DigitalInOut.switch_to_input for more details + """ kwargs = {k: v for k, v in (('pull', pull),) if not v is None} self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_input(**kwargs) From 47f5eb25d979219eae00771b1cf95af0b5d1c933 Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Thu, 17 May 2018 21:44:09 -0400 Subject: [PATCH 028/131] changed signature and docstring --- simpleio.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/simpleio.py b/simpleio.py index 9e23a82..62ab5e0 100644 --- a/simpleio.py +++ b/simpleio.py @@ -232,8 +232,9 @@ class DigitalOut: """ def __init__(self, pin, value=None, drive_mode=None): """ - value and drive_mode: if passed in will be passed to switch_to_output - see digitalio.DigitalInOut.switch_to_output for more details + kwargs will be passed directly to switch_to_output + value (bool): default value to set upon switching + drive_mode (DriveMode): drive mode for the output """ kwargs = {k: v for k, v in (('value', value), ('drive_mode', drive_mode)) if not v is None} self.iopin = digitalio.DigitalInOut(pin) @@ -252,12 +253,11 @@ class DigitalIn: """ Simple digital input that is valid until soft reset. """ - def __init__(self, pin, pull=None): + def __init__(self, pin, **kwargs): """ - pull: if passed in will be passed to switch_to_input - see digitalio.DigitalInOut.switch_to_input for more details + kwargs will be passed directly to switch_to_input + pull (pull): pull configuration for the input """ - kwargs = {k: v for k, v in (('pull', pull),) if not v is None} self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_input(**kwargs) From 42a5a3771918b07dbe1c9f294e6905e31b1ccf7e Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Thu, 17 May 2018 21:46:49 -0400 Subject: [PATCH 029/131] changed signature again --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 62ab5e0..dac75b9 100644 --- a/simpleio.py +++ b/simpleio.py @@ -230,7 +230,7 @@ class DigitalOut: """ Simple digital output that is valid until soft reset. """ - def __init__(self, pin, value=None, drive_mode=None): + def __init__(self, pin, **kwargs): """ kwargs will be passed directly to switch_to_output value (bool): default value to set upon switching From 2d969baf336e1b70df08204b807c5e793816bb35 Mon Sep 17 00:00:00 2001 From: Adam Patt Date: Thu, 17 May 2018 21:49:13 -0400 Subject: [PATCH 030/131] fixed body to match new signature --- simpleio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index dac75b9..2abf9b4 100644 --- a/simpleio.py +++ b/simpleio.py @@ -236,7 +236,6 @@ def __init__(self, pin, **kwargs): value (bool): default value to set upon switching drive_mode (DriveMode): drive mode for the output """ - kwargs = {k: v for k, v in (('value', value), ('drive_mode', drive_mode)) if not v is None} self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_output(**kwargs) From 5c0b8edace06cc3e1458e7e92179ebe703348463 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 18 May 2018 11:57:21 -0500 Subject: [PATCH 031/131] Combine docs Don't mention switch methods which are implementation details. --- simpleio.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/simpleio.py b/simpleio.py index 2abf9b4..6314bd7 100644 --- a/simpleio.py +++ b/simpleio.py @@ -228,14 +228,13 @@ def deinit(self): class DigitalOut: """ - Simple digital output that is valid until soft reset. + Simple digital output that is valid until reload. + + :param pin microcontroller.Pin: output pin + :param value bool: default value + :param drive_mode digitalio.DriveMode: drive mode for the output """ def __init__(self, pin, **kwargs): - """ - kwargs will be passed directly to switch_to_output - value (bool): default value to set upon switching - drive_mode (DriveMode): drive mode for the output - """ self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_output(**kwargs) @@ -250,13 +249,12 @@ def value(self, value): class DigitalIn: """ - Simple digital input that is valid until soft reset. + Simple digital input that is valid until reload. + + :param pin microcontroller.Pin: input pin + :param pull digitalio.Pull: pull configuration for the input """ def __init__(self, pin, **kwargs): - """ - kwargs will be passed directly to switch_to_input - pull (pull): pull configuration for the input - """ self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_input(**kwargs) From a5f72b41564aa1d70a9e21c4d82fc8229e37eceb Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 18 May 2018 12:07:13 -0500 Subject: [PATCH 032/131] Remove trailing whitespace --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 6314bd7..7fdb3ab 100644 --- a/simpleio.py +++ b/simpleio.py @@ -229,7 +229,7 @@ def deinit(self): class DigitalOut: """ Simple digital output that is valid until reload. - + :param pin microcontroller.Pin: output pin :param value bool: default value :param drive_mode digitalio.DriveMode: drive mode for the output @@ -250,7 +250,7 @@ def value(self, value): class DigitalIn: """ Simple digital input that is valid until reload. - + :param pin microcontroller.Pin: input pin :param pull digitalio.Pull: pull configuration for the input """ From aabadfb3fd4ad9eb8b64248f6d482c60312b5f19 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 11 Jul 2018 09:44:39 -0500 Subject: [PATCH 033/131] updated CoC Signed-off-by: sommersoft --- CODE_OF_CONDUCT.md | 123 ++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 35 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1617586..a9b258d 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,74 +1,127 @@ -# Contributor Covenant Code of Conduct +# Adafruit Community Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and +contributors and leaders pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. ## Our Standards +We are committed to providing a friendly, safe and welcoming environment for +all. + Examples of behavior that contributes to creating a positive environment include: +* Be kind and courteous to others * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences +* Collaborating with other community members * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable +Project leaders are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. -## Scope +## Moderation -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . -## Enforcement +On the Adafruit Discord, you may send an open message from any channel +to all Community Helpers by tagging @community helpers. You may also send an +open message from any channel, or a direct message to @kattni#1507, +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or +@Andon#8175. -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at support@adafruit.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +Email and direct message reports will be kept confidential. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. \ No newline at end of file From 64ca64827c4485b53b638bca80a6100a4222e579 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 9 Aug 2018 11:48:08 -0400 Subject: [PATCH 034/131] PyPi setup. --- .gitignore | 101 +++++---------------------------------------------- .pylintrc | 2 +- .travis.yml | 38 +++++++++---------- docs/conf.py | 2 +- setup.py | 60 ++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 113 deletions(-) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 0763dc9..55f127b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,95 +1,12 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# IPython Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# dotenv -.env - -# virtualenv -venv/ -ENV/ - -# Spyder project settings -.spyderproject - -# Rope project settings -.ropeproject - -# ReadTheDocs +*.mpy +.idea +__pycache__ _build - +*.pyc +.env build* bundles +*.DS_Store +.eggs +dist +**/*.egg-info \ No newline at end of file diff --git a/.pylintrc b/.pylintrc index 946d694..cb8d23d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -155,7 +155,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis. It # supports qualified module names, as well as Unix pattern matching. -ignored-modules= +ignored-modules=board # Show a hint with possible names when a member name was not found. The aspect # of finding the hint is based on edit distance. diff --git a/.travis.yml b/.travis.yml index 4e400dc..51aa40a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,32 @@ -# This is a common .travis.yml for generating library release zip files for -# CircuitPython library releases using circuitpython-build-tools. -# See https://github.com/adafruit/circuitpython-build-tools for detailed setup -# instructions. - dist: trusty sudo: false language: python python: - - "3.6" - +- '3.6' cache: - pip: true - + pip: true deploy: - provider: releases - api_key: $GITHUB_TOKEN +- provider: releases + api_key: "$GITHUB_TOKEN" file_glob: true - file: $TRAVIS_BUILD_DIR/bundles/* + file: "$TRAVIS_BUILD_DIR/bundles/*" skip_cleanup: true overwrite: true on: tags: true - +- provider: pypi + user: adafruit-travis + on: + tags: true + password: + secure: MY5EqGSyszPWYXv6fw9eZmNBu6cIfi2TVwlBDFNvrRSZS1vJJBiJXv/0sLUpJCryR3Hq5ZdE1D4ZhnSEyQs8YYvJHLDiCD2IiGv2PAwI2HZp5wN5TSg/b5cE/OKaCbUnQ7rP2/rMExcE287uhvSupVminZBJt6ar9G0J+B4UB2LoTCgCQW54ZoMDmLS8N4L9kUtqCPqIapF5qS2XqZI3MRxkHjJSy5VHgcqwB8IhYppT3ETBZbLM4u5peRC99VhSW1Kt84OWWXiRc8U/mmb6Ci4AfYUzkhFubnZCSmXR1WYzgDNd+K+mDgnH/kiRw1SMO8czWQhwmb094LSJPXFsiJhSinXdyUucmtWx/OeNrDspx4sG4nUFjrlBjds56Ei7jhFjIeEpnsuwcRMeBnCvX12NUo7E36lzaI7+mCl/pyt/3NqEOurbkQ2BMdjIdlyHidjVHWlC10+pdqiOJp+WBuC6eHVw/5wyK0723a+5WEJMemh+TqvxX75VQJhs5yJzKbkvvxs447ILODLIW2e4CedTTz0KY6W0uNEaVjlfOtEKcN1EJSZnFdFZ6vUXB4YiXipvMA4OWMHVn8UAJmWNas1uIT3UZtGNZHsT5cYxUuL7EJmcOaMkMgb6S+jOxDAht+IoVwsvB0qdNbq+O5nMt0Tkm31270bRBwPVTUnabgw= install: - - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme - +- pip install -r requirements.txt +- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme +- pip install --force-reinstall pylint==1.9.2 script: - - pylint simpleio.py - - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location . - - cd docs && sphinx-build -E -W -b html . _build/html \ No newline at end of file +- pylint simpleio.py +- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) +- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location + . +- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/docs/conf.py b/docs/conf.py index 6049c27..13b496a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,7 @@ 'sphinx.ext.viewcode', ] -autodoc_mock_imports = ["digitalio", "audioio", "pulseio"] +autodoc_mock_imports = ["pulseio"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7568091 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +"""A setuptools based setup module. + +See: +https://packaging.python.org/en/latest/distributing.html +https://github.com/pypa/sampleproject +""" + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path + +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: + long_description = f.read() + +setup( + name='adafruit-circuitpython-simpleio', + + use_scm_version=True, + setup_requires=['setuptools_scm'], + + description='CircuitPython helper library to simplify hardware interactions.', + long_description=long_description, + long_description_content_type='text/x-rst', + + # The project's main homepage. + url='https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO', + + # Author details + author='Adafruit Industries', + author_email='circuitpython@adafruit.com', + + install_requires=['Adafruit-Blinka'], + + # Choose your license + 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', + ], + + # What does your project relate to? + keywords='adafruit simpleio servo map range bitwrite hardware micropython circuitpython', + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + py_modules=['simpleio'], +) From cf9adf26d9eaaf70031135c9d983e363d3a27594 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 9 Aug 2018 11:50:30 -0400 Subject: [PATCH 035/131] Updated requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8b13789..edf9394 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ - +Adafruit-Blinka From d814f5790451e33db65ac342c0a1483de4a31630 Mon Sep 17 00:00:00 2001 From: Scott Webster Date: Mon, 13 Aug 2018 12:28:18 -0400 Subject: [PATCH 036/131] Make microseconds_to_angle() consistent with simpleio.Servo() - simpleio.Servo() allows for the fine tuning of pulse length via min_pulse and max_pulse but microseconds_to_angle() formerly ignored those values and used hard coded ones. - That would lead to an inaccurate conversion if fine tuning had been used. - This patch makes use of self.min_pulse and self.max_pulse in order to make correct use of any fine tuning specified during object instantiation. --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 7fdb3ab..3b31298 100644 --- a/simpleio.py +++ b/simpleio.py @@ -220,7 +220,7 @@ def angle(self, degrees): def microseconds_to_angle(self, us): #pylint: disable-msg=no-self-use, invalid-name """Converts microseconds to a degree value""" - return map_range(us, 500, 2500, 0, 180) + return map_range(us, self.min_pulse * 1000, self.max_pulse * 1000, 0, 180) def deinit(self): """Detaches servo object from pin, frees pin""" From 6a3393edabed95181df68a2217e31570058c37c7 Mon Sep 17 00:00:00 2001 From: Scott Webster Date: Mon, 13 Aug 2018 16:39:47 -0400 Subject: [PATCH 037/131] Correct unit of time in the Servo class docstring Docstring erroneously stated that units were in microseconds when they were in fact milliseconds. This patch corrects that. --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 3b31298..25149c5 100644 --- a/simpleio.py +++ b/simpleio.py @@ -178,8 +178,8 @@ class Servo: Easy control for hobby (3-wire) servos :param ~microcontroller.Pin pin: PWM pin where the servo is located. - :param int min_pulse: Pulse width (microseconds) corresponding to 0 degrees. - :param int max_pulse: Pulse width (microseconds) corresponding to 180 degrees. + :param int min_pulse: Pulse width (milliseconds) corresponding to 0 degrees. + :param int max_pulse: Pulse width (milliseconds) corresponding to 180 degrees. Example for Metro M0 Express: From 84c015777f627d6347ff77834b835ed425f63b8f Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 15 Aug 2018 15:21:49 -0400 Subject: [PATCH 038/131] removing servo class --- simpleio.py | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/simpleio.py b/simpleio.py index 25149c5..b332c55 100644 --- a/simpleio.py +++ b/simpleio.py @@ -173,59 +173,6 @@ def shift_out(data_pin, clock, value, msb_first=True): clock.value = True clock.value = False -class Servo: - """ - Easy control for hobby (3-wire) servos - - :param ~microcontroller.Pin pin: PWM pin where the servo is located. - :param int min_pulse: Pulse width (milliseconds) corresponding to 0 degrees. - :param int max_pulse: Pulse width (milliseconds) corresponding to 180 degrees. - - Example for Metro M0 Express: - - .. code-block:: python - - import simpleio - import time - from board import * - - pwm = simpleio.Servo(D9) - - while True: - pwm.angle = 0 - print("Angle: ", pwm.angle) - time.sleep(2) - pwm.angle = pwm.microseconds_to_angle(2500) - print("Angle: ", pwm.angle) - time.sleep(2) - """ - def __init__(self, pin, min_pulse=0.5, max_pulse=2.5): - self.pwm = pulseio.PWMOut(pin, frequency=50) - self.min_pulse = min_pulse - self.max_pulse = max_pulse - self._angle = None - - @property - def angle(self): - """Get and set the servo angle in degrees""" - return self._angle - - @angle.setter - def angle(self, degrees): - """Writes a value in degrees to the servo""" - self._angle = max(min(180, degrees), 0) - pulse_width = self.min_pulse + (self._angle / 180) * (self.max_pulse - self.min_pulse) - duty_percent = pulse_width / 20.0 - self.pwm.duty_cycle = int(duty_percent * 65535) - - def microseconds_to_angle(self, us): #pylint: disable-msg=no-self-use, invalid-name - """Converts microseconds to a degree value""" - return map_range(us, self.min_pulse * 1000, self.max_pulse * 1000, 0, 180) - - def deinit(self): - """Detaches servo object from pin, frees pin""" - self.pwm.deinit() - class DigitalOut: """ Simple digital output that is valid until reload. From 8e650c32c95e7611a7dcaa24c172d53f5fe9b218 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 2 Oct 2018 16:16:07 -0700 Subject: [PATCH 039/131] Update simpleio.tone to match 3.x audioio api --- simpleio.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/simpleio.py b/simpleio.py index b332c55..6d3007c 100644 --- a/simpleio.py +++ b/simpleio.py @@ -28,6 +28,7 @@ * Author(s): Scott Shawcroft """ import time +import sys try: import audioio except ImportError: @@ -45,21 +46,34 @@ def tone(pin, frequency, duration=1, length=100): :param int length: Variable size buffer (optional) :param int duration: Duration of tone in seconds (optional) """ + if length * frequency > 350000: + length = 350000 // frequency try: + # pin with PWM with pulseio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) except ValueError: + # pin without PWM sample_length = length square_wave = array.array("H", [0] * sample_length) for i in range(sample_length / 2): square_wave[i] = 0xFFFF - sample_tone = audioio.AudioOut(pin, square_wave) - sample_tone.frequency = int(len(square_wave) * frequency) - if not sample_tone.playing: - sample_tone.play(loop=True) - time.sleep(duration) - sample_tone.stop() + if sys.implementation.version[0] >= 3: + square_wave_sample = audioio.RawSample(square_wave) + square_wave_sample.sample_rate = int(len(square_wave) * frequency) + with audioio.AudioOut(pin) as dac: + if not dac.playing: + dac.play(square_wave_sample, loop=True) + time.sleep(duration) + dac.stop() + else: + sample_tone = audioio.AudioOut(pin, square_wave) + sample_tone.frequency = int(len(square_wave) * frequency) + if not sample_tone.playing: + sample_tone.play(loop=True) + time.sleep(duration) + sample_tone.stop() From 3bceffb0ec460c79a1b88ff60c3846292e472e6c Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 21 Dec 2018 13:11:05 -0600 Subject: [PATCH 040/131] change 'travis-ci.org' to 'travis-ci.com' --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 454148b..9031033 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_SimpleIO.svg?branch=master - :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_SimpleIO +.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_SimpleIO.svg?branch=master + :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_SimpleIO :alt: Build Status SimpleIO features a number of helpers to simplify hardware interactions. Many From 683897d1338b7eafaccbe9972e53d8b1bd5babc5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 6 May 2019 16:27:04 -0400 Subject: [PATCH 041/131] Added library name to example filenames --- examples/{map_range_demo.py => simpleio_map_range_demo.py} | 0 examples/{shift_in_out_demo.py => simpleio_shift_in_out_demo.py} | 0 examples/{tone_demo.py => simpleio_tone_demo.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/{map_range_demo.py => simpleio_map_range_demo.py} (100%) rename examples/{shift_in_out_demo.py => simpleio_shift_in_out_demo.py} (100%) rename examples/{tone_demo.py => simpleio_tone_demo.py} (100%) diff --git a/examples/map_range_demo.py b/examples/simpleio_map_range_demo.py similarity index 100% rename from examples/map_range_demo.py rename to examples/simpleio_map_range_demo.py diff --git a/examples/shift_in_out_demo.py b/examples/simpleio_shift_in_out_demo.py similarity index 100% rename from examples/shift_in_out_demo.py rename to examples/simpleio_shift_in_out_demo.py diff --git a/examples/tone_demo.py b/examples/simpleio_tone_demo.py similarity index 100% rename from examples/tone_demo.py rename to examples/simpleio_tone_demo.py From cd20defd89b6f254efdc101c6c9b6e2c25e1db27 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 6 May 2019 16:51:27 -0400 Subject: [PATCH 042/131] Updated examples.rst to reflect filename changes --- docs/examples.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index c05c623..ca8d565 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,14 +3,14 @@ Simple tests Ensure your device works with these simple tests. -.. literalinclude:: ../examples/tone_demo.py - :caption: examples/tone_demo.py +.. literalinclude:: ../examples/simpleio_tone_demo.py + :caption: examples/simpleio_tone_demo.py :linenos: -.. literalinclude:: ../examples/shift_in_out_demo.py - :caption: examples/shift_in_out_demo.py +.. literalinclude:: ../examples/simpleio_shift_in_out_demo.py + :caption: examples/simpleio_shift_in_out_demo.py :linenos: -.. literalinclude:: ../examples/map_range_demo.py - :caption: examples/map_range_demo.py - :linenos: \ No newline at end of file +.. literalinclude:: ../examples/simpleio_map_range_demo.py + :caption: examples/simpleio_map_range_demo.py + :linenos: From dbf1f1740472213098814cf6607d2b252da71117 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 7 May 2019 09:09:29 -0400 Subject: [PATCH 043/131] Added stuff to make travis pass --- simpleio.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simpleio.py b/simpleio.py index 6d3007c..8b1c3e8 100644 --- a/simpleio.py +++ b/simpleio.py @@ -50,9 +50,11 @@ def tone(pin, frequency, duration=1, length=100): length = 350000 // frequency try: # pin with PWM + #pylint: disable=no-member with pulseio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) + #pylint: enable=no-member except ValueError: # pin without PWM sample_length = length From 791252066a1cc889ef65efd6280cb275930f71c6 Mon Sep 17 00:00:00 2001 From: "Lee A. Butler" Date: Wed, 26 Jun 2019 21:51:18 -0400 Subject: [PATCH 044/131] bitcount argument to shift_out --- simpleio.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/simpleio.py b/simpleio.py index 8b1c3e8..2f349b7 100644 --- a/simpleio.py +++ b/simpleio.py @@ -126,7 +126,7 @@ def shift_in(data_pin, clock, msb_first=True): i += 1 return value -def shift_out(data_pin, clock, value, msb_first=True): +def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): """ Shifts out a byte of data one bit at a time. Data gets written to a data pin. Then, the clock pulses hi then low @@ -138,6 +138,7 @@ def shift_out(data_pin, clock, value, msb_first=True): :param ~digitalio.DigitalInOut clock: toggled once the data pin is set :param bool msb_first: True when the first bit is most significant :param int value: byte to be shifted + :param unsigned bitcount: number of bits to shift Example for Metro M0 Express: @@ -177,14 +178,17 @@ def shift_out(data_pin, clock, value, msb_first=True): latchpin.value = True time.sleep(1.0) """ - value = value&0xFF - for i in range(0, 8): - if msb_first: - tmpval = bool(value & (1 << (7-i))) - data_pin.value = tmpval - else: - tmpval = bool((value & (1 << i))) - data_pin.value = tmpval + if bitcount < 0: + raise ValueError + + if msb_first: + f = lambda : range(bitcount-1, -1, -1) + else: + f = lambda : range(0, bitcount) + + for i in f(): + tmpval = bool(value & (1< Date: Thu, 27 Jun 2019 20:48:53 -0400 Subject: [PATCH 045/131] argument to ValueError exception --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 2f349b7..9583fc0 100644 --- a/simpleio.py +++ b/simpleio.py @@ -179,7 +179,7 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): time.sleep(1.0) """ if bitcount < 0: - raise ValueError + raise ValueError('bitcount must be positive') if msb_first: f = lambda : range(bitcount-1, -1, -1) From 4902915e59b5b78592e6b7f325c42f7ce3ec8ed4 Mon Sep 17 00:00:00 2001 From: BJH Date: Sat, 6 Jul 2019 16:49:23 -0400 Subject: [PATCH 046/131] Gracefully handle in_min == in_max: if input is lower or higher, return out_min or out_max, if input == in_min == in_max, return 50% of the output range; oh, and don't crash --- simpleio.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 8b1c3e8..cfa9b9f 100644 --- a/simpleio.py +++ b/simpleio.py @@ -238,7 +238,16 @@ def map_range(x, in_min, in_max, out_min, out_max): :return: Returns value mapped to new range :rtype: float """ - mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min + in_range = in_max - in_min + in_delta = x - in_min + if in_range != 0: + mapped = in_delta / in_range + elif in_delta != 0: + mapped = in_delta + else: + mapped = .5 + mapped *= out_max - out_min + mapped += out_min if out_min <= out_max: return max(min(mapped, out_max), out_min) return min(max(mapped, out_max), out_min) From dcda5b7593619723ab651c16631c5854f4de5bd7 Mon Sep 17 00:00:00 2001 From: "Lee A. Butler" Date: Sat, 13 Jul 2019 22:18:44 -0400 Subject: [PATCH 047/131] pylint fixes --- simpleio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simpleio.py b/simpleio.py index 9583fc0..0fdc4a9 100644 --- a/simpleio.py +++ b/simpleio.py @@ -182,11 +182,11 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): raise ValueError('bitcount must be positive') if msb_first: - f = lambda : range(bitcount-1, -1, -1) + bitsequence = lambda: range(bitcount-1, -1, -1) else: - f = lambda : range(0, bitcount) + bitsequence = lambda: range(0, bitcount) - for i in f(): + for i in bitsequence(): tmpval = bool(value & (1< Date: Sat, 13 Jul 2019 22:37:34 -0400 Subject: [PATCH 048/131] bitcount 0..32 range --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 0fdc4a9..2e6a094 100644 --- a/simpleio.py +++ b/simpleio.py @@ -178,8 +178,8 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): latchpin.value = True time.sleep(1.0) """ - if bitcount < 0: - raise ValueError('bitcount must be positive') + if bitcount < 0 or bitcount > 32: + raise ValueError('bitcount must be in range 0..32 inclusive') if msb_first: bitsequence = lambda: range(bitcount-1, -1, -1) From 9779fcfda7ee19cabba90fd08757007ac5b35ffc Mon Sep 17 00:00:00 2001 From: "Lee A. Butler" Date: Sat, 13 Jul 2019 22:49:13 -0400 Subject: [PATCH 049/131] delete spaces on empty lines --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 2e6a094..42fca14 100644 --- a/simpleio.py +++ b/simpleio.py @@ -180,12 +180,12 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): """ if bitcount < 0 or bitcount > 32: raise ValueError('bitcount must be in range 0..32 inclusive') - + if msb_first: bitsequence = lambda: range(bitcount-1, -1, -1) else: bitsequence = lambda: range(0, bitcount) - + for i in bitsequence(): tmpval = bool(value & (1< Date: Wed, 11 Sep 2019 17:29:13 -0500 Subject: [PATCH 050/131] tone: Work with 4.x, 5.0; AudioOut and PWMAudioOut .. by creating new private functions for getting the right AudioOut and RawSample objects. INCOMPATIBLE CHANGE: this removes support for CircuitPython versions before 3.x in tone() Testing performed: On CPB, `tone(board.SPEAKER, 440)`. On Metro M4 Express, `tone(board.A0, 440). Both tests were using CircuitPython 5.0.alpha versions. Closes: #45 --- simpleio.py | 58 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/simpleio.py b/simpleio.py index c9a1ade..fb44581 100644 --- a/simpleio.py +++ b/simpleio.py @@ -29,14 +29,44 @@ """ import time import sys -try: - import audioio -except ImportError: - pass # not always supported by every board! import array import digitalio import pulseio +def _AudioOut(pin): + try: + import audioio + except ImportError: + pass + else: + return audioio.AudioOut(pin) + + try: + import audiopwmio + except ImportError: + pass + else: + return audiopwmio.PWMAudioOut(pin) + + raise RuntimeError("AudioOut not available") + +def _RawSample(buffer): + try: + import audiocore + except ImportError: + pass + else: + return audiocore.RawSample(buffer) + + try: + import audioio + except ImportError: + pass + else: + return audioio.RawSample(buffer) + + raise RuntimeError("AudioOut not available") + def tone(pin, frequency, duration=1, length=100): """ Generates a square wave of the specified frequency on a pin @@ -61,21 +91,13 @@ def tone(pin, frequency, duration=1, length=100): square_wave = array.array("H", [0] * sample_length) for i in range(sample_length / 2): square_wave[i] = 0xFFFF - if sys.implementation.version[0] >= 3: - square_wave_sample = audioio.RawSample(square_wave) - square_wave_sample.sample_rate = int(len(square_wave) * frequency) - with audioio.AudioOut(pin) as dac: - if not dac.playing: - dac.play(square_wave_sample, loop=True) - time.sleep(duration) - dac.stop() - else: - sample_tone = audioio.AudioOut(pin, square_wave) - sample_tone.frequency = int(len(square_wave) * frequency) - if not sample_tone.playing: - sample_tone.play(loop=True) + square_wave_sample = _RawSample(square_wave) + square_wave_sample.sample_rate = int(len(square_wave) * frequency) + with _AudioOut(pin) as dac: + if not dac.playing: + dac.play(square_wave_sample, loop=True) time.sleep(duration) - sample_tone.stop() + dac.stop() From 18807c1acc089bb7bb579da4199da8cdb573c466 Mon Sep 17 00:00:00 2001 From: jepler Date: Wed, 11 Sep 2019 17:36:53 -0500 Subject: [PATCH 051/131] pylint: Silence some expected pylint errors These functions are deliberately named with a leading underscore to indicate that they are private functions to the simpleio module. --- simpleio.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simpleio.py b/simpleio.py index fb44581..f8fe8cd 100644 --- a/simpleio.py +++ b/simpleio.py @@ -33,6 +33,7 @@ import digitalio import pulseio +#pylint: disable=invalid-name def _AudioOut(pin): try: import audioio @@ -66,6 +67,7 @@ def _RawSample(buffer): return audioio.RawSample(buffer) raise RuntimeError("AudioOut not available") +#pylint: enable=invalid-name def tone(pin, frequency, duration=1, length=100): """ From 76b86b4277db6d77e460e65c2bcf63a455d57b1a Mon Sep 17 00:00:00 2001 From: jepler Date: Wed, 11 Sep 2019 17:37:09 -0500 Subject: [PATCH 052/131] pylint: remove unneeded import According to pylint, this import is not needed, as `sys` is never referenced --- simpleio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index f8fe8cd..09bf8a4 100644 --- a/simpleio.py +++ b/simpleio.py @@ -28,7 +28,6 @@ * Author(s): Scott Shawcroft """ import time -import sys import array import digitalio import pulseio From 992f6b152ca39783ce87400ea4dd3ea613337f19 Mon Sep 17 00:00:00 2001 From: jepler Date: Wed, 11 Sep 2019 19:19:56 -0500 Subject: [PATCH 053/131] revisions based on review comments from @ladyada --- simpleio.py | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/simpleio.py b/simpleio.py index 09bf8a4..397f8b8 100644 --- a/simpleio.py +++ b/simpleio.py @@ -32,41 +32,18 @@ import digitalio import pulseio -#pylint: disable=invalid-name -def _AudioOut(pin): +try: + from audioio import AudioOut +except ImportError: try: - import audioio + from audiopwmio import PWMAudioOut as AudioOut except ImportError: - pass - else: - return audioio.AudioOut(pin) - - try: - import audiopwmio - except ImportError: - pass - else: - return audiopwmio.PWMAudioOut(pin) - - raise RuntimeError("AudioOut not available") - -def _RawSample(buffer): - try: - import audiocore - except ImportError: - pass - else: - return audiocore.RawSample(buffer) - - try: - import audioio - except ImportError: - pass - else: - return audioio.RawSample(buffer) + pass # not always supported by every board! - raise RuntimeError("AudioOut not available") -#pylint: enable=invalid-name +try: + import audiocore +except ImportError: + import audioio as audiocore def tone(pin, frequency, duration=1, length=100): """ @@ -92,9 +69,9 @@ def tone(pin, frequency, duration=1, length=100): square_wave = array.array("H", [0] * sample_length) for i in range(sample_length / 2): square_wave[i] = 0xFFFF - square_wave_sample = _RawSample(square_wave) + square_wave_sample = audiocore.RawSample(square_wave) square_wave_sample.sample_rate = int(len(square_wave) * frequency) - with _AudioOut(pin) as dac: + with AudioOut(pin) as dac: if not dac.playing: dac.play(square_wave_sample, loop=True) time.sleep(duration) From 9a580b57213a261550ee53fb988b4d1e5f93d583 Mon Sep 17 00:00:00 2001 From: jepler Date: Wed, 11 Sep 2019 20:18:48 -0500 Subject: [PATCH 054/131] Rearrange imports to satisfy linter error `ungrouped-imports` --- simpleio.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/simpleio.py b/simpleio.py index 397f8b8..c5c2ef2 100644 --- a/simpleio.py +++ b/simpleio.py @@ -31,7 +31,10 @@ import array import digitalio import pulseio - +try: + import audiocore +except ImportError: + import audioio as audiocore try: from audioio import AudioOut except ImportError: @@ -40,11 +43,6 @@ except ImportError: pass # not always supported by every board! -try: - import audiocore -except ImportError: - import audioio as audiocore - def tone(pin, frequency, duration=1, length=100): """ Generates a square wave of the specified frequency on a pin From 4bc5cfc5135854557c30bf1a1be328385842bf76 Mon Sep 17 00:00:00 2001 From: jepler Date: Wed, 11 Sep 2019 20:22:30 -0500 Subject: [PATCH 055/131] fix audioio import for boards without it (and docs) --- simpleio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index c5c2ef2..4b66202 100644 --- a/simpleio.py +++ b/simpleio.py @@ -34,7 +34,10 @@ try: import audiocore except ImportError: - import audioio as audiocore + try: + import audioio as audiocore + except ImportError: + pass # not always supported by every board! try: from audioio import AudioOut except ImportError: From 429426bf28102d1b2a1aa46b39ff582fc28b83f8 Mon Sep 17 00:00:00 2001 From: jepler Date: Fri, 13 Sep 2019 20:39:51 -0500 Subject: [PATCH 056/131] Further rearrange audio imports * where possible, check with sys.implementation.version, instead of try/except * reduce overall number of try/except clauses --- simpleio.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/simpleio.py b/simpleio.py index 4b66202..8437dd9 100644 --- a/simpleio.py +++ b/simpleio.py @@ -28,23 +28,23 @@ * Author(s): Scott Shawcroft """ import time +import sys import array import digitalio import pulseio try: - import audiocore -except ImportError: - try: + # RawSample was moved in CircuitPython 5.x. + if sys.implementation.version[0] >= 5: + import audiocore + else: import audioio as audiocore - except ImportError: - pass # not always supported by every board! -try: - from audioio import AudioOut -except ImportError: + # Some boards have AudioOut (true DAC), others have PWMAudioOut. try: - from audiopwmio import PWMAudioOut as AudioOut + from audioio import AudioOut except ImportError: - pass # not always supported by every board! + from audiopwmio import PWMAudioOut as AudioOut +except ImportError: + pass # not always supported by every board! def tone(pin, frequency, duration=1, length=100): """ From f535f0f02675ba101eb5a0979186ecbd086b1503 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 19 Sep 2019 19:57:29 -0400 Subject: [PATCH 057/131] Update repo. Fixes #44. --- README.rst | 3 +-- simpleio.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 9031033..b80335c 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ This driver depends on: Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading -`the Adafruit library and driver bundle `_. +`the Adafruit library and driver bundle `_. Usage Example ============= @@ -86,4 +86,3 @@ Now, once you have the virtual environment activated: This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to locally verify it will pass. - diff --git a/simpleio.py b/simpleio.py index 8437dd9..61d7c04 100644 --- a/simpleio.py +++ b/simpleio.py @@ -46,11 +46,15 @@ except ImportError: pass # not always supported by every board! +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/CircuitPython_SimpleIO.git" + + def tone(pin, frequency, duration=1, length=100): """ Generates a square wave of the specified frequency on a pin - :param ~microcontroller.Pin Pin: Pin on which to output the tone + :param ~microcontroller.Pin pin: Pin on which to output the tone :param float frequency: Frequency of tone in Hz :param int length: Variable size buffer (optional) :param int duration: Duration of tone in seconds (optional) @@ -79,7 +83,6 @@ def tone(pin, frequency, duration=1, length=100): dac.stop() - def bitWrite(x, n, b): #pylint: disable-msg=invalid-name """ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. @@ -97,7 +100,6 @@ def bitWrite(x, n, b): #pylint: disable-msg=invalid-name return x - def shift_in(data_pin, clock, msb_first=True): """ Shifts in a byte of data one bit at a time. Starts from either the LSB or @@ -127,6 +129,7 @@ def shift_in(data_pin, clock, msb_first=True): i += 1 return value + def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): """ Shifts out a byte of data one bit at a time. Data gets written to a data @@ -194,6 +197,7 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): clock.value = True clock.value = False + class DigitalOut: """ Simple digital output that is valid until reload. @@ -215,6 +219,7 @@ def value(self): def value(self, value): self.iopin.value = value + class DigitalIn: """ Simple digital input that is valid until reload. @@ -235,6 +240,7 @@ def value(self): def value(self, value): #pylint: disable-msg=no-self-use, unused-argument raise AttributeError("Cannot set the value on a digital input.") + def map_range(x, in_min, in_max, out_min, out_max): """ Maps a number from one range to another. From 1dd1d2890016fe9dd2c932b6798927c2e755a0de Mon Sep 17 00:00:00 2001 From: Andrea Manzini Date: Wed, 2 Oct 2019 22:15:22 +0200 Subject: [PATCH 058/131] rename example to include simpletest --- docs/examples.rst | 4 ++-- ...eio_map_range_demo.py => simpleio_map_range_simpletest.py} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename examples/{simpleio_map_range_demo.py => simpleio_map_range_simpletest.py} (100%) diff --git a/docs/examples.rst b/docs/examples.rst index ca8d565..61359aa 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -11,6 +11,6 @@ Ensure your device works with these simple tests. :caption: examples/simpleio_shift_in_out_demo.py :linenos: -.. literalinclude:: ../examples/simpleio_map_range_demo.py - :caption: examples/simpleio_map_range_demo.py +.. literalinclude:: ../examples/simpleio_map_range_simpletest.py + :caption: examples/simpleio_map_range_simpletest.py :linenos: diff --git a/examples/simpleio_map_range_demo.py b/examples/simpleio_map_range_simpletest.py similarity index 100% rename from examples/simpleio_map_range_demo.py rename to examples/simpleio_map_range_simpletest.py From 8b0cb14669b1884d9b5a5635eba1d03e8e174895 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Thu, 17 Oct 2019 19:52:17 -0400 Subject: [PATCH 059/131] Removed building locally section from README, replaced with documentation section --- README.rst | 48 +++--------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/README.rst b/README.rst index b80335c..ddcabe0 100644 --- a/README.rst +++ b/README.rst @@ -40,49 +40,7 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -Building locally -================ - -To build this library locally you'll need to install the -`circuitpython-build-tools `_ package. - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install circuitpython-build-tools - -Once installed, make sure you are in the virtual environment: - -.. code-block:: shell - - source .env/bin/activate - -Then run the build: - -.. code-block:: shell - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location . - -Sphinx documentation ------------------------ - -Sphinx is used to build the documentation based on rST files and comments in the code. First, -install dependencies (feel free to reuse the virtual environment from above): - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install Sphinx sphinx-rtd-theme - -Now, once you have the virtual environment activated: - -.. code-block:: shell - - cd docs - sphinx-build -E -W -b html . _build/html +Documentation +============= -This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to -view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. +For information on building library documentation, please check out `this guide `_. From 53c85f8f236e9f9c5a6ba676f8d92bf21f26eb94 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 22 Oct 2019 10:58:42 -0400 Subject: [PATCH 060/131] Added pypi installation instructions --- README.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.rst b/README.rst index ddcabe0..8fe2ce8 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,26 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. +Installing from PyPI +==================== + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. To install for current user: + +.. code-block:: shell + pip3 install adafruit-circuitpython-simpleio +To install system-wide (this may be required in some cases): + +.. code-block:: shell + sudo pip3 install adafruit-circuitpython-simpleio +To install in a virtual environment in your current project: + +.. code-block:: shell + mkdir project-name && cd project-name + python3 -m venv .env + source .env/bin/activate + pip3 install adafruit-circuitpython-simpleio + Usage Example ============= From a09c89f7df66c264a188bb7117bd4d2502cdd250 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 22 Oct 2019 20:15:54 -0400 Subject: [PATCH 061/131] Fixed spacing --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index 8fe2ce8..7b76abc 100644 --- a/README.rst +++ b/README.rst @@ -35,14 +35,19 @@ On supported GNU/Linux systems like the Raspberry Pi, you can install the driver PyPI `_. To install for current user: .. code-block:: shell + pip3 install adafruit-circuitpython-simpleio + To install system-wide (this may be required in some cases): .. code-block:: shell + sudo pip3 install adafruit-circuitpython-simpleio + To install in a virtual environment in your current project: .. code-block:: shell + mkdir project-name && cd project-name python3 -m venv .env source .env/bin/activate From 2eafdaf4177743ced5d41eb845a0e64fed961a7a Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 3 Jan 2020 14:19:33 -0500 Subject: [PATCH 062/131] Moved repository from Travis to GitHub Actions --- .github/workflows/build.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .travis.yml | 32 -------------- README.rst | 4 +- 5 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f0267bf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Library version + run: git describe --dirty --always --tags + - name: PyLint + run: | + pylint $( find . -path './simpleio.py' ) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Build docs + working-directory: docs + run: sphinx-build -E -W -b html . _build/html diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18efb9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Upload Release Assets + # the 'official' actions version does not yet support dynamically + # supplying asset names to upload. @csexton's version chosen based on + # discussion in the issue below, as its the simplest to implement and + # allows for selecting files with a pattern. + # https://github.com/actions/upload-release-asset/issues/4 + #uses: actions/upload-release-asset@v1.0.1 + uses: csexton/release-asset-action@master + with: + pattern: "bundles/*" + github-token: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Set up Python + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + env: + TWINE_USERNAME: ${{ secrets.pypi_username }} + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + python setup.py sdist + twine upload dist/* diff --git a/.gitignore b/.gitignore index 55f127b..c83f8b7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ __pycache__ _build *.pyc .env -build* bundles *.DS_Store .eggs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 51aa40a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -dist: trusty -sudo: false -language: python -python: -- '3.6' -cache: - pip: true -deploy: -- provider: releases - api_key: "$GITHUB_TOKEN" - file_glob: true - file: "$TRAVIS_BUILD_DIR/bundles/*" - skip_cleanup: true - overwrite: true - on: - tags: true -- provider: pypi - user: adafruit-travis - on: - tags: true - password: - secure: MY5EqGSyszPWYXv6fw9eZmNBu6cIfi2TVwlBDFNvrRSZS1vJJBiJXv/0sLUpJCryR3Hq5ZdE1D4ZhnSEyQs8YYvJHLDiCD2IiGv2PAwI2HZp5wN5TSg/b5cE/OKaCbUnQ7rP2/rMExcE287uhvSupVminZBJt6ar9G0J+B4UB2LoTCgCQW54ZoMDmLS8N4L9kUtqCPqIapF5qS2XqZI3MRxkHjJSy5VHgcqwB8IhYppT3ETBZbLM4u5peRC99VhSW1Kt84OWWXiRc8U/mmb6Ci4AfYUzkhFubnZCSmXR1WYzgDNd+K+mDgnH/kiRw1SMO8czWQhwmb094LSJPXFsiJhSinXdyUucmtWx/OeNrDspx4sG4nUFjrlBjds56Ei7jhFjIeEpnsuwcRMeBnCvX12NUo7E36lzaI7+mCl/pyt/3NqEOurbkQ2BMdjIdlyHidjVHWlC10+pdqiOJp+WBuC6eHVw/5wyK0723a+5WEJMemh+TqvxX75VQJhs5yJzKbkvvxs447ILODLIW2e4CedTTz0KY6W0uNEaVjlfOtEKcN1EJSZnFdFZ6vUXB4YiXipvMA4OWMHVn8UAJmWNas1uIT3UZtGNZHsT5cYxUuL7EJmcOaMkMgb6S+jOxDAht+IoVwsvB0qdNbq+O5nMt0Tkm31270bRBwPVTUnabgw= -install: -- pip install -r requirements.txt -- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme -- pip install --force-reinstall pylint==1.9.2 -script: -- pylint simpleio.py -- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) -- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-simpleio --library_location - . -- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 7b76abc..c649364 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_SimpleIO.svg?branch=master - :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_SimpleIO +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/actions/ :alt: Build Status SimpleIO features a number of helpers to simplify hardware interactions. Many From 9edc0e2b4c51aa6b10e1aa46ca2501e11144cb57 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 3 Mar 2020 00:28:48 -0600 Subject: [PATCH 063/131] build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh' Signed-off-by: sommersoft --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0267bf..ca1a0a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,13 @@ jobs: with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci - - name: Install deps + - name: Install dependencies + # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | 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 - name: Library version run: git describe --dirty --always --tags - name: PyLint From 9bea65d6ed12bbddd77b654e6610deea942005ef Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 5 Mar 2020 22:06:59 -0600 Subject: [PATCH 064/131] update pylintrc for black Signed-off-by: sommersoft --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cb8d23d..cd65e95 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From a9ce07600c7a2f597d849ee6fadf56f4277ecf0d Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 13 Mar 2020 13:19:42 -0500 Subject: [PATCH 065/131] update code of conduct --- CODE_OF_CONDUCT.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a9b258d..d79c514 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -34,13 +34,15 @@ Examples of unacceptable behavior by participants include: * Excessive or unwelcome helping; answering outside the scope of the question asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate The goal of the standards and moderation guidelines outlined here is to build -and maintain a respectful community. We ask that you don’t just aim to be +and maintain a respectful community. We ask that you don’t just aim to be "technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and @@ -74,8 +76,8 @@ In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel to all Community Helpers by tagging @community helpers. You may also send an open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or -@Andon#8175. +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, +@Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. @@ -83,7 +85,7 @@ In situations on Discord where the issue is particularly egregious, possibly illegal, requires immediate action, or violates the Discord terms of service, you should also report the message directly to Discord. -These are the steps for upholding our community’s standards of conduct. +These are the steps for upholding our community’s standards of conduct. 1. Any member of the community may report any situation that violates the Adafruit Community Code of Conduct. All reports will be reviewed and @@ -124,4 +126,4 @@ For other projects adopting the Adafruit Community Code of Conduct, please contact the maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider explicitly mentioning your moderation policy or making a copy with your -own moderation policy so as to avoid confusion. \ No newline at end of file +own moderation policy so as to avoid confusion. From 7fe022d68ad86b0af51a89f8dde6ddd73c65c9a6 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 15 Mar 2020 11:49:22 -0500 Subject: [PATCH 066/131] update code of coduct: discord moderation contact section Signed-off-by: sommersoft --- CODE_OF_CONDUCT.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d79c514..134d510 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -74,10 +74,10 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an -open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, -@Mr. Certainly#0472 or @Andon#8175. +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. From fb45955e9ad5659be6ba5c83c9805e5794513af8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 16 Mar 2020 16:30:57 -0400 Subject: [PATCH 067/131] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- .pylintrc | 3 +- docs/conf.py | 110 +++++++++++++--------- examples/simpleio_map_range_simpletest.py | 6 +- examples/simpleio_shift_in_out_demo.py | 4 +- setup.py | 50 +++++----- simpleio.py | 31 +++--- 7 files changed, 111 insertions(+), 95 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca1a0a7..856b828 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/.pylintrc b/.pylintrc index cd65e95..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -119,7 +119,8 @@ spelling-store-unknown-words=no [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO +# notes=FIXME,XXX,TODO +notes=FIXME,XXX [TYPECHECK] diff --git a/docs/conf.py b/docs/conf.py index 13b496a..3cf6a31 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 CircuitPython SimpleIO Library' -copyright = u'2017 Scott Shawcroft' -author = u'Scott Shawcroft' +project = u"Adafruit CircuitPython SimpleIO 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 = 'AdafruitSimpleIOLibrarydoc' +htmlhelp_basename = "AdafruitSimpleIOLibrarydoc" # -- 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, 'AdafruitSimpleIOLibrary.tex', u'Adafruit SimpleIO Library Documentation', - u'Scott Shawcroft', 'manual'), + ( + master_doc, + "AdafruitSimpleIOLibrary.tex", + u"Adafruit SimpleIO Library Documentation", + u"Scott Shawcroft", + "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, 'adafruitSimpleIOlibrary', u'Adafruit SimpleIO Library Documentation', - [author], 1) + ( + master_doc, + "adafruitSimpleIOlibrary", + u"Adafruit SimpleIO 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, 'AdafruitSimpleIOLibrary', u'Adafruit SimpleIO Library Documentation', - author, 'AdafruitSimpleIOLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitSimpleIOLibrary", + u"Adafruit SimpleIO Library Documentation", + author, + "AdafruitSimpleIOLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/simpleio_map_range_simpletest.py b/examples/simpleio_map_range_simpletest.py index 0fcdef5..e19e3bd 100644 --- a/examples/simpleio_map_range_simpletest.py +++ b/examples/simpleio_map_range_simpletest.py @@ -11,12 +11,12 @@ sensor_value = 150 # Map the sensor's range from 0<=sensor_value<=255 to 0<=sensor_value<=1023 - print('original sensor value: ', sensor_value) + print("original sensor value: ", sensor_value) mapped_value = simpleio.map_range(sensor_value, 0, 255, 0, 1023) - print('mapped sensor value: ', mapped_value) + print("mapped sensor value: ", mapped_value) time.sleep(2) # Map the new sensor value back to the old range sensor_value = simpleio.map_range(mapped_value, 0, 1023, 0, 255) - print('original value returned: ', sensor_value) + print("original value returned: ", sensor_value) time.sleep(2) diff --git a/examples/simpleio_shift_in_out_demo.py b/examples/simpleio_shift_in_out_demo.py index 5b6d978..5542f9c 100644 --- a/examples/simpleio_shift_in_out_demo.py +++ b/examples/simpleio_shift_in_out_demo.py @@ -22,7 +22,7 @@ # shifting 256 bits out of data pin latch.value = False data.direction = digitalio.Direction.OUTPUT - print('shifting out...') + print("shifting out...") simpleio.shift_out(data, clk, data_to_send, msb_first=False) latch.value = True time.sleep(3) @@ -30,6 +30,6 @@ # shifting 256 bits into the data pin latch.value = False data.direction = digitalio.Direction.INPUT - print('shifting in...') + print("shifting in...") simpleio.shift_in(data, clk) time.sleep(3) diff --git a/setup.py b/setup.py index 7568091..df1e407 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-simpleio', - + name="adafruit-circuitpython-simpleio", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython helper library to simplify hardware interactions.', + setup_requires=["setuptools_scm"], + description="CircuitPython helper library to simplify hardware interactions.", 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_SimpleIO', - + url="https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka"], # 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 simpleio servo map range bitwrite hardware micropython circuitpython', - + keywords="adafruit simpleio servo map range bitwrite hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['simpleio'], + py_modules=["simpleio"], ) diff --git a/simpleio.py b/simpleio.py index 61d7c04..270f6e2 100644 --- a/simpleio.py +++ b/simpleio.py @@ -32,6 +32,7 @@ import array import digitalio import pulseio + try: # RawSample was moved in CircuitPython 5.x. if sys.implementation.version[0] >= 5: @@ -44,7 +45,7 @@ except ImportError: from audiopwmio import PWMAudioOut as AudioOut except ImportError: - pass # not always supported by every board! + pass # not always supported by every board! __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/CircuitPython_SimpleIO.git" @@ -63,11 +64,13 @@ def tone(pin, frequency, duration=1, length=100): length = 350000 // frequency try: # pin with PWM - #pylint: disable=no-member - with pulseio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: + # pylint: disable=no-member + with pulseio.PWMOut( + pin, frequency=int(frequency), variable_frequency=False + ) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) - #pylint: enable=no-member + # pylint: enable=no-member except ValueError: # pin without PWM sample_length = length @@ -83,7 +86,7 @@ def tone(pin, frequency, duration=1, length=100): dac.stop() -def bitWrite(x, n, b): #pylint: disable-msg=invalid-name +def bitWrite(x, n, b): # pylint: disable-msg=invalid-name """ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. The return value is the original value with the changed bit. @@ -94,7 +97,7 @@ def bitWrite(x, n, b): #pylint: disable-msg=invalid-name :param b: value to write (0 or 1) """ if b == 1: - x |= 1< 32: - raise ValueError('bitcount must be in range 0..32 inclusive') + raise ValueError("bitcount must be in range 0..32 inclusive") if msb_first: - bitsequence = lambda: range(bitcount-1, -1, -1) + bitsequence = lambda: range(bitcount - 1, -1, -1) else: bitsequence = lambda: range(0, bitcount) for i in bitsequence(): - tmpval = bool(value & (1< Date: Tue, 7 Apr 2020 15:02:31 -0500 Subject: [PATCH 068/131] build.yml: add black formatting check Signed-off-by: sommersoft --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 856b828..7ce0cbe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,9 @@ jobs: pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags + - name: Check formatting + run: | + black --check --target-version=py35 . - name: PyLint run: | pylint $( find . -path './simpleio.py' ) From 25682700b2c1b3015effd8773b011d31db699082 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 9 Apr 2020 17:57:36 -0400 Subject: [PATCH 069/131] Black reformatting with Python 3 target. --- docs/conf.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3cf6a31..7990449 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,18 +32,18 @@ master_doc = "index" # General information about the project. -project = u"Adafruit CircuitPython SimpleIO Library" -copyright = u"2017 Scott Shawcroft" -author = u"Scott Shawcroft" +project = "Adafruit CircuitPython SimpleIO Library" +copyright = "2017 Scott Shawcroft" +author = "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 = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0" +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -133,8 +133,8 @@ ( master_doc, "AdafruitSimpleIOLibrary.tex", - u"Adafruit SimpleIO Library Documentation", - u"Scott Shawcroft", + "Adafruit SimpleIO Library Documentation", + "Scott Shawcroft", "manual", ), ] @@ -147,7 +147,7 @@ ( master_doc, "adafruitSimpleIOlibrary", - u"Adafruit SimpleIO Library Documentation", + "Adafruit SimpleIO Library Documentation", [author], 1, ) @@ -162,7 +162,7 @@ ( master_doc, "AdafruitSimpleIOLibrary", - u"Adafruit SimpleIO Library Documentation", + "Adafruit SimpleIO Library Documentation", author, "AdafruitSimpleIOLibrary", "One line description of project.", From fc0ceb01e5c6414acb86f0a89f2345facbece5c4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 8 Jul 2020 16:49:05 -0400 Subject: [PATCH 070/131] Fixed discord invite link --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c649364..07bbb46 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :alt: Documentation Status .. image :: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord .. image:: https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/workflows/Build%20CI/badge.svg From c03fdd6d013247715ef42a8391977f674c51cc7a Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 16:06:47 -0500 Subject: [PATCH 071/131] Added pre-commit-config file Signed-off-by: dherrada --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab5f1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From 40c822de3a8929b9b30f1d48a75761b77c6dd956 Mon Sep 17 00:00:00 2001 From: Patrick <4002194+askpatrickw@users.noreply.github.com> Date: Wed, 27 Jan 2021 00:30:31 +0000 Subject: [PATCH 072/131] fix __repo__ url typo CircuitPython_SimpleIO should be Adafruit_CircuitPython_SimpleIO --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 270f6e2..91050bf 100644 --- a/simpleio.py +++ b/simpleio.py @@ -48,7 +48,7 @@ pass # not always supported by every board! __version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/CircuitPython_SimpleIO.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO.git" def tone(pin, frequency, duration=1, length=100): From 299d82982f74906cade79b52baa5b0103a1cf9c7 Mon Sep 17 00:00:00 2001 From: Dylan Herrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 2 Feb 2021 14:28:43 -0500 Subject: [PATCH 073/131] Moved from pulseio.PWMOut to pwmio.PWMOut --- simpleio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleio.py b/simpleio.py index 91050bf..c284152 100644 --- a/simpleio.py +++ b/simpleio.py @@ -31,7 +31,7 @@ import sys import array import digitalio -import pulseio +import pwmio try: # RawSample was moved in CircuitPython 5.x. @@ -65,7 +65,7 @@ def tone(pin, frequency, duration=1, length=100): try: # pin with PWM # pylint: disable=no-member - with pulseio.PWMOut( + with pwmio.PWMOut( pin, frequency=int(frequency), variable_frequency=False ) as pwm: pwm.duty_cycle = 0x8000 From aef6c69c70dde37cbd9a627ae6efa8130a02e1f2 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 4 Feb 2021 15:42:32 -0500 Subject: [PATCH 074/131] Ran pre-commit, added licenses --- .github/workflows/build.yml | 30 +- .github/workflows/release.yml | 4 + .gitignore | 6 +- .pylintrc | 4 + .readthedocs.yml | 4 + CODE_OF_CONDUCT.md | 14 +- LICENSES/CC-BY-4.0.txt | 324 ++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst | 4 +- README.rst.license | 3 + docs/_static/favicon.ico.license | 3 + docs/api.rst.license | 3 + docs/conf.py | 4 + docs/examples.rst.license | 3 + docs/index.rst.license | 3 + examples/simpleio_map_range_simpletest.py | 3 + examples/simpleio_shift_in_out_demo.py | 3 + examples/simpleio_tone_demo.py | 3 + requirements.txt | 4 + setup.py | 4 + simpleio.py | 23 +- 22 files changed, 456 insertions(+), 32 deletions(-) create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ce0cbe..59baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,36 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | - pylint $( find . -path './simpleio.py' ) + pylint $( find . -path './adafruit*.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: diff --git a/.gitignore b/.gitignore index c83f8b7..9647e71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ @@ -8,4 +12,4 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info diff --git a/.pylintrc b/.pylintrc index d8f0ee8..5c31f66 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst b/README.rst index 07bbb46..dc493bb 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ To install system-wide (this may be required in some cases): .. code-block:: shell sudo pip3 install adafruit-circuitpython-simpleio - + To install in a virtual environment in your current project: .. code-block:: shell @@ -52,7 +52,7 @@ To install in a virtual environment in your current project: python3 -m venv .env source .env/bin/activate pip3 install adafruit-circuitpython-simpleio - + Usage Example ============= diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index 7990449..8d0f724 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/simpleio_map_range_simpletest.py b/examples/simpleio_map_range_simpletest.py index e19e3bd..dd2f72e 100644 --- a/examples/simpleio_map_range_simpletest.py +++ b/examples/simpleio_map_range_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ 'map_range_demo.py'. diff --git a/examples/simpleio_shift_in_out_demo.py b/examples/simpleio_shift_in_out_demo.py index 5542f9c..7a01f79 100644 --- a/examples/simpleio_shift_in_out_demo.py +++ b/examples/simpleio_shift_in_out_demo.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ 'shift_in_out_demo.py'. diff --git a/examples/simpleio_tone_demo.py b/examples/simpleio_tone_demo.py index 60f80be..4c3a8b4 100644 --- a/examples/simpleio_tone_demo.py +++ b/examples/simpleio_tone_demo.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ 'tone_demo.py'. diff --git a/requirements.txt b/requirements.txt index edf9394..17a850d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,5 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + Adafruit-Blinka diff --git a/setup.py b/setup.py index df1e407..742d45f 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: diff --git a/simpleio.py b/simpleio.py index c284152..5aa014c 100644 --- a/simpleio.py +++ b/simpleio.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Scott Shawcroft for Adafruit Industries # -# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + """ `simpleio` - Simple, beginner friendly IO. ================================================= From bd8537e828f0a33e64b9c8acea212b214dfdb4ad Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 4 Feb 2021 15:49:16 -0500 Subject: [PATCH 075/131] Fixed pylint directive --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..3ff6b3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: pre-commit run --all-files - name: PyLint run: | - pylint $( find . -path './adafruit*.py' ) + pylint $( find . -path './simpleio.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . From 9b53bebc520d70f89d44fc989fc493d5036df925 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Feb 2021 16:38:51 -0500 Subject: [PATCH 076/131] Hardcoded Black and REUSE versions Signed-off-by: dherrada --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab5f1c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From 96fff16f76cb8678bd4072dde817789969908d76 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 2 Mar 2021 18:12:43 -0600 Subject: [PATCH 077/131] pylint to precommit --- .github/workflows/build.yml | 4 ---- .pre-commit-config.yaml | 15 +++++++++++++++ .pylintrc | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ff6b3c..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,10 +50,6 @@ jobs: - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './simpleio.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index 5c31f66..9ed669e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -250,7 +250,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 From 390e7971c87517f6624ab6fbb16adc1258446a95 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 19 Mar 2021 13:47:26 -0400 Subject: [PATCH 078/131] "Increase duplicate code check threshold " --- .pylintrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9ed669e..0238b90 100644 --- a/.pylintrc +++ b/.pylintrc @@ -22,8 +22,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. -# jobs=1 -jobs=2 +jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. @@ -253,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 86c2137d90dfeafdfad9b606b8ffd42a45905f2d Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:32:42 -0400 Subject: [PATCH 079/131] Added pull request template Signed-off-by: dherrada --- .../adafruit_circuitpython_pr.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..71ef8f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Thank you for contributing! Before you submit a pull request, please read the following. + +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. From c5018ec6b32a1a9f0478d22474a9fb457b01b530 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:35:18 -0400 Subject: [PATCH 080/131] Added help text and problem matcher Signed-off-by: dherrada --- .github/workflows/build.yml | 2 ++ .github/workflows/failure-help-text.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/failure-help-text.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3baf502..0ab7182 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,3 +71,5 @@ jobs: python setup.py sdist python setup.py bdist_wheel --universal twine check dist/* + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 From dd00c661217143b610903adf52c285cc5c5396a6 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 May 2021 09:54:31 -0400 Subject: [PATCH 081/131] Moved CI to Python 3.7 Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab7182..c4c975d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 + - name: Set up Python 3.7 uses: actions/setup-python@v1 with: - python-version: 3.6 + python-version: 3.7 - name: Versions run: | python3 --version From 1a04fb1b87c58d03ad0827d0e49ee99e9f365b44 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Jun 2021 12:38:13 -0400 Subject: [PATCH 082/131] Moved default branch to main --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dc493bb..9d8f68b 100644 --- a/README.rst +++ b/README.rst @@ -62,7 +62,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Documentation From 9d6d5285a565bf4816a473ff2601445c8062e523 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 083/131] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From 85025e0b15fd15c07c26c888341bddcdbdb223a8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 11:30:51 -0500 Subject: [PATCH 084/131] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index 9d8f68b..81bf554 100644 --- a/README.rst +++ b/README.rst @@ -58,6 +58,11 @@ Usage Example See the examples in the `examples/` folder for usage. +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From 8c7580977184ea0e1ab3e812d9343da55741f2f4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 085/131] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - id: pylint + name: pylint (example code) description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) + description: Run pylint rules on "tests/*.py" files + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index 0238b90..e78bad2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 From 74fc230da5cccbf37260eba36bfa8402a8fdb66a Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 086/131] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e78bad2..cfd1c41 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From ca56187fe7af315130808191b004432fdfdc1b09 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 087/131] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +python: + version: "3.6" + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt From 9c2601c119a9f7b11f7f0630e1ae43fbf036560e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:16:35 -0600 Subject: [PATCH 088/131] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From c541bc32ca841e8554a21def5d32ca687e41c561 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 089/131] First part of patch Signed-off-by: dherrada --- .../PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md | 2 +- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md index 71ef8f8..8de294e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -4,7 +4,7 @@ Thank you for contributing! Before you submit a pull request, please read the following. -Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Set up Python if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 272d225365eed46916390cf1f393dd08bc00b7d4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:17 -0500 Subject: [PATCH 090/131] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 4 ++-- docs/index.rst | 2 +- setup.py | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 81bf554..2988777 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit-circuitpython-simpleio/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/simpleio/en/latest/ + :target: https://docs.circuitpython.org/projects/simpleio/en/latest/ :alt: Documentation Status .. image :: https://img.shields.io/discord/327254708534116352.svg @@ -61,7 +61,7 @@ See the examples in the `examples/` folder for usage. Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index 8d0f724..46eb31f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,8 +23,8 @@ autodoc_mock_imports = ["pulseio"] intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "python": ("https://docs.python.org/3", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index 4124d84..28e5b1a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/setup.py b/setup.py index 742d45f..bc63e8b 100644 --- a/setup.py +++ b/setup.py @@ -45,8 +45,6 @@ "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 simpleio servo map range bitwrite hardware micropython circuitpython", From b670c717ddc84b91c72e711235e3c5cb068b671b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Thu, 10 Feb 2022 10:16:35 -0500 Subject: [PATCH 091/131] Consolidate Documentation sections of README --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 2988777..219ff06 100644 --- a/README.rst +++ b/README.rst @@ -63,14 +63,11 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + Contributing ============ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. - -Documentation -============= - -For information on building library documentation, please check out `this guide `_. From 3d42999ce08f62d12189cbe3b473009de6f60bcd Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 092/131] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From b5ecb28b413ecdbccbf18eedb4eb53ac8fcc2619 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 093/131] Update Black to latest. Signed-off-by: Kattni Rembor --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..7467c1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool From bfa65e806357c1404dea1aae844665514a6997c7 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 21 Apr 2022 15:00:27 -0400 Subject: [PATCH 094/131] Updated gitignore Signed-off-by: evaherrada --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9647e71..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,47 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files *.mpy -.idea + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -bundles + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info + +# IDE-specific files +.idea +.vscode +*~ From ea53565c076c7493a060a6a8139a348380a2d24f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:59:18 -0400 Subject: [PATCH 095/131] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 219ff06..7958b96 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :target: https://docs.circuitpython.org/projects/simpleio/en/latest/ :alt: Documentation Status -.. image :: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 6f1f0eaecf1017c31a3d3605da89204a7a56ac96 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 14:06:22 -0500 Subject: [PATCH 096/131] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 7958b96..675c595 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :target: https://docs.circuitpython.org/projects/simpleio/en/latest/ :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 19972bf0b8e2836d235ff2647339312a43325cac Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:49:44 -0400 Subject: [PATCH 097/131] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7467c1d..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - id: pylint name: pylint (example code) description: Run pylint rules on "examples/*.py" files types: [python] files: "^examples/" args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint name: pylint (test code) description: Run pylint rules on "tests/*.py" files types: [python] files: "^tests/" args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 71b308019cb0f93d8475554322ce5eeacbeb7637 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 098/131] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cfd1c41..f006a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 2e0fdd4f64c05cdd59270d24aea92a42f3ea4ab6 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 099/131] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index f006a4a..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From ac3bd23895001c3a8d9aca1c9c6258bc7d8a6aab Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 100/131] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 46eb31f..a252455 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,7 +54,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From d238fe99e24ea4cdb472f1d8a9c99dd189b0aeca Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:58 -0400 Subject: [PATCH 101/131] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 28e5b1a..9fcc8f9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -29,7 +29,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 240a4852040f12354c72109bc9cc0a4630daa83f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:59:19 -0400 Subject: [PATCH 102/131] Changed .env to .venv in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 675c595..a5c09f8 100644 --- a/README.rst +++ b/README.rst @@ -49,8 +49,8 @@ To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-simpleio Usage Example From 98d9aaf60a06662bb0321dcdb766775540c00a9b Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:01:03 -0400 Subject: [PATCH 103/131] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index a5c09f8..17dba1a 100644 --- a/README.rst +++ b/README.rst @@ -14,6 +14,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/actions/ :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + SimpleIO features a number of helpers to simplify hardware interactions. Many of the functions and classes are inspired by Arduino APIs to make it easier to move to CircuitPython from Arduino. From 248da65116e984f1ea25fe7fd24afe980ccfbc03 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:55 -0400 Subject: [PATCH 104/131] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++------ .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 47 ++++++++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 54 ----------------------------------- 6 files changed, 71 insertions(+), 70 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - name: Pre-commit hooks run: | pre-commit run --all-files @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + pip install --upgrade build twine + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + done; + python -m build twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + done; + python -m build twine upload dist/* diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0750d34 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-simpleio" +description = "CircuitPython helper library to simplify hardware interactions." +version = "0.0.0-auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO"} +keywords = [ + "adafruit", + "simpleio", + "servo", + "map", + "range", + "bitwrite", + "hardware", + "micropython", + "circuitpython", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +py-modules = ["simpleio"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 17a850d..7a984a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/setup.py b/setup.py deleted file mode 100644 index bc63e8b..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -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: - long_description = f.read() - -setup( - name="adafruit-circuitpython-simpleio", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="CircuitPython helper library to simplify hardware interactions.", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka"], - # Choose your license - 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", - ], - # What does your project relate to? - keywords="adafruit simpleio servo map range bitwrite hardware micropython circuitpython", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - py_modules=["simpleio"], -) From 60d9df0ca09b5005ea0c03b94daae854983d79bd Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 105/131] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 0750d34..aa6cc5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From eeb165ca4852fb74d755e9dae451d820ac4863f6 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:16 -0400 Subject: [PATCH 106/131] Update version string --- pyproject.toml | 2 +- simpleio.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index aa6cc5b..cae2801 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-simpleio" description = "CircuitPython helper library to simplify hardware interactions." -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} diff --git a/simpleio.py b/simpleio.py index 5aa014c..5fa48d7 100644 --- a/simpleio.py +++ b/simpleio.py @@ -30,7 +30,7 @@ except ImportError: pass # not always supported by every board! -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO.git" From e4f99815a9d82ba67687676ceb0af747e40e6d07 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:16 -0400 Subject: [PATCH 107/131] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From ee4660eceefb745a442fbb2a133466e072264f4d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:33 -0400 Subject: [PATCH 108/131] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a252455..cc92102 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -37,7 +38,8 @@ # General information about the project. project = "Adafruit CircuitPython SimpleIO Library" -copyright = "2017 Scott Shawcroft" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Scott Shawcroft" author = "Scott Shawcroft" # The version info for the project you're documenting, acts as replacement for From 0a8fcbfc92060eb298ea52d5e88587b37347a0be Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:23 -0400 Subject: [PATCH 109/131] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index cc92102..0d59988 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,8 +38,14 @@ # General information about the project. project = "Adafruit CircuitPython SimpleIO Library" +creation_year = "2017" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Scott Shawcroft" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Scott Shawcroft" author = "Scott Shawcroft" # The version info for the project you're documenting, acts as replacement for From 2453b466fba4d08f84168cae9454d54b68fd5611 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:50 -0400 Subject: [PATCH 110/131] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From b5c9ff1e50dbbd5f522dea809c62e9e2a6c97ea6 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:47:01 -0400 Subject: [PATCH 111/131] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From 8d27b664a7e13904964f8daebe5728e1d56da32e Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:21 -0400 Subject: [PATCH 112/131] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From d57d1087dcc9bd8f3a8b3b428415188697b022f6 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:46 -0400 Subject: [PATCH 113/131] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} From 59b04c1d20b7067ed2b6d0215955432d8f2ae959 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 114/131] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -225,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -257,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -309,21 +284,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 72b5fda9b09e1af00a1b40095084bb9f726e849e Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:11:32 -0500 Subject: [PATCH 115/131] Fix pylint errors --- simpleio.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/simpleio.py b/simpleio.py index 5fa48d7..ca3f7d1 100644 --- a/simpleio.py +++ b/simpleio.py @@ -171,12 +171,9 @@ def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): if bitcount < 0 or bitcount > 32: raise ValueError("bitcount must be in range 0..32 inclusive") - if msb_first: - bitsequence = lambda: range(bitcount - 1, -1, -1) - else: - bitsequence = lambda: range(0, bitcount) + bitsequence = range(bitcount - 1, -1, -1) if msb_first else range(bitcount) - for i in bitsequence(): + for i in bitsequence: tmpval = bool(value & (1 << i)) data_pin.value = tmpval # toggle clock pin True/False From 3364371c789ec67d2f30f1db1a8ed967fddee581 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 116/131] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 252d3d0ea44a9e5d43c91de604f152e7d3099380 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 117/131] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From a61aad7af2b66f960098407e9320507216d559f5 Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:43:09 -0700 Subject: [PATCH 118/131] Adding type annotations. Had to include some math.floor to coerce floats to integers. --- simpleio.py | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/simpleio.py b/simpleio.py index ca3f7d1..a0153fa 100644 --- a/simpleio.py +++ b/simpleio.py @@ -10,9 +10,18 @@ * Author(s): Scott Shawcroft """ -import time -import sys +try: + from typing import Any + + from microcontroller import Pin +except: + pass + import array +import sys +import time +from math import floor + import digitalio import pwmio @@ -34,13 +43,13 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO.git" -def tone(pin, frequency, duration=1, length=100): +def tone(pin: Pin, frequency: float, duration: int = 1, length: float = 100) -> None: """ Generates a square wave of the specified frequency on a pin :param ~microcontroller.Pin pin: Pin on which to output the tone :param float frequency: Frequency of tone in Hz - :param int length: Variable size buffer (optional) + :param float length: Variable size buffer (optional) :param int duration: Duration of tone in seconds (optional) """ if length * frequency > 350000: @@ -48,17 +57,15 @@ def tone(pin, frequency, duration=1, length=100): try: # pin with PWM # pylint: disable=no-member - with pwmio.PWMOut( - pin, frequency=int(frequency), variable_frequency=False - ) as pwm: + with pwmio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) # pylint: enable=no-member except ValueError: # pin without PWM - sample_length = length + sample_length = floor(length) square_wave = array.array("H", [0] * sample_length) - for i in range(sample_length / 2): + for i in range(floor(sample_length / 2)): square_wave[i] = 0xFFFF square_wave_sample = audiocore.RawSample(square_wave) square_wave_sample.sample_rate = int(len(square_wave) * frequency) @@ -69,7 +76,7 @@ def tone(pin, frequency, duration=1, length=100): dac.stop() -def bitWrite(x, n, b): # pylint: disable-msg=invalid-name +def bitWrite(x: int, n: int, b: int) -> int: # pylint: disable-msg=invalid-name """ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. The return value is the original value with the changed bit. @@ -86,7 +93,7 @@ def bitWrite(x, n, b): # pylint: disable-msg=invalid-name return x -def shift_in(data_pin, clock, msb_first=True): +def shift_in(data_pin: digitalio.DigitalInOut, clock: digitalio.DigitalInOut, msb_first: bool = True) -> int: """ Shifts in a byte of data one bit at a time. Starts from either the LSB or MSB. @@ -116,7 +123,13 @@ def shift_in(data_pin, clock, msb_first=True): return value -def shift_out(data_pin, clock, value, msb_first=True, bitcount=8): +def shift_out( + data_pin: digitalio.DigitalInOut, + clock: digitalio.DigitalInOut, + value: int, + msb_first: bool = True, + bitcount: int = 8, +) -> None: """ Shifts out a byte of data one bit at a time. Data gets written to a data pin. Then, the clock pulses hi then low @@ -190,17 +203,17 @@ class DigitalOut: :param drive_mode digitalio.DriveMode: drive mode for the output """ - def __init__(self, pin, **kwargs): + def __init__(self, pin: Pin, **kwargs: Any) -> None: self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_output(**kwargs) @property - def value(self): + def value(self) -> Any: """The digital logic level of the output pin.""" return self.iopin.value @value.setter - def value(self, value): + def value(self, value: bool) -> None: self.iopin.value = value @@ -212,21 +225,21 @@ class DigitalIn: :param pull digitalio.Pull: pull configuration for the input """ - def __init__(self, pin, **kwargs): + def __init__(self, pin: Pin, **kwargs: Any) -> None: self.iopin = digitalio.DigitalInOut(pin) self.iopin.switch_to_input(**kwargs) @property - def value(self): + def value(self) -> Any: """The digital logic level of the input pin.""" return self.iopin.value @value.setter - def value(self, value): # pylint: disable-msg=no-self-use, unused-argument + def value(self, value: Any) -> None: # pylint: disable-msg=no-self-use, unused-argument raise AttributeError("Cannot set the value on a digital input.") -def map_range(x, in_min, in_max, out_min, out_max): +def map_range(x: float, in_min: float, in_max: float, out_min: float, out_max: float) -> float: """ Maps a number from one range to another. Note: This implementation handles values < in_min differently than arduino's map function does. From 4b37794ab9430eae79ef8be566ce1fc534bbfca8 Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:59:37 -0700 Subject: [PATCH 119/131] Changes to fix CI errors on PR --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index a0153fa..c8172e8 100644 --- a/simpleio.py +++ b/simpleio.py @@ -14,7 +14,7 @@ from typing import Any from microcontroller import Pin -except: +except ImportError: pass import array From 5dfe90fb211b2ac869e7bfb996826417124a9d9e Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Mon, 24 Apr 2023 11:09:38 -0700 Subject: [PATCH 120/131] Working on linting errors --- simpleio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index c8172e8..2400929 100644 --- a/simpleio.py +++ b/simpleio.py @@ -93,7 +93,9 @@ def bitWrite(x: int, n: int, b: int) -> int: # pylint: disable-msg=invalid-name return x -def shift_in(data_pin: digitalio.DigitalInOut, clock: digitalio.DigitalInOut, msb_first: bool = True) -> int: +def shift_in( + data_pin: digitalio.DigitalInOut, clock: digitalio.DigitalInOut, msb_first: bool = True +) -> int: """ Shifts in a byte of data one bit at a time. Starts from either the LSB or MSB. From 89d7a06c429e9dd25959bcae5bbd9c89deaefdff Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Mon, 24 Apr 2023 11:32:49 -0700 Subject: [PATCH 121/131] Linting for CI --- simpleio.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/simpleio.py b/simpleio.py index 2400929..aa98db1 100644 --- a/simpleio.py +++ b/simpleio.py @@ -57,7 +57,9 @@ def tone(pin: Pin, frequency: float, duration: int = 1, length: float = 100) -> try: # pin with PWM # pylint: disable=no-member - with pwmio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: + with pwmio.PWMOut( + pin, frequency=int(frequency), variable_frequency=False + ) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) # pylint: enable=no-member @@ -94,7 +96,9 @@ def bitWrite(x: int, n: int, b: int) -> int: # pylint: disable-msg=invalid-name def shift_in( - data_pin: digitalio.DigitalInOut, clock: digitalio.DigitalInOut, msb_first: bool = True + data_pin: digitalio.DigitalInOut, + clock: digitalio.DigitalInOut, + msb_first: bool = True, ) -> int: """ Shifts in a byte of data one bit at a time. Starts from either the LSB or @@ -237,11 +241,13 @@ def value(self) -> Any: return self.iopin.value @value.setter - def value(self, value: Any) -> None: # pylint: disable-msg=no-self-use, unused-argument + def value(self, value: Any) -> None: # pylint: disable=no-self-use, unused-argument raise AttributeError("Cannot set the value on a digital input.") -def map_range(x: float, in_min: float, in_max: float, out_min: float, out_max: float) -> float: +def map_range( + x: float, in_min: float, in_max: float, out_min: float, out_max: float +) -> float: """ Maps a number from one range to another. Note: This implementation handles values < in_min differently than arduino's map function does. From a1ecde6586674db938c57720fcccf2f7a5b4a33d Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Wed, 26 Apr 2023 19:58:41 -0700 Subject: [PATCH 122/131] Making return type changes as requested by review --- simpleio.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/simpleio.py b/simpleio.py index aa98db1..1f5829f 100644 --- a/simpleio.py +++ b/simpleio.py @@ -214,7 +214,7 @@ def __init__(self, pin: Pin, **kwargs: Any) -> None: self.iopin.switch_to_output(**kwargs) @property - def value(self) -> Any: + def value(self) -> bool: """The digital logic level of the output pin.""" return self.iopin.value @@ -236,12 +236,14 @@ def __init__(self, pin: Pin, **kwargs: Any) -> None: self.iopin.switch_to_input(**kwargs) @property - def value(self) -> Any: + def value(self) -> bool: """The digital logic level of the input pin.""" return self.iopin.value @value.setter - def value(self, value: Any) -> None: # pylint: disable=no-self-use, unused-argument + def value( + self, value: bool + ) -> None: # pylint: disable=no-self-use, unused-argument raise AttributeError("Cannot set the value on a digital input.") From 8f24c08ea014e7e20967e8014598c270b169232e Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Wed, 26 Apr 2023 20:06:07 -0700 Subject: [PATCH 123/131] Fixing pylint issue --- simpleio.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/simpleio.py b/simpleio.py index 1f5829f..88cc381 100644 --- a/simpleio.py +++ b/simpleio.py @@ -241,9 +241,7 @@ def value(self) -> bool: return self.iopin.value @value.setter - def value( - self, value: bool - ) -> None: # pylint: disable=no-self-use, unused-argument + def value(self, value: bool) -> None: # pylint: disable=no-self-use raise AttributeError("Cannot set the value on a digital input.") From 409c013966d1813982b06eaf99121284c6041c41 Mon Sep 17 00:00:00 2001 From: Ross Kukard <75049118+RossK1@users.noreply.github.com> Date: Wed, 26 Apr 2023 20:09:51 -0700 Subject: [PATCH 124/131] Fixing black pre-commit --- simpleio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleio.py b/simpleio.py index 88cc381..58f0b81 100644 --- a/simpleio.py +++ b/simpleio.py @@ -241,7 +241,7 @@ def value(self) -> bool: return self.iopin.value @value.setter - def value(self, value: bool) -> None: # pylint: disable=no-self-use + def value(self, value: bool) -> None: # pylint: disable=no-self-use raise AttributeError("Cannot set the value on a digital input.") From 20317088f6e7d2fbbf52496ac1223b24a4aeba29 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 125/131] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From 6897d6ff21132e99111c72b2e60cf1d20223e9bb Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Tue, 23 May 2023 22:25:55 -0400 Subject: [PATCH 126/131] Update .pylintrc, fix jQuery for docs --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index 0d59988..29d378b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From c7272bb0c7defe979a5e024d411d659e91d57b7b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:19:17 -0500 Subject: [PATCH 127/131] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 29d378b..2bbf428 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -94,19 +94,10 @@ # 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" - -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(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_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, From 967a12a68c4b82048cb5efe99847408215188561 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 128/131] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From 6a1a438b0b156cd672d7daf67df3b1bc1b497124 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 129/131] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 2bbf428..1a225bf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -97,7 +97,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_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, From 5770df8b88e66ea0690fa0fb04b16b01f96b6fbd Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 130/131] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From b79d18682f4fe72740c335fb45bd15560b9bb89b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 16 May 2025 19:11:49 +0000 Subject: [PATCH 131/131] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +-- .pylintrc | 399 ---------------------- README.rst | 6 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/simpleio_map_range_simpletest.py | 2 + examples/simpleio_shift_in_out_demo.py | 2 + examples/simpleio_tone_demo.py | 4 +- ruff.toml | 109 ++++++ simpleio.py | 15 +- 11 files changed, 151 insertions(+), 451 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 17dba1a..ea5fb1e 100644 --- a/README.rst +++ b/README.rst @@ -14,9 +14,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO/actions/ :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff SimpleIO features a number of helpers to simplify hardware interactions. Many of the functions and classes are inspired by Arduino APIs to make it easier to diff --git a/docs/api.rst b/docs/api.rst index 67c1b45..315e75b 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,5 +1,8 @@ .. If you created a package, create one automodule per module in the package. +API Reference +############# + .. automodule:: simpleio :members: diff --git a/docs/conf.py b/docs/conf.py index 1a225bf..76d1ee9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -42,9 +40,7 @@ creation_year = "2017" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Scott Shawcroft" author = "Scott Shawcroft" diff --git a/examples/simpleio_map_range_simpletest.py b/examples/simpleio_map_range_simpletest.py index dd2f72e..e03f944 100644 --- a/examples/simpleio_map_range_simpletest.py +++ b/examples/simpleio_map_range_simpletest.py @@ -7,7 +7,9 @@ ================================================= maps a number from one range to another """ + import time + import simpleio while True: diff --git a/examples/simpleio_shift_in_out_demo.py b/examples/simpleio_shift_in_out_demo.py index 7a01f79..f73d727 100644 --- a/examples/simpleio_shift_in_out_demo.py +++ b/examples/simpleio_shift_in_out_demo.py @@ -9,8 +9,10 @@ """ import time + import board import digitalio + import simpleio # set up clock, data, and latch pins diff --git a/examples/simpleio_tone_demo.py b/examples/simpleio_tone_demo.py index 4c3a8b4..ae1c7dd 100644 --- a/examples/simpleio_tone_demo.py +++ b/examples/simpleio_tone_demo.py @@ -7,10 +7,12 @@ ================================================= a short piezo song using tone() """ + import time + import board -import simpleio +import simpleio while True: for f in (262, 294, 330, 349, 392, 440, 494, 523): diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..2e20813 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,109 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import + "PLW2901", # loop var overwrite +] + +[format] +line-ending = "lf" diff --git a/simpleio.py b/simpleio.py index 58f0b81..3a5a488 100644 --- a/simpleio.py +++ b/simpleio.py @@ -10,6 +10,7 @@ * Author(s): Scott Shawcroft """ + try: from typing import Any @@ -56,13 +57,9 @@ def tone(pin: Pin, frequency: float, duration: int = 1, length: float = 100) -> length = 350000 // frequency try: # pin with PWM - # pylint: disable=no-member - with pwmio.PWMOut( - pin, frequency=int(frequency), variable_frequency=False - ) as pwm: + with pwmio.PWMOut(pin, frequency=int(frequency), variable_frequency=False) as pwm: pwm.duty_cycle = 0x8000 time.sleep(duration) - # pylint: enable=no-member except ValueError: # pin without PWM sample_length = floor(length) @@ -78,7 +75,7 @@ def tone(pin: Pin, frequency: float, duration: int = 1, length: float = 100) -> dac.stop() -def bitWrite(x: int, n: int, b: int) -> int: # pylint: disable-msg=invalid-name +def bitWrite(x: int, n: int, b: int) -> int: """ Based on the Arduino bitWrite function, changes a specific bit of a value to 0 or 1. The return value is the original value with the changed bit. @@ -241,13 +238,11 @@ def value(self) -> bool: return self.iopin.value @value.setter - def value(self, value: bool) -> None: # pylint: disable=no-self-use + def value(self, value: bool) -> None: raise AttributeError("Cannot set the value on a digital input.") -def map_range( - x: float, in_min: float, in_max: float, out_min: float, out_max: float -) -> float: +def map_range(x: float, in_min: float, in_max: float, out_min: float, out_max: float) -> float: """ Maps a number from one range to another. Note: This implementation handles values < in_min differently than arduino's map function does.