pycall 0.1.0.alpha.20170403 → 0.1.0.alpha.20170419

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f71e741e2100584c7f767b479215f6738a1c2766
4
- data.tar.gz: 86c1b2baafb99c7a4252bb24837b9b43ca3dc445
3
+ metadata.gz: 220ffefcf04f5d0eaeed99447b88e9c2df85be7e
4
+ data.tar.gz: 39549ff7df8bbe36cd9004438cb8c663ca150cd8
5
5
  SHA512:
6
- metadata.gz: 16301b5fbff74a7beff8f64a1937a15868edd9666e89219f935d293a6f80f5b1aa9df64619a9a6addd0ef825349262b37aa4f19a7aff73d32a9e47140a879889
7
- data.tar.gz: 1dc51fde23af83ae1dd7a161035f53890e4d52d08bc0ca05daf95d7cc23dc89c0b4a9ca86f687fc52a422fdf8fe269e824017b12be7a89c316cdcf90a04f23ab
6
+ metadata.gz: 3bf207903eda56329bd667660235994698b867d1a00a197da4053b19a0fb20cb98c9721bbd65a47954a1056e1c42f86e81167036de5f75083c23d84d7764f2a4
7
+ data.tar.gz: 97283d06818c407cff5b6fda9e394bf6a85875f7193748ad6a79e85d296a5e26fcd8ae5a84c01bdb52d9ec2905ab50e68c0f37033ebb4c0000f2fa38c6273670
data/lib/pycall/eval.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  module PyCall
2
2
  module Eval
3
+ Py_file_input = 257
3
4
  Py_eval_input = 258
4
5
 
5
- def self.eval(str, filename: "pycall")
6
+ def self.input_type(sym)
7
+ return Py_file_input if sym == :file
8
+ return Py_eval_input if sym == :eval
9
+ raise ArgumentError, "Unknown input_type for compile Python code"
10
+ end
11
+
12
+ def self.eval(str, filename: "pycall", input_type: :eval)
13
+ input_type = self.input_type(input_type)
6
14
  globals_ptr = main_dict.__pyobj__
7
15
  locals_ptr = main_dict.__pyobj__
8
16
  defer_sigint do
9
- py_code_ptr = LibPython.Py_CompileString(str, filename, Py_eval_input)
17
+ py_code_ptr = LibPython.Py_CompileString(str, filename, input_type)
10
18
  raise PyError.fetch if py_code_ptr.null?
11
19
  LibPython.PyEval_EvalCode(py_code_ptr, globals_ptr, locals_ptr)
12
20
  end
@@ -42,8 +50,8 @@ module PyCall
42
50
  end
43
51
  end
44
52
 
45
- def self.eval(str, conversion: true)
46
- result = Eval.eval(str)
53
+ def self.eval(str, conversion: true, filename: "pycall", input_type: :eval)
54
+ result = Eval.eval(str, filename: filename, input_type: input_type)
47
55
  conversion ? result.to_ruby : result
48
56
  end
49
57
  end
@@ -191,7 +191,6 @@ module PyCall
191
191
  attach_function :PyObject_HasAttrString, [PyObjectStruct.by_ref, :string], :int
192
192
  attach_function :PyObject_GetItem, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], PyObjectStruct.by_ref
193
193
  attach_function :PyObject_SetItem, [PyObjectStruct.by_ref, PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
194
- attach_function :PyObject_DelItem, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
195
194
  attach_function :PyObject_Call, [PyObjectStruct.by_ref, PyObjectStruct.by_ref, PyObjectStruct.by_ref], PyObjectStruct.by_ref
196
195
  attach_function :PyObject_IsInstance, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
197
196
  attach_function :PyObject_Dir, [PyObjectStruct.by_ref], PyObjectStruct.by_ref
@@ -280,8 +279,6 @@ module PyCall
280
279
 
281
280
  attach_function :PyList_New, [:ssize_t], PyObjectStruct.by_ref
282
281
  attach_function :PyList_Size, [PyObjectStruct.by_ref], :ssize_t
283
- attach_function :PyList_GetItem, [PyObjectStruct.by_ref, :ssize_t], PyObjectStruct.by_ref
284
- attach_function :PyList_SetItem, [PyObjectStruct.by_ref, :ssize_t, PyObjectStruct.by_ref], :int
285
282
  attach_function :PyList_Append, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
286
283
 
287
284
  # Sequence
@@ -309,8 +306,6 @@ module PyCall
309
306
 
310
307
  attach_function :PySet_Size, [PyObjectStruct.by_ref], :ssize_t
311
308
  attach_function :PySet_Contains, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
312
- attach_function :PySet_Add, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
313
- attach_function :PySet_Discard, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
314
309
 
315
310
  # Module
316
311
 
data/lib/pycall/utils.rb CHANGED
@@ -79,6 +79,13 @@ module PyCall
79
79
  @type.(pyobj)
80
80
  end
81
81
 
82
+ def with(ctx)
83
+ __exit__ = PyCall.getattr(ctx, :__exit__)
84
+ yield PyCall.getattr(ctx,:__enter__).()
85
+ ensure
86
+ __exit__.()
87
+ end
88
+
82
89
  def format_traceback(pyobj)
83
90
  @format_tb ||= import_module('traceback').format_tb
84
91
  @format_tb.(pyobj)
@@ -1,3 +1,3 @@
1
1
  module PyCall
2
- VERSION = "0.1.0.alpha.20170403"
2
+ VERSION = "0.1.0.alpha.20170419"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pycall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.20170403
4
+ version: 0.1.0.alpha.20170419
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi