Skip to content

Commit 6dae7a2

Browse files
committed
ffilib: Initial version of wrapper for ffi module.
1 parent 2c2f610 commit 6dae7a2

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

ffilib/ffilib.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import ffi
3+
4+
_cache = {}
5+
6+
def open(name, maxver=10, extra=()):
7+
try:
8+
return _cache[name]
9+
except KeyError:
10+
pass
11+
def libs():
12+
if sys.platform == "linux":
13+
yield '%s.so' % name
14+
for i in range(maxver, -1, -1):
15+
yield '%s.so.%u' % (name, i)
16+
else:
17+
for ext in ('dylib', 'dll'):
18+
yield '%s.%s' % (name, ext)
19+
for n in extra:
20+
yield n
21+
err = None
22+
for n in libs():
23+
try:
24+
l = ffi.open(n)
25+
_cache[name] = l
26+
return l
27+
except OSError as e:
28+
err = e
29+
raise err

ffilib/metadata.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist_name = ffilib
2+
srctype = micropython-lib
3+
type = module
4+
version = 0.1.0
5+
author = Damien George
6+
desc = MicroPython FFI helper module
7+
long_desc = MicroPython FFI helper module to easily interface with underlying shared libraries

ffilib/setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
# Remove current dir from sys.path, otherwise setuptools will peek up our
3+
# module instead of system.
4+
sys.path.pop(0)
5+
from setuptools import setup
6+
7+
8+
setup(name='micropython-ffilib',
9+
version='0.1.0',
10+
description='MicroPython FFI helper module',
11+
long_description='MicroPython FFI helper module to easily interface with underlying shared libraries',
12+
url='https://github.com/micropython/micropython/issues/405',
13+
author='Damien George',
14+
author_email='[email protected]',
15+
maintainer='MicroPython Developers',
16+
maintainer_email='[email protected]',
17+
license='MIT',
18+
py_modules=['ffilib'])

0 commit comments

Comments
 (0)