Module: Rupy::Python

Extended by:
FFI::Library
Defined in:
lib/rupy/python.rb

Overview

This module provides access to the Python C API functions via the Ruby ffi gem. Documentation for these functions may be found [here](docs.python.org/c-api/). Likewise the FFI gem documentation may be found [here](rdoc.info/projects/ffi/ffi).

Defined Under Namespace

Classes: DummyStruct, PyMethodDef, PyObjectStruct

Constant Summary collapse

METH_VARARGS =
0x0001
PY_FILE_INPUT =
257
PY_EVAL_INPUT =
258
PYTHON =
(OPTIONS[:python] or `python -c "import sys; print sys.executable"`.chomp)
PYTHON_VERSION =
`#{PYTHON} -c 'import sys; print "%d.%d" % sys.version_info[:2]'`.chomp
PYTHON_LIB =
find_python_lib

Class Method Summary collapse

Class Method Details

.find_python_libObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rupy/python.rb', line 23

def self.find_python_lib
    python_lib_path = File.join(`#{PYTHON} -c "import sys; print(sys.prefix)"`.chomp,
      "lib", "python#{PYTHON_VERSION}", "config")
    for ext in [ FFI::Platform::LIBSUFFIX, "so", "a", "dll" ]
        lib = File.join(python_lib_path, "libpython#{PYTHON_VERSION}.#{ext}")
        if File.exists?(lib)
            return lib
            break
        end
    end
    return nil
end