]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Lint! Untested.
authorScott Shawcroft <scott@tannewt.org>
Wed, 27 Jun 2018 01:29:49 +0000 (18:29 -0700)
committerScott Shawcroft <scott@tannewt.org>
Wed, 27 Jun 2018 01:30:28 +0000 (18:30 -0700)
12 files changed:
examples/index.md [deleted file]
src/adafruit_blinka/__init__.py [changed mode: 0644->0755]
src/adafruit_blinka/agnostic/__init__.py [changed mode: 0644->0755]
src/adafruit_blinka/agnostic/time.py [changed mode: 0644->0755]
src/adafruit_blinka/board/feather_huzzah.py [changed mode: 0644->0755]
src/adafruit_blinka/board/nodemcu.py [changed mode: 0644->0755]
src/adafruit_blinka/board/pyboard.py [changed mode: 0644->0755]
src/adafruit_blinka/microcontroller/esp8266/__init__.py
src/adafruit_blinka/microcontroller/esp8266/pin.py [changed mode: 0644->0755]
src/adafruit_blinka/microcontroller/stm32/pin.py [changed mode: 0644->0755]
src/microcontroller/__init__.py [changed mode: 0644->0755]
src/microcontroller/pin.py [changed mode: 0644->0755]

diff --git a/examples/index.md b/examples/index.md
deleted file mode 100644 (file)
index 184ca33..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-# About Adafruit_Micropython_Blinka
-
-This repository is structured around integration tests rooted at the `test/src`
-directory, intended to test the compatibility layer rooted in `src`. 
-
-The tests offer a procedural way to assert equivalence between 'native' CircuitPython behaviour and behaviour of the **adafruit_blinka** compatibility layer.
-
-The structure of the testing modules permits test suites to be imported and configured selectively on different implementations, platforms and boards (see `adafruit_blinka.agnostic.py` for definitions of these terms).
-
-Automated introspection of the python runtime combines with interactive prompts
-to configure a scenario for testing (e.g. which platform, which board, what is wired to it)
-so the same routines can be carried out on Micropython boards, dual boards running either CircuitPython or Micropython, or dedicated CircuitPython boards.
-
-Typically the tests have first run on a native CircuitPython platform, and are then used to 
-prove equivalence on a Micropython platform running the **adafruit_blinka** compatibility layer.
-
-# Tests so far
-
-Tests of compatible versions of **digitalio**, **board** and **microcontroller** have successfully demonstrated
-the same code running on either platform, setting and getting pin values and using pull.
-
-Tests have also proven compatibility of the following unmodified CircuitPython libraries...
-
-* adafruit_bme280
-* adafruit_mma8451
-* adafruit_gps
-
-...which proves the fundamentals of bitbangio.I2C, busio.I2C and busio.UART
-
-# Example
-
-To take a minimal example, the following should assert the default behaviour of the DigitalInOut 
-constructor, checks the behaviour of switch_to_input/output(), configures a pin as a pull-up button, a pull-down button and an LED.
-
-```python
-from testing import test_module_name
-test_module_name("testing.universal.digitalio")
-```
-
-Or to take a more involved example of constructing a test suite requiring hardware, 
-the following should verify I2C communication with a BME280 module.
-
-```python
-import unittest
-import testing.universal.i2c
-suite = unittest.TestSuite()
-suite.addTest(testing.universal.i2c.TestBME280Interactive)
-runner = unittest.TestRunner()
-runner.run(suite)
-```
-
-
-To prove this on a newly-flashed Feather Huzzah running Micropython 1.9.3, 
-it should be possible (on a posix-compliant platform with adafruit_ampy installed) 
-to `cd test/scripts` then run `./upload_feather_huzzah_micropython_put.sh` to 
-synchronize relevant files to the filesystem of the huzzah, reset the huzzah then 
-connect using `screen /dev/ttyUSB0 115200` before running the above commands.
-
-Micropython hosts require a micropython repository alongside
-the Adafruit_Micropython_Blinka repository. For circuitpython, 
-the repository is expected to be called circuitpython_2.2.3. 
-In each case, the matching version should have been checked out from github
-and `make` needs to have been run in the `mpy-cross` folder. This provides a tool 
-to make bytecode-compiled .mpy versions of all .py files before upload so that 
-tests can be achieved within the limited memory available on many target platforms. 
-
-## Comments
-
-There are reference routines in `test/scripts` like `upload_feather_huzzah_micropython_put.sh` which execute a selective bytecode-compile to .mpy format and an ampy upload for CircuitPython/Micropython on esp8266, or `upload_pyboard_micropython_cp.sh` which selectively bytecode-compiles and synchronizes files with cp to the CIRCUITPY or PYBFLASH disk mount for stm32 and samd21 platforms.
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 08ec27e..8c83305
@@ -27,35 +27,43 @@ class Enum(object):
         """
         for key in dir(cls):
             val = getattr(cls, key)
         """
         for key in dir(cls):
             val = getattr(cls, key)
