Browse Source

Support Python 2.7

One extra dependency is pulled in for Python versions older than 3.6,
but other than that it's pretty easy to support them.  It definitely
works on 2.7 now, and should work on older 3.x versions (but that's
untested).
Clara Hobbs 7 years ago
parent
commit
e1e7b4f726
2 changed files with 15 additions and 7 deletions
  1. 2
    1
      README.rst
  2. 13
    6
      pdbuddy/__init__.py

+ 2
- 1
README.rst View File

@@ -55,5 +55,6 @@ Write the SinkConfig object to flash
55 55
 Requirements
56 56
 ------------
57 57
 
58
--  Python >= 3.6
58
+-  Python 2.7, 3.6
59 59
 -  pySerial >= 3.0
60
+-  aenum >= 2.0 (if using Python < 3.6)

+ 13
- 6
pdbuddy/__init__.py View File

@@ -1,6 +1,13 @@
1 1
 """Python bindings for PD Buddy Sink configuration"""
2 2
 
3
-from enum import *
3
+try:
4
+    # Try importing enum from the standard library
5
+    import enum
6
+    # Make sure Flag is available
7
+    enum.Flag
8
+except (ImportError, NameError):
9
+    # If something above failed, try aenum instead
10
+    import aenum as enum
4 11
 
5 12
 import serial
6 13
 import serial.tools.list_ports
@@ -38,7 +45,7 @@ class Sink:
38 45
             printed as a response to the command.
39 46
         """
40 47
         # Send the command
41
-        self._port.write(bytes(cmd, "utf-8") + b"\r\n")
48
+        self._port.write(cmd.encode("utf-8") + b"\r\n")
42 49
         self._port.flush()
43 50
 
44 51
         # Read the result
@@ -167,7 +174,7 @@ class SinkConfig:
167 174
         self.i = i
168 175
 
169 176
     def __repr__(self):
170
-        s = type(self).__name__ + "("
177
+        s = self.__class__.__name__ + "("
171 178
 
172 179
         if self.status is not None:
173 180
             s += "status={}".format(self.status)
@@ -301,14 +308,14 @@ class SinkConfig:
301 308
         return cls(status=status, flags=flags, v=v, i=i)
302 309
 
303 310
 
304
-class SinkStatus(Enum):
311
+class SinkStatus(enum.Enum):
305 312
     """Status field of a PD Buddy Sink configuration object"""
306 313
     EMPTY = 1
307 314
     VALID = 2
308 315
     INVALID = 3
309 316
 
310 317
 
311
-class SinkFlags(Flag):
318
+class SinkFlags(enum.Flag):
312 319
     """Flags field of a PD Buddy Sink configuration object"""
313 320
     NONE = 0
314
-    GIVEBACK = auto()
321
+    GIVEBACK = enum.auto()

Loading…
Cancel
Save