Skip to content

Commit 09c00a6

Browse files
committed
Move platform guessing to __init__.py
And import appropriate platform-specific module automatically
1 parent 95bf005 commit 09c00a6

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

ev3dev/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
from .core import *
1+
import platform
22
from .version import __version__
33

4+
# -----------------------------------------------------------------------------
5+
# Guess platform we are running on
6+
def current_platform():
7+
machine = platform.machine()
8+
if machine == 'armv5tejl':
9+
return 'ev3'
10+
elif machine == 'armv6l':
11+
return 'brickpi'
12+
else:
13+
return 'unsupported'
14+
15+
if current_platform() == 'brickpi':
16+
from .brickpi import *
17+
else:
18+
# Import ev3 by default, so that it is covered by documentation.
19+
from .ev3 import *

ev3dev/core.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import os
3131
import fnmatch
3232
import numbers
33-
import platform
3433
import fcntl
3534
import array
3635
import mmap
@@ -42,18 +41,6 @@
4241
from subprocess import Popen
4342

4443

45-
# -----------------------------------------------------------------------------
46-
# Guess platform we are running on
47-
def current_platform():
48-
machine = platform.machine()
49-
if machine == 'armv5tejl':
50-
return 'ev3'
51-
elif machine == 'armv6l':
52-
return 'brickpi'
53-
else:
54-
return 'unsupported'
55-
56-
5744
# -----------------------------------------------------------------------------
5845
# Attribute reader/writer with cached file access
5946
class FileCache(object):

0 commit comments

Comments
 (0)