pycall 1.2.0.beta1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/pycall.rb +10 -0
- data/lib/pycall/pymodule_wrapper.rb +46 -0
- data/lib/pycall/pyobject_wrapper.rb +3 -31
- data/lib/pycall/version.rb +1 -1
- data/pycall.gemspec +3 -3
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0a9785eaac83c23c7c49f7cf48b5f5fd658e8d6b1a1f3dc36f1b9039d6747c
|
4
|
+
data.tar.gz: 9e1996633c503014e3110242c242d4590ad7fa2061ebadea9f856875eff48f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b358c6af0013f068da55247fb45ddc24d9f00d0e8826c55530bd39d0f9d16cbc04390695f6b9e0c4518beefbbb396cf4eeb80bc46089dc0132ff3ed763d8cfd
|
7
|
+
data.tar.gz: 9576c22da8b097a52577d4a82065384db2ea2d8878fc2012b90f7350b1a4db05e6892242a23c36ebe78f0ebe36ca6b38ad270c33277a7760761f0f4f9cffdebf
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# PyCall: Calling Python functions from the Ruby language
|
7
7
|
|
8
8
|
[![Build Status](https://travis-ci.org/mrkn/pycall.rb.svg?branch=master)](https://travis-ci.org/mrkn/pycall.rb)
|
9
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/071is0f4iu0vy8lp/branch/master?svg=true)](https://ci.appveyor.com/project/mrkn/pycall
|
9
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/071is0f4iu0vy8lp/branch/master?svg=true)](https://ci.appveyor.com/project/mrkn/pycall/branch/master)
|
10
10
|
|
11
11
|
This library provides the features to directly call and partially interoperate
|
12
12
|
with Python from the Ruby language. You can import arbitrary Python modules
|
@@ -23,6 +23,15 @@ pycall.rb supports Python version 2.7 or higher.
|
|
23
23
|
|
24
24
|
Note that in Python 2.7 old-style class, that is defined without a super class, is not fully supported in pycall.rb.
|
25
25
|
|
26
|
+
## Note for pyenv users
|
27
|
+
|
28
|
+
pycall.rb requires Python's shared library (e.g. `libpython3.7m.so`).
|
29
|
+
pyenv does not build the shared library in default, so you need to specify `--enable-shared` option at the installation like below:
|
30
|
+
|
31
|
+
```
|
32
|
+
$ env PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install 3.7.2
|
33
|
+
```
|
34
|
+
|
26
35
|
## Installation
|
27
36
|
|
28
37
|
Add this line to your application's Gemfile:
|
data/lib/pycall.rb
CHANGED
@@ -4,6 +4,7 @@ module PyCall
|
|
4
4
|
require 'pycall/pyerror'
|
5
5
|
require 'pycall/pyobject_wrapper'
|
6
6
|
require 'pycall/pytypeobject_wrapper'
|
7
|
+
require 'pycall/pymodule_wrapper'
|
7
8
|
require 'pycall/init'
|
8
9
|
|
9
10
|
module_function
|
@@ -48,6 +49,15 @@ module PyCall
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
52
|
+
def getattr(*args)
|
53
|
+
obj, *rest = args
|
54
|
+
LibPython::Helpers.getattr(obj.__pyptr__, *rest)
|
55
|
+
end
|
56
|
+
|
57
|
+
def hasattr?(obj, name)
|
58
|
+
LibPython::Helpers.hasattr?(obj.__pyptr__, name)
|
59
|
+
end
|
60
|
+
|
51
61
|
def import_module(name)
|
52
62
|
LibPython::Helpers.import_module(name)
|
53
63
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pycall/pyobject_wrapper'
|
2
|
+
|
3
|
+
module PyCall
|
4
|
+
module PyModuleWrapper
|
5
|
+
include PyObjectWrapper
|
6
|
+
|
7
|
+
def [](*args)
|
8
|
+
case args[0]
|
9
|
+
when String, Symbol
|
10
|
+
PyCall.getattr(self, args[0])
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module_function
|
18
|
+
|
19
|
+
class WrapperModuleCache < WrapperObjectCache
|
20
|
+
def initialize
|
21
|
+
super(LibPython::API::PyModule_Type)
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_wrapper_object(wrapper_object)
|
25
|
+
unless wrapper_object.kind_of?(Module) && wrapper_object.kind_of?(PyObjectWrapper)
|
26
|
+
raise TypeError, "unexpected type #{wrapper_object.class} (expected Module extended by PyObjectWrapper)"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.instance
|
31
|
+
@instance ||= self.new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private_constant :WrapperModuleCache
|
36
|
+
|
37
|
+
def wrap_module(pymodptr)
|
38
|
+
check_ismodule(pymodptr)
|
39
|
+
WrapperModuleCache.instance.lookup(pymodptr) do
|
40
|
+
Module.new do |mod|
|
41
|
+
mod.instance_variable_set(:@__pyptr__, pymodptr)
|
42
|
+
mod.extend PyModuleWrapper
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -170,32 +170,9 @@ module PyCall
|
|
170
170
|
|
171
171
|
module_function
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
def check_wrapper_object(wrapper_object)
|
179
|
-
unless wrapper_object.kind_of?(Module) && wrapper_object.kind_of?(PyObjectWrapper)
|
180
|
-
raise TypeError, "unexpected type #{wrapper_object.class} (expected Module extended by PyObjectWrapper)"
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def self.instance
|
185
|
-
@instance ||= self.new
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
private_constant :WrapperModuleCache
|
190
|
-
|
191
|
-
def wrap_module(pymodptr)
|
192
|
-
check_ismodule(pymodptr)
|
193
|
-
WrapperModuleCache.instance.lookup(pymodptr) do
|
194
|
-
Module.new do |mod|
|
195
|
-
mod.instance_variable_set(:@__pyptr__, pymodptr)
|
196
|
-
mod.extend PyObjectWrapper
|
197
|
-
end
|
198
|
-
end
|
173
|
+
def check_ismodule(pyptr)
|
174
|
+
return if pyptr.kind_of? LibPython::API::PyModule_Type
|
175
|
+
raise TypeError, "PyModule object is required"
|
199
176
|
end
|
200
177
|
|
201
178
|
def check_isclass(pyptr)
|
@@ -204,9 +181,4 @@ module PyCall
|
|
204
181
|
return defined?(LibPython::API::PyClass_Type) && pyptr.kind_of?(LibPython::API::PyClass_Type)
|
205
182
|
raise TypeError, "PyType object is required"
|
206
183
|
end
|
207
|
-
|
208
|
-
def check_ismodule(pyptr)
|
209
|
-
return if pyptr.kind_of? LibPython::API::PyModule_Type
|
210
|
-
raise TypeError, "PyModule object is required"
|
211
|
-
end
|
212
184
|
end
|
data/lib/pycall/version.rb
CHANGED
data/pycall.gemspec
CHANGED
@@ -30,11 +30,11 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
spec.extensions = ["ext/pycall/extconf.rb"]
|
32
32
|
|
33
|
-
spec.add_development_dependency "bundler", "
|
34
|
-
spec.add_development_dependency "rake"
|
33
|
+
spec.add_development_dependency "bundler", ">= 1.17.2"
|
34
|
+
spec.add_development_dependency "rake"
|
35
35
|
spec.add_development_dependency "rake-compiler"
|
36
36
|
spec.add_development_dependency "rake-compiler-dock"
|
37
|
-
spec.add_development_dependency "rspec"
|
37
|
+
spec.add_development_dependency "rspec"
|
38
38
|
spec.add_development_dependency "launchy"
|
39
39
|
spec.add_development_dependency "pry"
|
40
40
|
spec.add_development_dependency "pry-byebug"
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pycall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.17.2
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.17.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: launchy
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/pycall/list.rb
|
188
188
|
- lib/pycall/pretty_print.rb
|
189
189
|
- lib/pycall/pyerror.rb
|
190
|
+
- lib/pycall/pymodule_wrapper.rb
|
190
191
|
- lib/pycall/pyobject_wrapper.rb
|
191
192
|
- lib/pycall/python/PyCall/__init__.py
|
192
193
|
- lib/pycall/python/PyCall/six.py
|
@@ -214,12 +215,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
215
|
version: '0'
|
215
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
217
|
requirements:
|
217
|
-
- - "
|
218
|
+
- - ">="
|
218
219
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
220
|
+
version: '0'
|
220
221
|
requirements: []
|
221
|
-
|
222
|
-
rubygems_version: 2.7.6
|
222
|
+
rubygems_version: 3.0.2
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: pycall
|