Skip to content

Commit caa01ad

Browse files
authored
Accept unit classes in motor groups (#480)
1 parent ecfbc29 commit caa01ad

File tree

7 files changed

+220
-113
lines changed

7 files changed

+220
-113
lines changed

docs/motors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Most methods which run motors with accept a ``speed`` or ``speed_pct`` argument.
1414

1515
.. autoclass:: SpeedInteger
1616
.. autoclass:: SpeedPercent
17+
.. autoclass:: SpeedNativeUnits
1718
.. autoclass:: SpeedRPS
1819
.. autoclass:: SpeedRPM
1920
.. autoclass:: SpeedDPS

ev3dev2/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def matches(attribute, pattern):
124124
yield f
125125

126126

127+
def library_load_warning_message(library_name, dependent_class):
128+
return 'Import warning: Failed to import "{}". {} will be unusable!'.format(library_name, dependent_class)
129+
127130
class DeviceNotFound(Exception):
128131
pass
129132

ev3dev2/button.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@
3030

3131
import array
3232
import time
33-
import evdev
34-
from . import get_current_platform
33+
import logging
34+
from . import get_current_platform, library_load_warning_message
35+
36+
log = logging.getLogger(__name__)
3537

3638
try:
3739
# This is a linux-specific module.
38-
# It is required by the Button() class, but failure to import it may be
40+
# It is required by the Button class, but failure to import it may be
3941
# safely ignored if one just needs to run API tests on Windows.
4042
import fcntl
4143
except ImportError:
42-
print("WARNING: Failed to import fcntl. Button class will be unuseable!")
44+
log.warning(library_load_warning_message("fcntl", "Button"))
45+
46+
try:
47+
# This is a linux-specific module.
48+
# It is required by the Button class, but failure to import it may be
49+
# safely ignored if one just needs to run API tests on Windows.
50+
import evdev
51+
except ImportError:
52+
log.warning(library_load_warning_message("evdev", "Button"))
4353

4454

4555
# Import the button filenames, this is platform specific

ev3dev2/display.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@
3131
import os
3232
import mmap
3333
import ctypes
34+
import logging
3435
from PIL import Image, ImageDraw
3536
from . import fonts
36-
from . import get_current_platform
37+
from . import get_current_platform, library_load_warning_message
3738
from struct import pack
3839

40+
log = logging.getLogger(__name__)
41+
3942
try:
4043
# This is a linux-specific module.
4144
# It is required by the Display class, but failure to import it may be
4245
# safely ignored if one just needs to run API tests on Windows.
4346
import fcntl
4447
except ImportError:
45-
print("WARNING: Failed to import fcntl. Display class will be unusable!")
48+
log.warning(library_load_warning_message("fcntl", "Display"))
4649

4750
class FbMem(object):
4851

0 commit comments

Comments
 (0)