lib/pycall/utils.rb in pycall-0.1.0.alpha.20170302 vs lib/pycall/utils.rb in pycall-0.1.0.alpha.20170307
- old
+ new
@@ -1,7 +1,12 @@
module PyCall
module Utils
+ def append_sys_path(path_str)
+ pyobj = LibPython.PyUnicode_DecodeUTF8(path_str, path_str.bytesize, nil)
+ sys.path.append.(pyobj)
+ end
+
def callable?(pyobj)
case pyobj
when PyObject
when PyTypeObject
pyobj = PyObject.new(pyobj.to_ptr)
@@ -17,26 +22,45 @@
value = LibPython.PyObject_Dir(pyobj)
return value.to_ruby unless value.null?
raise PyError.fetch
end
+ def incref(pyobj)
+ LibPython.Py_IncRef(pyobj)
+ pyobj
+ end
+
+ def decref(pyobj)
+ LibPython.Py_DecRef(pyobj)
+ pyobj.send :pointer=, FFI::Pointer::NULL
+ pyobj
+ end
+
def int(pyobj)
@int ||= PyCall.eval('int')
@int.(pyobj)
end
def len(pyobj)
@len ||= PyCall.eval('len')
@len.(pyobj)
end
+ def None
+ LibPython.Py_None
+ end
+
def slice(*args)
Slice.new(*args)
end
def str(pyobj)
@str ||= PyCall.eval('str')
@str.(pyobj)
+ end
+
+ def sys
+ @sys ||= PyCall.import_module('sys')
end
def tuple(*args)
PyCall::Tuple[*args]
end