Skip to content

Instantly share code, notes, and snippets.

@bhavishyagopesh
Last active February 8, 2018 07:22
Show Gist options
  • Save bhavishyagopesh/7d139dc0cbfc22a0778dde7672f04b5b to your computer and use it in GitHub Desktop.
Save bhavishyagopesh/7d139dc0cbfc22a0778dde7672f04b5b to your computer and use it in GitHub Desktop.
Dep_binary
import ctypes
import os
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from commoncode import system
from commoncode import command
from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager
bin_dep_spec = HookspecMarker('bin_dep_plugin')
bin_dep_plugin = HookimplMarker('bin_dep_plugin')
#
# OS/Arch
#
current_os, current_arch = os_arch()
on_windows = current_os == 'win'
on_mac = current_os == 'mac'
on_linux = current_os == 'linux'
on_posix = not on_windows and (on_mac or on_linux)
current_os_arch = '%(current_os)s-%(current_arch)s' % locals()
noarch = 'noarch'
current_os_noarch = '%(current_os)s-%(noarch)s' % locals()
#
# Shared library file extensions
#
if on_windows:
lib_ext = '.dll'
if on_mac:
lib_ext = '.dylib'
if on_linux:
lib_ext = '.so'
@bin_dep_spec
def get_bin_dep(libname):
"""specification for getting lib on various platforms(i.e. os/arch)
"""
pass
@bin_dep_plugin
def get_bin_dep(libname):
"""Implementation of plugin to get path for typecode binaries
"""
data_dir = os.path.join(os.path.dirname(__file__), 'data')
bin_dir = os.path.join(os.path.dirname(__file__), 'bin')
root_dir = command.get_base_dir(bin_dir)[0]
# now command.load_lib(libname, root_dir) can be called
try:
command.load_lib(libname, root_dir)
except ImportError:
lib = ctypes.CDLL(libname+system.lib_ext)
if lib:
return lib
raise ImportError('Failed to load %(libname)s' % locals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment