pycall 0.1.0.alpha.20170226 → 0.1.0.alpha.20170302

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: ab504049d683e34fa1e325340601d6577a40cd5e
4
- data.tar.gz: c477cf5937dd0499e50512a4829ad3688d8e34e5
3
+ metadata.gz: f8c5abd1327e908691a79a42fdc536826e48d208
4
+ data.tar.gz: 4dd793ea028f6b9e47c9e74266d043de5751a74a
5
5
  SHA512:
6
- metadata.gz: 041fda79cb71ccb7653e442c1831f97b489058adb48159cef581d49174182350047e736192eb5568c6d2c4b61d6e2691e917ccb28f578c2dd5b340d90dca41d3
7
- data.tar.gz: eb6af8382a0531729aa8ac151d0880e1c7c613441550490fad77e924b26012723833b5ea1aaab75e6ef9a9f1d9d4e99e416ac4c244c155f7c5a2f7b42c4c5d3c
6
+ metadata.gz: 6a75c2f1a5df62a881f8eee78fc72f5896bbc30d912610afc4f7b6bc719b43015cdddd03f87b6202a5ab782c4a182fd6fef181923e270cd1299bc9b738ff2709
7
+ data.tar.gz: 6fa5f34b243181d4340c3c265eb3c68b430c971976ba8a2ee8649d77a3df5ce547afa69b86d9e253cca7eb801f06e78647bc39ab2343198ebfb667f5e78f1a23
data/.travis.yml CHANGED
@@ -2,10 +2,15 @@ sudo: false
2
2
  language: ruby
3
3
 
4
4
  rvm:
5
- - 2.1.10
6
- - 2.2.5
7
- - 2.3.1
8
5
  - ruby-head
6
+ - 2.4.0
7
+ - 2.3.1
8
+ - 2.2.5
9
+ - 2.1.10
10
+
11
+ env:
12
+ - PYTHON=python
13
+ - PYTHON=python3
9
14
 
10
15
  addons:
11
16
  apt:
@@ -152,6 +152,7 @@ module PyCall
152
152
  attach_function :PyObject_Repr, [PyObject.by_ref], PyObject.by_ref
153
153
  attach_function :PyObject_Str, [PyObject.by_ref], PyObject.by_ref
154
154
  attach_function :PyObject_Type, [PyObject.by_ref], PyTypeObject.by_ref
155
+ attach_function :PyCallable_Check, [PyObject.by_ref], :int
155
156
 
156
157
  # Bool
157
158
 
@@ -203,9 +204,9 @@ module PyCall
203
204
  when libpython.find_symbol('PyUnicode_DecodeUTF8')
204
205
  attach_function :PyUnicode_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
205
206
  when libpython.find_symbol('PyUnicodeUCS4_DecodeUTF8')
206
- attach_function :PyUnicodeUCS4_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
207
+ attach_function :PyUnicode_DecodeUTF8, :PyUnicodeUCS4_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
207
208
  when libpython.find_symbol('PyUnicodeUCS2_DecodeUTF8')
208
- attach_function :PyUnicodeUCS2_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
209
+ attach_function :PyUnicode_DecodeUTF8, :PyUnicodeUCS2_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
209
210
  end
210
211
 
211
212
  # PyUnicode_AsUTF8String
@@ -279,6 +280,7 @@ module PyCall
279
280
  attach_function :PyNumber_Subtract, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
280
281
  attach_function :PyNumber_Multiply, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
281
282
  attach_function :PyNumber_TrueDivide, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
283
+ attach_function :PyNumber_Power, [PyObject.by_ref, PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
282
284
 
283
285
  # Compiler
284
286
 
@@ -78,29 +78,40 @@ module PyCall
78
78
  end
79
79
 
80
80
  def +(other)
81
+ other = Conversions.from_ruby(other)
81
82
  value = LibPython.PyNumber_Add(self, other)
82
83
  return value.to_ruby unless value.null?
83
84
  raise PyError.fetch
84
85
  end
85
86
 
86
87
  def -(other)
88
+ other = Conversions.from_ruby(other)
87
89
  value = LibPython.PyNumber_Subtract(self, other)
88
90
  return value.to_ruby unless value.null?
89
91
  raise PyError.fetch
90
92
  end
91
93
 
92
94
  def *(other)
95
+ other = Conversions.from_ruby(other)
93
96
  value = LibPython.PyNumber_Multiply(self, other)
94
97
  return value.to_ruby unless value.null?
95
98
  raise PyError.fetch
96
99
  end
97
100
 
98
101
  def /(other)
102
+ other = Conversions.from_ruby(other)
99
103
  value = LibPython.PyNumber_TrueDivide(self, other)
100
104
  return value.to_ruby unless value.null?
101
105
  raise PyError.fetch
102
106
  end
103
107
 
108
+ def **(other)
109
+ other = Conversions.from_ruby(other)
110
+ value = LibPython.PyNumber_Power(self, other, LibPython.Py_None)
111
+ return value.to_ruby unless value.null?
112
+ raise PyError.fetch
113
+ end
114
+
104
115
  def coerce(other)
105
116
  [Conversions.from_ruby(other), self]
106
117
  end
@@ -135,6 +146,10 @@ module PyCall
135
146
  end
136
147
 
137
148
  alias inspect to_s
149
+
150
+ def type
151
+ LibPython.PyObject_Type(self)
152
+ end
138
153
  end
139
154
 
140
155
  class PyTypeObject < FFI::Struct
data/lib/pycall/utils.rb CHANGED
@@ -1,5 +1,18 @@
1
1
  module PyCall
2
2
  module Utils
3
+ def callable?(pyobj)
4
+ case pyobj
5
+ when PyObject
6
+ when PyTypeObject
7
+ pyobj = PyObject.new(pyobj.to_ptr)
8
+ when PyObjectWrapper
9
+ pyobj = pyobj.__pyobj__
10
+ else
11
+ raise TypeError, "the argument must be a PyObject"
12
+ end
13
+ 1 == LibPython.PyCallable_Check(pyobj)
14
+ end
15
+
3
16
  def dir(pyobj)
4
17
  value = LibPython.PyObject_Dir(pyobj)
5
18
  return value.to_ruby unless value.null?
@@ -1,3 +1,3 @@
1
1
  module PyCall
2
- VERSION = "0.1.0.alpha.20170226"
2
+ VERSION = "0.1.0.alpha.20170302"
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.20170226
4
+ version: 0.1.0.alpha.20170302
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-02-27 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi