Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ffilib/ffilib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
import ffi

_cache = {}

def open(name, maxver=10, extra=()):
try:
return _cache[name]
except KeyError:
pass
def libs():
if sys.platform == "linux":
yield '%s.so' % name
for i in range(maxver, -1, -1):
yield '%s.so.%u' % (name, i)
else:
for ext in ('dylib', 'dll'):
yield '%s.%s' % (name, ext)
for n in extra:
yield n
err = None
for n in libs():
try:
l = ffi.open(n)
_cache[name] = l
return l
except OSError as e:
err = e
raise err
7 changes: 7 additions & 0 deletions ffilib/metadata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist_name = ffilib
srctype = micropython-lib
type = module
version = 0.1.0
author = Damien George
desc = MicroPython FFI helper module
long_desc = MicroPython FFI helper module to easily interface with underlying shared libraries
18 changes: 18 additions & 0 deletions ffilib/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
# Remove current dir from sys.path, otherwise setuptools will peek up our
# module instead of system.
sys.path.pop(0)
from setuptools import setup


setup(name='micropython-ffilib',
version='0.1.0',
description='MicroPython FFI helper module',
long_description='MicroPython FFI helper module to easily interface with underlying shared libraries',
url='https://github.com/micropython/micropython/issues/405',
author='Damien George',
author_email='micro-python@googlegroups.com',
maintainer='MicroPython Developers',
maintainer_email='micro-python@googlegroups.com',
license='MIT',
py_modules=['ffilib'])