-            if type(val) is cls:
+            if isinstance(cls, val):
                 yield (key, val)
 
 
 class ContextManaged:
                 yield (key, val)
 
 
 class ContextManaged:
+    """An object that automatically deinitializes hardware with a context manager."""
     def __enter__(self):
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
         self.deinit()
 
     def __enter__(self):
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
         self.deinit()
 
+    def deinit(self):
+        """Free any hardware used by the object."""
+        pass
+
 
 class Lockable(ContextManaged):
 
 class Lockable(ContextManaged):
+    """An object that must be locked to prevent collisions on a microcontroller resource."""
     _locked = False
 
     def try_lock(self):
     _locked = False
 
     def try_lock(self):
+        """Attempt to grab the lock. Return True on success, False if the lock is already taken."""
         if self._locked:
             return False
         if self._locked:
             return False
-        else:
-            self._locked = True
-            return True
+        self._locked = True
+        return True
 
     def unlock(self):
 
     def unlock(self):
+        """Release the lock so others may use the resource."""
         if self._locked:
             self._locked = False
         else:
             raise ValueError("Not locked")
 
 def patch_system():
         if self._locked:
             self._locked = False
         else:
             raise ValueError("Not locked")
 
 def patch_system():
+    """Patch modules that may be different due to the platform."""
     import sys
     from adafruit_blinka.agnostic import time
     import sys
     from adafruit_blinka.agnostic import time
-    sys.modules['time'] = time
\ No newline at end of file
+    sys.modules['time'] = time
old mode 100644 (file)
new mode 100755 (executable)
index 85670bf..8d60cff
@@ -8,10 +8,10 @@ import gc
 import sys
 gc.collect()
 
 import sys
 gc.collect()
 
-try:
-    microcontroller = sys.platform
-except:
-    microcontroller = None
+
+# We intentionally are patching into this namespace as module names so skip the name check.
+# pylint: disable=invalid-name
+microcontroller = sys.platform
 
 board = None
 if microcontroller is not None:
 
 board = None
 if microcontroller is not None:
old mode 100644 (file)
new mode 100755 (executable)
index 078b833..eefaa56
@@ -1,4 +1,10 @@
+"""Platform agnostic time implementation"""
+
 from adafruit_blinka import agnostic
 from adafruit_blinka import agnostic
+
+# We intentionally are patching into this namespace so skip the wildcard check.
+# pylint: disable=unused-wildcard-import,wildcard-import
+
 if agnostic.implementation == "circuitpython":
     from time import *
 elif agnostic.implementation == "micropython":
 if agnostic.implementation == "circuitpython":
     from time import *
 elif agnostic.implementation == "micropython":
@@ -6,22 +12,29 @@ elif agnostic.implementation == "micropython":
     from utime import sleep
 
     from ucollections import namedtuple
     from utime import sleep
 
     from ucollections import namedtuple
