pycall 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +150 -0
- data/.github/workflows/windows.yml +127 -0
- data/.gitignore +2 -0
- data/CHANGES.md +39 -1
- data/README.md +153 -7
- data/Rakefile +81 -19
- data/ci/travis_install.sh +30 -9
- data/examples/classifier_comparison.rb +1 -1
- data/examples/hist.rb +1 -1
- data/examples/notebooks/classifier_comparison.ipynb +1 -1
- data/examples/notebooks/leaflet.ipynb +77 -0
- data/ext/pycall/libpython.c +7 -1
- data/ext/pycall/pycall.c +60 -6
- data/ext/pycall/pycall_internal.h +27 -1
- data/ext/pycall/ruby_wrapper.c +11 -2
- data/ext/pycall/thread.c +36 -0
- data/lib/pycall.rb +11 -0
- data/lib/pycall/dict.rb +2 -2
- data/lib/pycall/init.rb +3 -8
- data/lib/pycall/iruby_helper.rb +1 -1
- data/lib/pycall/libpython/finder.rb +131 -84
- data/lib/pycall/list.rb +2 -2
- data/lib/pycall/pyobject_wrapper.rb +1 -1
- data/lib/pycall/python/investigator.py +82 -9
- data/lib/pycall/pytypeobject_wrapper.rb +10 -0
- data/lib/pycall/version.rb +7 -1
- data/lib/pycall/wrapper_object_cache.rb +51 -25
- data/pycall.gemspec +9 -2
- metadata +23 -7
- data/.travis.yml +0 -56
- data/appveyor.yml +0 -104
@@ -51,8 +51,18 @@ module PyCall
|
|
51
51
|
|
52
52
|
def <(other)
|
53
53
|
case other
|
54
|
+
when self
|
55
|
+
false
|
54
56
|
when PyTypeObjectWrapper
|
55
57
|
__pyptr__ < other.__pyptr__
|
58
|
+
when Class
|
59
|
+
false if other.ancestors.include?(self)
|
60
|
+
when Module
|
61
|
+
if ancestors.include?(other)
|
62
|
+
true
|
63
|
+
elsif other.ancestors.include?(self)
|
64
|
+
false
|
65
|
+
end
|
56
66
|
else
|
57
67
|
raise TypeError, "compared with non class/module"
|
58
68
|
end
|
data/lib/pycall/version.rb
CHANGED
@@ -1,5 +1,49 @@
|
|
1
1
|
module PyCall
|
2
2
|
class WrapperObjectCache
|
3
|
+
|
4
|
+
begin
|
5
|
+
ObjectSpace::WeakMap.new[42] = Object.new
|
6
|
+
rescue
|
7
|
+
WMAP_SUPPORT_INT_KEY = false
|
8
|
+
else
|
9
|
+
WMAP_SUPPORT_INT_KEY = true
|
10
|
+
end
|
11
|
+
|
12
|
+
if WMAP_SUPPORT_INT_KEY
|
13
|
+
def self.get_key(pyptr)
|
14
|
+
pyptr.__address__
|
15
|
+
end
|
16
|
+
else
|
17
|
+
class Key
|
18
|
+
@address_key_map = {}
|
19
|
+
|
20
|
+
def self.[](address)
|
21
|
+
# An instance of Key created here is parmanently cached in @address_key_map.
|
22
|
+
# This behavior is intentional.
|
23
|
+
@address_key_map[address] ||= new(address)
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(address)
|
27
|
+
@address = address
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :address
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
case other
|
34
|
+
when Key
|
35
|
+
self.address == other.address
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_key(pyptr)
|
43
|
+
Key[pyptr.__address__]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
3
47
|
def initialize(*restricted_pytypes)
|
4
48
|
unless restricted_pytypes.empty?
|
5
49
|
restricted_pytypes.each do |pytype|
|
@@ -8,9 +52,7 @@ module PyCall
|
|
8
52
|
end
|
9
53
|
end
|
10
54
|
@restricted_pytypes = restricted_pytypes
|
11
|
-
@wrapper_object_table =
|
12
|
-
@wrapped_pyptr_table = {}
|
13
|
-
@weakref_table = {}
|
55
|
+
@wrapper_object_table = ObjectSpace::WeakMap.new
|
14
56
|
end
|
15
57
|
|
16
58
|
def lookup(pyptr)
|
@@ -25,16 +67,14 @@ module PyCall
|
|
25
67
|
end
|
26
68
|
end
|
27
69
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
70
|
+
key = self.class.get_key(pyptr)
|
71
|
+
wrapper_object = @wrapper_object_table[key]
|
72
|
+
unless wrapper_object
|
73
|
+
wrapper_object = yield(pyptr)
|
74
|
+
check_wrapper_object(wrapper_object)
|
75
|
+
@wrapper_object_table[key] = wrapper_object
|
32
76
|
end
|
33
77
|
|
34
|
-
wrapper_object = yield(pyptr)
|
35
|
-
check_wrapper_object(wrapper_object)
|
36
|
-
register_wrapper_object(pyptr, wrapper_object)
|
37
|
-
|
38
78
|
wrapper_object
|
39
79
|
end
|
40
80
|
|
@@ -43,19 +83,5 @@ module PyCall
|
|
43
83
|
raise TypeError, "unexpected wrapper object (expected an object extended by PyObjectWrapper)"
|
44
84
|
end
|
45
85
|
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
86
|
end
|
61
87
|
end
|
data/pycall.gemspec
CHANGED
@@ -5,7 +5,13 @@ require 'pycall/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "pycall"
|
8
|
-
|
8
|
+
version_components = [
|
9
|
+
PyCall::Version::MAJOR.to_s,
|
10
|
+
PyCall::Version::MINOR.to_s,
|
11
|
+
PyCall::Version::MICRO.to_s,
|
12
|
+
PyCall::Version::TAG,
|
13
|
+
]
|
14
|
+
spec.version = version_components.compact.join(".")
|
9
15
|
spec.authors = ["Kenta Murata"]
|
10
16
|
spec.email = ["mrkn@mrkn.jp"]
|
11
17
|
|
@@ -30,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
30
36
|
spec.require_paths = ["lib"]
|
31
37
|
spec.extensions = ["ext/pycall/extconf.rb"]
|
32
38
|
|
33
|
-
spec.add_development_dependency "bundler"
|
39
|
+
spec.add_development_dependency "bundler"
|
34
40
|
spec.add_development_dependency "rake"
|
35
41
|
spec.add_development_dependency "rake-compiler"
|
36
42
|
spec.add_development_dependency "rake-compiler-dock"
|
@@ -38,4 +44,5 @@ Gem::Specification.new do |spec|
|
|
38
44
|
spec.add_development_dependency "launchy"
|
39
45
|
spec.add_development_dependency "pry"
|
40
46
|
spec.add_development_dependency "pry-byebug"
|
47
|
+
spec.add_development_dependency "test-unit"
|
41
48
|
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: 1.
|
4
|
+
version: 1.4.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: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
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: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: test-unit
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: pycall
|
126
140
|
email:
|
127
141
|
- mrkn@mrkn.jp
|
@@ -130,15 +144,15 @@ extensions:
|
|
130
144
|
- ext/pycall/extconf.rb
|
131
145
|
extra_rdoc_files: []
|
132
146
|
files:
|
147
|
+
- ".github/workflows/ci.yml"
|
148
|
+
- ".github/workflows/windows.yml"
|
133
149
|
- ".gitignore"
|
134
150
|
- ".rspec"
|
135
|
-
- ".travis.yml"
|
136
151
|
- CHANGES.md
|
137
152
|
- Gemfile
|
138
153
|
- LICENSE.txt
|
139
154
|
- README.md
|
140
155
|
- Rakefile
|
141
|
-
- appveyor.yml
|
142
156
|
- bin/console
|
143
157
|
- bin/guard
|
144
158
|
- bin/rspec
|
@@ -157,6 +171,7 @@ files:
|
|
157
171
|
- examples/notebooks/classifier_comparison.ipynb
|
158
172
|
- examples/notebooks/forest_importances.ipynb
|
159
173
|
- examples/notebooks/iruby_integration.ipynb
|
174
|
+
- examples/notebooks/leaflet.ipynb
|
160
175
|
- examples/notebooks/lorenz_attractor.ipynb
|
161
176
|
- examples/notebooks/polar_axes.ipynb
|
162
177
|
- examples/notebooks/sum_benchmarking.ipynb
|
@@ -171,6 +186,7 @@ files:
|
|
171
186
|
- ext/pycall/pycall_internal.h
|
172
187
|
- ext/pycall/range.c
|
173
188
|
- ext/pycall/ruby_wrapper.c
|
189
|
+
- ext/pycall/thread.c
|
174
190
|
- images/pycallrb_logo.png
|
175
191
|
- images/pycallrb_logo_200.png
|
176
192
|
- lib/pycall.rb
|
@@ -219,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
235
|
- !ruby/object:Gem::Version
|
220
236
|
version: '0'
|
221
237
|
requirements: []
|
222
|
-
rubygems_version: 3.
|
238
|
+
rubygems_version: 3.2.3
|
223
239
|
signing_key:
|
224
240
|
specification_version: 4
|
225
241
|
summary: pycall
|
data/.travis.yml
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
os: linux
|
4
|
-
|
5
|
-
dist: trusty
|
6
|
-
sudo: required
|
7
|
-
|
8
|
-
rvm:
|
9
|
-
- ruby-head
|
10
|
-
- 2.5.0
|
11
|
-
- 2.4.3
|
12
|
-
- 2.3.5
|
13
|
-
|
14
|
-
env:
|
15
|
-
global:
|
16
|
-
- PYCALL_DEBUG_FIND_LIBPYTHON=1
|
17
|
-
matrix:
|
18
|
-
- PYENV_VERSION=2.7.13
|
19
|
-
- PYENV_VERSION=3.6.2
|
20
|
-
- PYENV_VERSION=system LIBPYTHON=versions/3.6.2/lib/libpython3.6m.so
|
21
|
-
- PYENV_VERSION=miniconda2-4.1.11
|
22
|
-
- PYENV_VERSION=miniconda3-4.3.11
|
23
|
-
|
24
|
-
matrix:
|
25
|
-
include:
|
26
|
-
- os: osx
|
27
|
-
osx_image: xcode9
|
28
|
-
compiler: clang
|
29
|
-
rvm: 2.4.1
|
30
|
-
env: PYENV_VERSION=3.6.2
|
31
|
-
- os: osx
|
32
|
-
osx_image: xcode9
|
33
|
-
compiler: clang
|
34
|
-
rvm: 2.4.1
|
35
|
-
env: PYENV_VERSION=system LIBPYTHON=versions/3.6.2/lib/libpython3.6m.so
|
36
|
-
- os: osx
|
37
|
-
osx_image: xcode9
|
38
|
-
compiler: clang
|
39
|
-
rvm: 2.4.1
|
40
|
-
env: PYENV_VERSION=miniconda3-4.3.11
|
41
|
-
allow_failures:
|
42
|
-
- os: osx
|
43
|
-
|
44
|
-
before_install:
|
45
|
-
- gem update --system
|
46
|
-
- gem update bundler
|
47
|
-
- export PATH="$(pyenv root)/bin:$PATH"
|
48
|
-
- eval "$(pyenv init -)"
|
49
|
-
|
50
|
-
install:
|
51
|
-
- ci/travis_install.sh
|
52
|
-
|
53
|
-
before_script:
|
54
|
-
- . ci/travis_before_script.sh
|
55
|
-
- bundle exec rake clobber compile
|
56
|
-
- python lib/pycall/python/investigator.py
|
data/appveyor.yml
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
---
|
2
|
-
environment:
|
3
|
-
matrix:
|
4
|
-
# Ruby 2.4 (32bit)
|
5
|
-
- ruby_version: "24"
|
6
|
-
PYTHONDIR: "C:\\Python27"
|
7
|
-
PYTHON: "C:\\Python27\\python.exe"
|
8
|
-
|
9
|
-
- ruby_version: "24"
|
10
|
-
PYTHONDIR: "C:\\Python34"
|
11
|
-
PYTHON: "C:\\Python34\\python.exe"
|
12
|
-
|
13
|
-
- ruby_version: "24"
|
14
|
-
PYTHONDIR: "C:\\Python35"
|
15
|
-
PYTHON: "C:\\Python35\\python.exe"
|
16
|
-
|
17
|
-
- ruby_version: "24"
|
18
|
-
PYTHONDIR: "C:\\Python36"
|
19
|
-
PYTHON: "C:\\Python36\\python.exe"
|
20
|
-
|
21
|
-
# Ruby 2.4 (64bit)
|
22
|
-
- ruby_version: "24-x64"
|
23
|
-
PYTHONDIR: "C:\\Python27-x64"
|
24
|
-
PYTHON: "C:\\Python27-x64\\python.exe"
|
25
|
-
|
26
|
-
- ruby_version: "24-x64"
|
27
|
-
PYTHONDIR: "C:\\Python34-x64"
|
28
|
-
PYTHON: "C:\\Python34-x64\\python.exe"
|
29
|
-
|
30
|
-
- ruby_version: "24-x64"
|
31
|
-
PYTHONDIR: "C:\\Python35-x64"
|
32
|
-
PYTHON: "C:\\Python35-x64\\python.exe"
|
33
|
-
|
34
|
-
- ruby_version: "24-x64"
|
35
|
-
PYTHONDIR: "C:\\Python36-x64"
|
36
|
-
PYTHON: "C:\\Python36-x64\\python.exe"
|
37
|
-
|
38
|
-
# Ruby 2.3 (32bit)
|
39
|
-
- ruby_version: "23"
|
40
|
-
PYTHONDIR: "C:\\Python27"
|
41
|
-
PYTHON: "C:\\Python27\\python.exe"
|
42
|
-
|
43
|
-
- ruby_version: "23"
|
44
|
-
PYTHONDIR: "C:\\Python34"
|
45
|
-
PYTHON: "C:\\Python34\\python.exe"
|
46
|
-
|
47
|
-
- ruby_version: "23"
|
48
|
-
PYTHONDIR: "C:\\Python35"
|
49
|
-
PYTHON: "C:\\Python35\\python.exe"
|
50
|
-
|
51
|
-
- ruby_version: "23"
|
52
|
-
PYTHONDIR: "C:\\Python36"
|
53
|
-
PYTHON: "C:\\Python36\\python.exe"
|
54
|
-
|
55
|
-
# Ruby 2.3 (64bit)
|
56
|
-
- ruby_version: "23-x64"
|
57
|
-
PYTHONDIR: "C:\\Python27-x64"
|
58
|
-
PYTHON: "C:\\Python27-x64\\python.exe"
|
59
|
-
|
60
|
-
- ruby_version: "23-x64"
|
61
|
-
PYTHONDIR: "C:\\Python34-x64"
|
62
|
-
PYTHON: "C:\\Python34-x64\\python.exe"
|
63
|
-
|
64
|
-
- ruby_version: "23-x64"
|
65
|
-
PYTHONDIR: "C:\\Python35-x64"
|
66
|
-
PYTHON: "C:\\Python35-x64\\python.exe"
|
67
|
-
|
68
|
-
- ruby_version: "23-x64"
|
69
|
-
PYTHONDIR: "C:\\Python36-x64"
|
70
|
-
PYTHON: "C:\\Python36-x64\\python.exe"
|
71
|
-
|
72
|
-
branches:
|
73
|
-
only:
|
74
|
-
- master
|
75
|
-
- /release-.*/
|
76
|
-
|
77
|
-
notifications:
|
78
|
-
- provider: Email
|
79
|
-
on_build_success: false
|
80
|
-
on_build_failure: false
|
81
|
-
on_build_status_changed: false
|
82
|
-
|
83
|
-
deploy: off
|
84
|
-
build: off
|
85
|
-
|
86
|
-
install:
|
87
|
-
- "SET PATH=%PYTHONDIR%;%PYTHONDIR%\\Scripts;%PATH%"
|
88
|
-
- "SET PATH=C:\\Ruby%ruby_version%\\bin;%PATH%"
|
89
|
-
- "bundle install"
|
90
|
-
- "pip install numpy"
|
91
|
-
|
92
|
-
before_test:
|
93
|
-
- "bundle exec rake -rdevkit clobber compile"
|
94
|
-
- ECHO "=== python investigator.py ==="
|
95
|
-
- "python lib\\pycall\\python\\investigator.py"
|
96
|
-
|
97
|
-
test_script:
|
98
|
-
- "SET PYCALL_DEBUG_FIND_LIBPYTHON=1"
|
99
|
-
- rake
|
100
|
-
|
101
|
-
matrix:
|
102
|
-
allow_failures:
|
103
|
-
- PYTHONDIR: "C:\\Python27"
|
104
|
-
- PYTHONDIR: "C:\\Python27-x64"
|