pycall 1.0.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +41 -0
- data/CHANGES.md +39 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +29 -0
- data/appveyor.yml +138 -0
- data/bin/console +10 -0
- data/bin/guard +17 -0
- data/bin/rspec +17 -0
- data/bin/runner +6 -0
- data/bin/setup +8 -0
- data/config/Guardfile +30 -0
- data/docker/Dockerfile +191 -0
- data/docker/Gemfile +12 -0
- data/docker/README.md +22 -0
- data/examples/classifier_comparison.rb +135 -0
- data/examples/datascience_rb_20170519.ipynb +4836 -0
- data/examples/hist.rb +32 -0
- data/examples/notebooks/classifier_comparison.ipynb +226 -0
- data/examples/notebooks/forest_importances.ipynb +238 -0
- data/examples/notebooks/iruby_integration.ipynb +183 -0
- data/examples/notebooks/lorenz_attractor.ipynb +214 -0
- data/examples/notebooks/polar_axes.ipynb +209 -0
- data/examples/notebooks/sum_benchmarking.ipynb +374 -0
- data/examples/notebooks/xkcd_style.ipynb +149 -0
- data/examples/plot_forest_importances_faces.rb +46 -0
- data/examples/sum_benchmarking.rb +49 -0
- data/ext/pycall/extconf.rb +3 -0
- data/ext/pycall/gc.c +74 -0
- data/ext/pycall/libpython.c +217 -0
- data/ext/pycall/pycall.c +2184 -0
- data/ext/pycall/pycall_internal.h +700 -0
- data/ext/pycall/range.c +69 -0
- data/ext/pycall/ruby_wrapper.c +432 -0
- data/lib/pycall.rb +91 -0
- data/lib/pycall/conversion.rb +173 -0
- data/lib/pycall/dict.rb +48 -0
- data/lib/pycall/error.rb +10 -0
- data/lib/pycall/gc_guard.rb +84 -0
- data/lib/pycall/import.rb +120 -0
- data/lib/pycall/init.rb +55 -0
- data/lib/pycall/iruby_helper.rb +40 -0
- data/lib/pycall/libpython.rb +12 -0
- data/lib/pycall/libpython/finder.rb +170 -0
- data/lib/pycall/libpython/pyobject_struct.rb +30 -0
- data/lib/pycall/libpython/pytypeobject_struct.rb +273 -0
- data/lib/pycall/list.rb +45 -0
- data/lib/pycall/pretty_print.rb +9 -0
- data/lib/pycall/pyerror.rb +30 -0
- data/lib/pycall/pyobject_wrapper.rb +212 -0
- data/lib/pycall/python/PyCall/__init__.py +1 -0
- data/lib/pycall/python/PyCall/six.py +23 -0
- data/lib/pycall/python/investigator.py +7 -0
- data/lib/pycall/pytypeobject_wrapper.rb +90 -0
- data/lib/pycall/set.rb +19 -0
- data/lib/pycall/slice.rb +8 -0
- data/lib/pycall/tuple.rb +46 -0
- data/lib/pycall/version.rb +3 -0
- data/lib/pycall/wrapper_object_cache.rb +61 -0
- data/pycall.gemspec +40 -0
- data/tasks/docker.rake +21 -0
- data/tasks/pycall.rake +7 -0
- metadata +228 -0
data/lib/pycall/slice.rb
ADDED
data/lib/pycall/tuple.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module PyCall
|
2
|
+
class Tuple
|
3
|
+
include PyObjectWrapper
|
4
|
+
|
5
|
+
def self.new(init)
|
6
|
+
case init
|
7
|
+
when Integer
|
8
|
+
super(LibPython.PyTuple_New(init))
|
9
|
+
when Array
|
10
|
+
tuple = new(init.length)
|
11
|
+
init.each_with_index do |obj, index|
|
12
|
+
tuple[index] = obj
|
13
|
+
end
|
14
|
+
tuple
|
15
|
+
when LibPython::PyObjectStruct
|
16
|
+
super(init)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Make tuple from array
|
21
|
+
def self.[](*ary)
|
22
|
+
new(ary)
|
23
|
+
end
|
24
|
+
|
25
|
+
def size
|
26
|
+
LibPython.PyTuple_Size(__pyobj__)
|
27
|
+
end
|
28
|
+
|
29
|
+
alias length size
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
LibPython.PyTuple_GetItem(__pyobj__, index).to_ruby
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, value)
|
36
|
+
value = Conversions.from_ruby(value)
|
37
|
+
LibPython.PyTuple_SetItem(__pyobj__, index, value)
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_a
|
41
|
+
Array.new(length) {|i| self[i] }
|
42
|
+
end
|
43
|
+
|
44
|
+
alias to_ary to_a
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module PyCall
|
2
|
+
class WrapperObjectCache
|
3
|
+
def initialize(*restricted_pytypes)
|
4
|
+
unless restricted_pytypes.empty?
|
5
|
+
restricted_pytypes.each do |pytype|
|
6
|
+
next if pytype.kind_of? PyTypePtr
|
7
|
+
raise TypeError, "unexpected type of object in the arguments (#{pytype.class} for PyCall::PyTypePtr)"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
@restricted_pytypes = restricted_pytypes
|
11
|
+
@wrapper_object_table = {}
|
12
|
+
@wrapped_pyptr_table = {}
|
13
|
+
@weakref_table = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def lookup(pyptr)
|
17
|
+
# TODO: check pytypeptr type
|
18
|
+
unless pyptr.kind_of? PyPtr
|
19
|
+
raise TypeError, "unexpected argument type #{pyptr.class} (expected PyCall::PyPtr)"
|
20
|
+
end
|
21
|
+
|
22
|
+
unless @restricted_pytypes.empty?
|
23
|
+
unless @restricted_pytypes.any? {|pytype| pyptr.kind_of? pytype }
|
24
|
+
raise TypeError, "unexpected argument Python type #{pyptr.__ob_type__.__name__} (expected either of them in [#{@restricted_pytypes.map(&:__tp_name__).join(', ')}])"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
wrapper_object_id = @wrapper_object_table[pyptr.__address__]
|
29
|
+
if wrapper_object_id
|
30
|
+
wrapper_object = ObjectSpace._id2ref(wrapper_object_id) rescue nil
|
31
|
+
return wrapper_object if wrapper_object
|
32
|
+
end
|
33
|
+
|
34
|
+
wrapper_object = yield(pyptr)
|
35
|
+
check_wrapper_object(wrapper_object)
|
36
|
+
register_wrapper_object(pyptr, wrapper_object)
|
37
|
+
|
38
|
+
wrapper_object
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_wrapper_object(wrapper_object)
|
42
|
+
unless wrapper_object.kind_of?(PyObjectWrapper)
|
43
|
+
raise TypeError, "unexpected wrapper object (expected an object extended by PyObjectWrapper)"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def register_wrapper_object(pyptr, wrapper_object)
|
48
|
+
@wrapper_object_table[pyptr.__address__] = wrapper_object.__id__
|
49
|
+
@wrapped_pyptr_table[wrapper_object.__id__] = pyptr.__address__
|
50
|
+
ObjectSpace.define_finalizer(wrapper_object, &method(:unregister_wrapper_object))
|
51
|
+
# TODO: weakref
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def unregister_wrapper_object(wrapper_object_id)
|
56
|
+
pyptr_addr = @wrapped_pyptr_table.delete(wrapper_object_id)
|
57
|
+
@wrapper_object_table.delete(pyptr_addr) if pyptr_addr
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/pycall.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pycall/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pycall"
|
8
|
+
spec.version = PyCall::VERSION
|
9
|
+
spec.authors = ["Kenta Murata"]
|
10
|
+
spec.email = ["mrkn@mrkn.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{pycall}
|
13
|
+
spec.description = %q{pycall}
|
14
|
+
spec.homepage = "https://github.com/mrkn/pycall"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
case f
|
19
|
+
when %r{^Guardfile}, # NOTE: Skip symlink for Windows
|
20
|
+
%r{^(test|spec|features)/}
|
21
|
+
true
|
22
|
+
else
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
spec.extensions = ["ext/pycall/extconf.rb"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rake-compiler"
|
35
|
+
spec.add_development_dependency "rake-compiler-dock"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "launchy"
|
38
|
+
spec.add_development_dependency "pry"
|
39
|
+
spec.add_development_dependency "pry-byebug"
|
40
|
+
end
|
data/tasks/docker.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :docker do
|
2
|
+
task :build do
|
3
|
+
Dir.chdir File.expand_path('../..', __FILE__) do
|
4
|
+
system "docker build -f docker/Dockerfile -t rubydata/pycall ."
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Run docker container [port=8888] [attach_local=$(pwd)]'
|
9
|
+
task :run do
|
10
|
+
require 'securerandom'
|
11
|
+
require 'launchy'
|
12
|
+
token = SecureRandom.hex(48)
|
13
|
+
port = ENV['port'] || '8888'
|
14
|
+
attach_local = File.expand_path(ENV['attach_local'] || Dir.pwd)
|
15
|
+
Thread.start do
|
16
|
+
sleep 3
|
17
|
+
Launchy.open("http://localhost:#{port}/?token=#{token}")
|
18
|
+
end
|
19
|
+
system "docker run -it -e 'JUPYTER_TOKEN=#{token}' -v #{attach_local}:/notebooks/local -p #{port}:8888 --rm --name pycall rubydata/pycall"
|
20
|
+
end
|
21
|
+
end
|
data/tasks/pycall.rake
ADDED
metadata
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pycall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: x64-mingw32
|
6
|
+
authors:
|
7
|
+
- Kenta Murata
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler-dock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: launchy
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: pycall
|
126
|
+
email:
|
127
|
+
- mrkn@mrkn.jp
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CHANGES.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- appveyor.yml
|
141
|
+
- bin/console
|
142
|
+
- bin/guard
|
143
|
+
- bin/rspec
|
144
|
+
- bin/runner
|
145
|
+
- bin/setup
|
146
|
+
- config/Guardfile
|
147
|
+
- docker/Dockerfile
|
148
|
+
- docker/Gemfile
|
149
|
+
- docker/README.md
|
150
|
+
- examples/classifier_comparison.rb
|
151
|
+
- examples/datascience_rb_20170519.ipynb
|
152
|
+
- examples/hist.rb
|
153
|
+
- examples/notebooks/classifier_comparison.ipynb
|
154
|
+
- examples/notebooks/forest_importances.ipynb
|
155
|
+
- examples/notebooks/iruby_integration.ipynb
|
156
|
+
- examples/notebooks/lorenz_attractor.ipynb
|
157
|
+
- examples/notebooks/polar_axes.ipynb
|
158
|
+
- examples/notebooks/sum_benchmarking.ipynb
|
159
|
+
- examples/notebooks/xkcd_style.ipynb
|
160
|
+
- examples/plot_forest_importances_faces.rb
|
161
|
+
- examples/sum_benchmarking.rb
|
162
|
+
- ext/pycall/extconf.rb
|
163
|
+
- ext/pycall/gc.c
|
164
|
+
- ext/pycall/libpython.c
|
165
|
+
- ext/pycall/pycall.c
|
166
|
+
- ext/pycall/pycall_internal.h
|
167
|
+
- ext/pycall/range.c
|
168
|
+
- ext/pycall/ruby_wrapper.c
|
169
|
+
- lib/2.1/pycall.so
|
170
|
+
- lib/2.2/pycall.so
|
171
|
+
- lib/2.3/pycall.so
|
172
|
+
- lib/2.4/pycall.so
|
173
|
+
- lib/pycall.rb
|
174
|
+
- lib/pycall/conversion.rb
|
175
|
+
- lib/pycall/dict.rb
|
176
|
+
- lib/pycall/error.rb
|
177
|
+
- lib/pycall/gc_guard.rb
|
178
|
+
- lib/pycall/import.rb
|
179
|
+
- lib/pycall/init.rb
|
180
|
+
- lib/pycall/iruby_helper.rb
|
181
|
+
- lib/pycall/libpython.rb
|
182
|
+
- lib/pycall/libpython/finder.rb
|
183
|
+
- lib/pycall/libpython/pyobject_struct.rb
|
184
|
+
- lib/pycall/libpython/pytypeobject_struct.rb
|
185
|
+
- lib/pycall/list.rb
|
186
|
+
- lib/pycall/pretty_print.rb
|
187
|
+
- lib/pycall/pyerror.rb
|
188
|
+
- lib/pycall/pyobject_wrapper.rb
|
189
|
+
- lib/pycall/python/PyCall/__init__.py
|
190
|
+
- lib/pycall/python/PyCall/six.py
|
191
|
+
- lib/pycall/python/investigator.py
|
192
|
+
- lib/pycall/pytypeobject_wrapper.rb
|
193
|
+
- lib/pycall/set.rb
|
194
|
+
- lib/pycall/slice.rb
|
195
|
+
- lib/pycall/tuple.rb
|
196
|
+
- lib/pycall/version.rb
|
197
|
+
- lib/pycall/wrapper_object_cache.rb
|
198
|
+
- pycall.gemspec
|
199
|
+
- tasks/docker.rake
|
200
|
+
- tasks/pycall.rake
|
201
|
+
homepage: https://github.com/mrkn/pycall
|
202
|
+
licenses:
|
203
|
+
- MIT
|
204
|
+
metadata: {}
|
205
|
+
post_install_message:
|
206
|
+
rdoc_options: []
|
207
|
+
require_paths:
|
208
|
+
- lib
|
209
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '2.1'
|
214
|
+
- - "<"
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '2.5'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 2.6.12
|
225
|
+
signing_key:
|
226
|
+
specification_version: 4
|
227
|
+
summary: pycall
|
228
|
+
test_files: []
|