-    _struct_time = namedtuple("struct_time", ("tm_year", "tm_mon", "tm_mday", "tm_hour", "tm_min", "tm_sec", "tm_wday", "tm_yday", "tm_isdst"))
+    _struct_time = namedtuple("struct_time", ("tm_year", "tm_mon", "tm_mday",
+                                              "tm_hour", "tm_min", "tm_sec",
+                                              "tm_wday", "tm_yday", "tm_isdst"))
 
 
-    def marshal_time(tm_year, tm_mon, tm_mday, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=-1, tm_yday=-1, tm_isdst=-1):
+    #pylint: disable=too-many-arguments
+    def _marshal_time(tm_year, tm_mon, tm_mday, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=-1,
+                      tm_yday=-1, tm_isdst=-1):
+        """Construct struct_time with default values."""
         _struct_time(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
 
         _struct_time(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
 
-    def struct_time(t):
-        return marshal_time(*t)
+    def struct_time(time_tuple):
+        """Create a struct_time"""
+        return _marshal_time(*time_tuple)
 
 
-    total_ms = 0
-    prev_ticks_ms = utime.ticks_ms()
+    #pylint: disable=invalid-name
+    _total_ms = 0
+    _prev_ticks_ms = utime.ticks_ms()
     def monotonic():
     def monotonic():
-        """
-        Assumes that monotonic is called more frequently than the wraparound of micropython's utime.ticks_ms()
-        """
-        global prev_ticks_ms, total_ms
+        """A monotonically increasing time in seconds. No defined start time."""
+        # Assumes that monotonic is called more frequently than the wraparound of micropython's
+        # utime.ticks_ms()
+        global _prev_ticks_ms, _total_ms #pylint: disable=global-statement
         ticks_ms = utime.ticks_ms()
         ticks_ms = utime.ticks_ms()
-        total_ms += utime.ticks_diff(ticks_ms, prev_ticks_ms)
-        prev_ticks_ms = ticks_ms
-        return total_ms * 0.001
\ No newline at end of file
+        _total_ms += utime.ticks_diff(ticks_ms, _prev_ticks_ms)
+        _prev_ticks_ms = ticks_ms
+        return _total_ms * 0.001
old mode 100644 (file)
new mode 100755 (executable)
index 60dd863..f02f647
@@ -1,6 +1,9 @@
+"""Feather Huzzah pin names"""
+
 from adafruit_blinka.microcontroller.esp8266 import pin
 
 from adafruit_blinka.microcontroller.esp8266 import pin
 
-# TODO need equiv of INPUT_PULL_DOWN_16 ? see https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html
+# TODO need equiv of INPUT_PULL_DOWN_16 ?
+# See https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html
 
 GPIO0 = pin.GPIO0
 GPIO1 = pin.GPIO1
 
 GPIO0 = pin.GPIO0
 GPIO1 = pin.GPIO1
@@ -24,4 +27,4 @@ RX = GPIO3
 TX = GPIO1
 
 SDA = GPIO4
 TX = GPIO1
 
 SDA = GPIO4
-SCL = GPIO5
\ No newline at end of file
+SCL = GPIO5
old mode 100644 (file)
new mode 100755 (executable)
index 83e4ca8..256e836
@@ -1,3 +1,5 @@
+"""NodeMCU pin names"""
+
 from adafruit_blinka.microcontroller.esp8266 import pin
 
 D0 = pin.GPIO16
 from adafruit_blinka.microcontroller.esp8266 import pin
 
 D0 = pin.GPIO16
@@ -26,4 +28,4 @@ RX0 = D9
 TX0 = D10
 
 # GPIO0 and GPIO2 have built-in pull-ups on common ESP8266
 TX0 = D10
 
 # GPIO0 and GPIO2 have built-in pull-ups on common ESP8266
-# breakout boards making them suitable for I2C SDA and SCL
\ No newline at end of file
+# breakout boards making them suitable for I2C SDA and SCL
old mode 100644 (file)
new mode 100755 (executable)
index 4bf49de..4c5eb10
@@ -1,3 +1,5 @@
+"""PyBoard pin names"""
+
 from adafruit_blinka.microcontroller.stm32 import pin
 
 X1 = pin.A0
 from adafruit_blinka.microcontroller.stm32 import pin
 
 X1 = pin.A0
old mode 100644 (file)
new mode 100755 (executable)
index c37e053..986b968
@@ -1,3 +1,5 @@
+"""ESP8266 pin names"""
+
 from microcontroller import Pin
 
 GPIO0 = Pin(0)
 from microcontroller import Pin
 
 GPIO0 = Pin(0)
@@ -14,12 +16,13 @@ GPIO16 = Pin(16)
 TOUT = Pin("TOUT")
 
 # ordered as spiId, sckId, mosiId, misoId
 TOUT = Pin("TOUT")
 
 # ordered as spiId, sckId, mosiId, misoId
-spiPorts = ((1, GPIO14, GPIO13, GPIO12))
+SPI_PORTS = ((1, GPIO14, GPIO13, GPIO12))
 
 # ordered as uartId, txId, rxId
 
 # ordered as uartId, txId, rxId
-uartPorts = (
+UART_PORTS = (
     (0, GPIO1, GPIO3),
     (0, GPIO1, GPIO3),
-    # (0, GPIO15, GPIO13) # TODO secondary pins for UART0 configurable from Micropython? How to flag?
+    # TODO secondary pins for UART0 configurable from Micropython? How to flag?
+    # (0, GPIO15, GPIO13)
     (1, GPIO2, None))
 
     (1, GPIO2, None))
 
-i2cPorts = ()
\ No newline at end of file
+I2C_PORTS = ()
old mode 100644 (file)
new mode 100755 (executable)
index 3f46781..870e240
@@ -1,3 +1,5 @@
+"""STM32 pins"""
+
 from microcontroller import Pin
 
 A0 = Pin('A0')
 from microcontroller import Pin
 
 A0 = Pin('A0')
@@ -49,10 +51,10 @@ C13 = Pin('C13')
 D2 = Pin('D2')
 
 # ordered as spiId, sckId, mosiId, misoId
 D2 = Pin('D2')
 
 # ordered as spiId, sckId, mosiId, misoId
-spiPorts = ((1, B13, B15, B14), (2, A5, A6, A7))
+SPI_PORTS = ((1, B13, B15, B14), (2, A5, A6, A7))
 
 # ordered as uartId, txId, rxId
 
 # ordered as uartId, txId, rxId
-uartPorts = (
+UART_PORTS = (
     (1, B6, B7),
     (2, A2, A3),
     (3, B10, B11),
     (1, B6, B7),
     (2, A2, A3),
     (3, B10, B11),
@@ -60,8 +62,7 @@ uartPorts = (
     (6, C6, C7),
 )
 
     (6, C6, C7),
 )
 
-i2cPorts = (
+I2C_PORTS = (
     (1, B6, B7),
     (2, B10, B11),
 )
     (1, B6, B7),
     (2, B10, B11),
 )
-
old mode 100644 (file)
new mode 100755 (executable)
index c1b0027..5957a91
@@ -1,10 +1,12 @@
-from adafruit_blinka import Enum, agnostic
+"""Microcontroller pins"""
 
 
+from adafruit_blinka import Enum, agnostic
 
 class Pin(Enum):
 
 class Pin(Enum):
-    def __init__(self, id):
+    """Reference Pin object"""
+    def __init__(self, pin_id):
         """Identifier for pin, referencing platform-specific pin id"""
         """Identifier for pin, referencing platform-specific pin id"""
-        self.id = id
+        self._id = pin_id
 
     def __repr__(self):
         import board
 
     def __repr__(self):
         import board
@@ -17,10 +19,12 @@ class Pin(Enum):
                 return "microcontroller.pin.{}".format(key)
         return repr(self)
 
                 return "microcontroller.pin.{}".format(key)
         return repr(self)
 
+# We intentionally are patching into this namespace so skip the wildcard check.
+# pylint: disable=unused-wildcard-import,wildcard-import
 
 if agnostic.microcontroller == "esp8266":
     from adafruit_blinka.microcontroller.esp8266 import *
 elif agnostic.microcontroller == "stm32":
     from adafruit_blinka.microcontroller.stm32 import *
 else:
 
 if agnostic.microcontroller == "esp8266":
     from adafruit_blinka.microcontroller.esp8266 import *
 elif agnostic.microcontroller == "stm32":
     from adafruit_blinka.microcontroller.stm32 import *
 else:
-    raise NotImplementedError("Microcontroller not supported")
\ No newline at end of file
+    raise NotImplementedError("Microcontroller not supported")
old mode 100644 (file)
new mode 100755 (executable)
index 2b6199b..2109544
@@ -1,8 +1,13 @@
+"""Pins named after their chip name."""
+
 from adafruit_blinka import agnostic
 
 from adafruit_blinka import agnostic
 
+# We intentionally are patching into this namespace so skip the wildcard check.
+# pylint: disable=unused-wildcard-import,wildcard-import
+
 if agnostic.microcontroller == "esp8266":
     from adafruit_blinka.microcontroller.esp8266.pin import *
 elif agnostic.microcontroller == "stm32":
     from adafruit_blinka.microcontroller.stm32.pin import *
 else:
 if agnostic.microcontroller == "esp8266":
     from adafruit_blinka.microcontroller.esp8266.pin import *
 elif agnostic.microcontroller == "stm32":
     from adafruit_blinka.microcontroller.stm32.pin import *
 else:
-    raise NotImplementedError("Microcontroller not supported")
\ No newline at end of file
+    raise NotImplementedError("Microcontroller not supported")