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
 Requirements
55
 Requirements
56
 ------------
56
 ------------
57
 
57
 
58
--  Python >= 3.6
58
+-  Python 2.7, 3.6
59
 -  pySerial >= 3.0
59
 -  pySerial >= 3.0
60
+-  aenum >= 2.0 (if using Python < 3.6)

+ 13
- 6
pdbuddy/__init__.py View File

1
 """Python bindings for PD Buddy Sink configuration"""
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
 import serial
12
 import serial
6
 import serial.tools.list_ports
13
 import serial.tools.list_ports
38
             printed as a response to the command.
45
             printed as a response to the command.
39
         """
46
         """
40
         # Send the command
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
         self._port.flush()
49
         self._port.flush()
43
 
50
 
44
         # Read the result
51
         # Read the result
167
         self.i = i
174
         self.i = i
168
 
175
 
169
     def __repr__(self):
176
     def __repr__(self):
170
-        s = type(self).__name__ + "("
177
+        s = self.__class__.__name__ + "("
171
 
178
 
172
         if self.status is not None:
179
         if self.status is not None:
173
             s += "status={}".format(self.status)
180
             s += "status={}".format(self.status)
301
         return cls(status=status, flags=flags, v=v, i=i)
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
     """Status field of a PD Buddy Sink configuration object"""
312
     """Status field of a PD Buddy Sink configuration object"""
306
     EMPTY = 1
313
     EMPTY = 1
307
     VALID = 2
314
     VALID = 2
308
     INVALID = 3
315
     INVALID = 3
309
 
316
 
310
 
317
 
311
-class SinkFlags(Flag):
318
+class SinkFlags(enum.Flag):
312
     """Flags field of a PD Buddy Sink configuration object"""
319
     """Flags field of a PD Buddy Sink configuration object"""
313
     NONE = 0
320
     NONE = 0
314
-    GIVEBACK = auto()
321
+    GIVEBACK = enum.auto()

Loading…
Cancel
Save