From 6dae7a234e92d40a2479fd7e386cf5372ca391f7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 Jun 2015 22:46:08 +0100 Subject: [PATCH] ffilib: Initial version of wrapper for ffi module. --- ffilib/ffilib.py | 29 +++++++++++++++++++++++++++++ ffilib/metadata.txt | 7 +++++++ ffilib/setup.py | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 ffilib/ffilib.py create mode 100644 ffilib/metadata.txt create mode 100644 ffilib/setup.py diff --git a/ffilib/ffilib.py b/ffilib/ffilib.py new file mode 100644 index 00000000..df9222ca --- /dev/null +++ b/ffilib/ffilib.py @@ -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 diff --git a/ffilib/metadata.txt b/ffilib/metadata.txt new file mode 100644 index 00000000..aeaccb0b --- /dev/null +++ b/ffilib/metadata.txt @@ -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 diff --git a/ffilib/setup.py b/ffilib/setup.py new file mode 100644 index 00000000..eb83f4ac --- /dev/null +++ b/ffilib/setup.py @@ -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'])