rubypython 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +3 -0
- data/.gemtest +0 -0
- data/.gitignore +13 -0
- data/.hgignore +14 -0
- data/.hgtags +7 -0
- data/.rspec +1 -1
- data/Contributors.rdoc +9 -0
- data/History.rdoc +148 -0
- data/{License.txt → License.rdoc} +7 -1
- data/Manifest.txt +15 -10
- data/PostInstall.txt +11 -4
- data/README.rdoc +272 -0
- data/Rakefile +107 -22
- data/autotest/discover.rb +1 -0
- data/lib/rubypython.rb +214 -120
- data/lib/rubypython/blankobject.rb +16 -14
- data/lib/rubypython/conversion.rb +242 -173
- data/lib/rubypython/legacy.rb +30 -31
- data/lib/rubypython/macros.rb +43 -34
- data/lib/rubypython/operators.rb +103 -101
- data/lib/rubypython/options.rb +41 -44
- data/lib/rubypython/pygenerator.rb +61 -0
- data/lib/rubypython/pymainclass.rb +46 -29
- data/lib/rubypython/pyobject.rb +193 -177
- data/lib/rubypython/python.rb +189 -176
- data/lib/rubypython/pythonerror.rb +54 -63
- data/lib/rubypython/pythonexec.rb +123 -0
- data/lib/rubypython/rubypyproxy.rb +213 -137
- data/lib/rubypython/type.rb +20 -0
- data/spec/basic_spec.rb +50 -0
- data/spec/callback_spec.rb +7 -17
- data/spec/conversion_spec.rb +7 -21
- data/spec/legacy_spec.rb +1 -16
- data/spec/pymainclass_spec.rb +6 -15
- data/spec/pyobject_spec.rb +39 -64
- data/spec/python_helpers/basics.py +20 -0
- data/spec/python_helpers/objects.py +24 -20
- data/spec/pythonerror_spec.rb +5 -17
- data/spec/refcnt_spec.rb +4 -10
- data/spec/rubypyclass_spec.rb +1 -11
- data/spec/rubypyproxy_spec.rb +45 -54
- data/spec/rubypython_spec.rb +45 -57
- data/spec/spec_helper.rb +49 -33
- metadata +87 -63
- data.tar.gz.sig +0 -0
- data/History.markdown +0 -97
- data/README.markdown +0 -105
- data/lib/rubypython/core_ext/string.rb +0 -7
- data/lib/rubypython/version.rb +0 -9
- data/spec/python_helpers/objects.pyc +0 -0
- metadata.gz.sig +0 -0
data/spec/rubypython_spec.rb
CHANGED
@@ -1,95 +1,83 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe RubyPython do
|
4
|
-
|
5
|
-
before do
|
6
|
-
RubyPython.start
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
RubyPython.start
|
11
|
-
end
|
12
|
-
|
13
4
|
describe "#import" do
|
14
|
-
it "
|
5
|
+
it "should handle multiple imports" do
|
15
6
|
lambda do
|
16
7
|
RubyPython.import 'cPickle'
|
17
8
|
RubyPython.import 'urllib'
|
18
9
|
end.should_not raise_exception
|
19
10
|
end
|
20
11
|
|
21
|
-
it "
|
12
|
+
it "should propagate Python errors" do
|
22
13
|
lambda do
|
23
14
|
RubyPython.import 'nonExistentModule'
|
24
15
|
end.should raise_exception(RubyPython::PythonError)
|
25
16
|
end
|
26
17
|
|
27
|
-
it "
|
18
|
+
it "should return a RubyPyModule" do
|
28
19
|
RubyPython.import('urllib2').should be_a(RubyPython::RubyPyModule)
|
29
20
|
end
|
30
21
|
end
|
31
|
-
|
32
22
|
end
|
33
23
|
|
34
|
-
describe RubyPython,
|
24
|
+
describe RubyPython, :self_start => true do
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
describe "#session" do
|
27
|
+
it "should start interpreter" do
|
28
|
+
RubyPython.session do
|
29
|
+
cPickle = RubyPython.import "cPickle"
|
30
|
+
cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.").rubify.should == {"a"=>"n", [1, "2"]=>4}
|
31
|
+
end
|
40
32
|
end
|
41
|
-
end
|
42
33
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
it "should stop the interpreter" do
|
35
|
+
RubyPython.session do
|
36
|
+
cPickle = RubyPython.import "cPickle"
|
37
|
+
end
|
47
38
|
|
48
|
-
|
39
|
+
RubyPython.stop.should be_false
|
40
|
+
end
|
49
41
|
end
|
50
|
-
end
|
51
42
|
|
52
|
-
describe
|
43
|
+
describe "#run" do
|
44
|
+
it "should start interpreter" do
|
45
|
+
RubyPython.run do
|
46
|
+
cPickle = import "cPickle"
|
47
|
+
cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.").rubify.should == {"a"=>"n", [1, "2"]=>4}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should stop the interpreter" do
|
52
|
+
RubyPython.run do
|
53
|
+
cPickle = import "cPickle"
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
RubyPython.run do
|
56
|
-
cPickle = import "cPickle"
|
57
|
-
cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.").rubify.should == {"a"=>"n", [1, "2"]=>4}
|
56
|
+
RubyPython.stop.should be_false
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
|
62
|
-
RubyPython
|
63
|
-
|
60
|
+
describe '#reload_library', :slow => true do
|
61
|
+
it 'leaves RubyPython in a stable state' do
|
62
|
+
lambda do
|
63
|
+
RubyPython.instance_eval { reload_library }
|
64
|
+
RubyPython.run {}
|
65
|
+
end.should_not raise_exception
|
64
66
|
end
|
65
|
-
|
66
|
-
RubyPython.stop.should be_false
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
describe '.configure', :slow => true do
|
70
|
+
it 'allows python executable to be specified', :unless => `which python2.6`.empty? do
|
71
|
+
RubyPython.configure :python_exe => 'python2.6'
|
72
|
+
RubyPython.run do
|
73
|
+
sys = RubyPython.import 'sys'
|
74
|
+
sys.version.rubify.to_f.should == 2.6
|
75
|
+
end
|
76
|
+
end
|
70
77
|
|
71
|
-
|
72
|
-
|
73
|
-
lambda do
|
78
|
+
after(:all) do
|
79
|
+
RubyPython.clear_options
|
74
80
|
RubyPython.instance_eval { reload_library }
|
75
|
-
RubyPython.run {}
|
76
|
-
end.should_not raise_exception
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
describe RubyPython, '.configure', :slow => true do
|
82
|
-
it 'allows python executable to be specified', :unless => `which python2.6`.empty? do
|
83
|
-
RubyPython.configure :python_exe => 'python2.6'
|
84
|
-
RubyPython.run do
|
85
|
-
sys = RubyPython.import 'sys'
|
86
|
-
sys.version.rubify.to_f.should == 2.6
|
87
81
|
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
after(:all) do
|
92
|
-
RubyPython.clear_options
|
93
|
-
RubyPython.instance_eval { reload_library }
|
94
82
|
end
|
95
83
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,49 +1,65 @@
|
|
1
1
|
begin
|
2
2
|
require 'rspec'
|
3
|
-
require 'ffi'
|
4
3
|
rescue LoadError
|
5
4
|
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
6
|
-
gem 'rspec'
|
7
5
|
require 'rspec'
|
8
|
-
require 'ffi'
|
9
6
|
end
|
10
7
|
|
11
|
-
|
8
|
+
dir = File.dirname(__FILE__)
|
9
|
+
|
10
|
+
$:.unshift(File.join(dir, '..', 'lib'))
|
12
11
|
require 'rubypython'
|
13
12
|
|
14
13
|
module TestConstants
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
AMethod = method(:a_method)
|
40
|
-
|
14
|
+
AString = "STRING"
|
15
|
+
AStringWithNULLs = "STRING\0WITH\0NULLS"
|
16
|
+
AnInt = 1
|
17
|
+
AChar = 'a'
|
18
|
+
AFloat = 1.0
|
19
|
+
AnArray = [AnInt, AChar, AFloat, AString]
|
20
|
+
ASym = :sym
|
21
|
+
AHash = {
|
22
|
+
AnInt => AnInt,
|
23
|
+
AChar.to_sym => AChar,
|
24
|
+
ASym => AFloat,
|
25
|
+
AString => AString
|
26
|
+
}
|
27
|
+
AConvertedHash = Hash[*AHash.map do |k, v|
|
28
|
+
key = k.is_a?(Symbol) ? k.to_s : k
|
29
|
+
[key, v]
|
30
|
+
end.flatten]
|
31
|
+
AProc = Proc.new { |a1, a2| a1 + a2 }
|
32
|
+
def self.a_method(a1, a2)
|
33
|
+
a1 + a2
|
34
|
+
end
|
35
|
+
AMethod = method(:a_method)
|
41
36
|
end
|
42
37
|
|
43
38
|
def run_python_command(cmd)
|
44
|
-
|
39
|
+
%x(python -c '#{cmd}').chomp
|
45
40
|
end
|
46
41
|
|
47
|
-
|
48
|
-
|
42
|
+
RSpec.configure do |config|
|
43
|
+
if RUBY_VERSION < '1.9.2'
|
44
|
+
config.filter_run_excluding :ruby_version => '1.9'
|
45
|
+
end
|
46
|
+
|
47
|
+
config.before(:all) do
|
48
|
+
class RubyPython::RubyPyProxy
|
49
|
+
[:should, :should_not, :class].each { |m| reveal(m) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
config.before(:all, :self_start => nil) do
|
54
|
+
RubyPython.start
|
55
|
+
|
56
|
+
@sys = RubyPython.import 'sys'
|
57
|
+
@sys.path.append File.join(dir, 'python_helpers')
|
58
|
+
@objects = RubyPython.import 'objects'
|
59
|
+
@basics = RubyPython.import 'basics'
|
60
|
+
end
|
61
|
+
|
62
|
+
config.after(:all) do
|
63
|
+
RubyPython.stop
|
64
|
+
end
|
49
65
|
end
|
metadata
CHANGED
@@ -1,42 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubypython
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
+
- Steeve Morin
|
14
|
+
- Austin Ziegler
|
13
15
|
- Zach Raines
|
14
16
|
autorequire:
|
15
17
|
bindir: bin
|
16
|
-
cert_chain:
|
17
|
-
- |
|
18
|
-
-----BEGIN CERTIFICATE-----
|
19
|
-
MIIDSDCCAjCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBKMRwwGgYDVQQDDBNyYWlu
|
20
|
-
ZXN6bV9ydWJ5cHl0aG9uMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
|
21
|
-
k/IsZAEZFgNjb20wHhcNMTAwODA4MDI0NTMwWhcNMTEwODA4MDI0NTMwWjBKMRww
|
22
|
-
GgYDVQQDDBNyYWluZXN6bV9ydWJ5cHl0aG9uMRUwEwYKCZImiZPyLGQBGRYFZ21h
|
23
|
-
aWwxEzARBgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
24
|
-
ggEKAoIBAQDPSmmxYqWWN53XrD4btZ08twipRz5priTFtwmKL01WfhHa66OhDoV2
|
25
|
-
OPtW0RoWegZ5gti/gJ67P6IVl1yBekfV581yHsZqV7VqcOkDbT93F3HuTLH12d1C
|
26
|
-
w/OhHoGZUURedNeSMjKmMSlCCD4rzCfXTeAEU6E3rXh3u2AD7kQfeYcZA/u0YgrD
|
27
|
-
lS3c2oX3GvJHjd4hV5hIGgOGXDxcgH5S1iO6588SBxLN+xdYC82w09e5r09tBvo3
|
28
|
-
BXZlsErwuWRI8Ha7y6thbrB28GS5jI378ew4kSUS/1T9Sz4EcPmhyhyCeXvvsdCm
|
29
|
-
4BvNPMBl/yP2fhcubMD/Q0t9Ia9chVc3AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYD
|
30
|
-
VR0OBBYEFNLncU/Kj1RRsjb5blAhik0hgvKCMAsGA1UdDwQEAwIEsDANBgkqhkiG
|
31
|
-
9w0BAQUFAAOCAQEAj8z1kRS/1sHU2yRZothKrgsOLoDxF1+uYq909rS2d6FqOJbt
|
32
|
-
V08JaOil/eMlTjPk7nBUU9OZlNmb8oD0Wt2Lgv9GFMJJm0mch767Nk3h1t9qiJJC
|
33
|
-
v4Ida7e6+ArAcHExQx/lul2jJCWezgIVxz9T9unOfvylOyXwAHV4EEK47EeU1TZV
|
34
|
-
T4cMl2JyytBtjCPydVJGfirxlM7aTMOZ6FvUbCiFvHaymAgoOVZmm7NpE6GsMT7g
|
35
|
-
1b1UcQqvLqyp9gdB3jVeb7JnTLY+WlHWt2rFVbeqv7KtJlp7+4uWMKkzTbW/ujdG
|
36
|
-
cguJMiQCSOlUPZxCWWMkjfZbXvtS5VdzJevSqQ==
|
37
|
-
-----END CERTIFICATE-----
|
18
|
+
cert_chain: []
|
38
19
|
|
39
|
-
date: 2011-
|
20
|
+
date: 2011-03-17 00:00:00 -04:00
|
40
21
|
default_executable:
|
41
22
|
dependencies:
|
42
23
|
- !ruby/object:Gem::Dependency
|
@@ -45,14 +26,14 @@ dependencies:
|
|
45
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
46
27
|
none: false
|
47
28
|
requirements:
|
48
|
-
- -
|
29
|
+
- - ~>
|
49
30
|
- !ruby/object:Gem::Version
|
50
|
-
hash:
|
31
|
+
hash: 25
|
51
32
|
segments:
|
33
|
+
- 1
|
52
34
|
- 0
|
53
|
-
-
|
54
|
-
|
55
|
-
version: 0.6.3
|
35
|
+
- 7
|
36
|
+
version: 1.0.7
|
56
37
|
type: :runtime
|
57
38
|
version_requirements: *id001
|
58
39
|
- !ruby/object:Gem::Dependency
|
@@ -78,7 +59,7 @@ dependencies:
|
|
78
59
|
requirement: &id003 !ruby/object:Gem::Requirement
|
79
60
|
none: false
|
80
61
|
requirements:
|
81
|
-
- -
|
62
|
+
- - ~>
|
82
63
|
- !ruby/object:Gem::Version
|
83
64
|
hash: 3
|
84
65
|
segments:
|
@@ -87,73 +68,116 @@ dependencies:
|
|
87
68
|
version: "2.0"
|
88
69
|
type: :development
|
89
70
|
version_requirements: *id003
|
90
|
-
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: tilt
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 15
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 0
|
83
|
+
version: "1.0"
|
84
|
+
type: :development
|
85
|
+
version_requirements: *id004
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: hoe
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 41
|
95
|
+
segments:
|
96
|
+
- 2
|
97
|
+
- 9
|
98
|
+
- 1
|
99
|
+
version: 2.9.1
|
100
|
+
type: :development
|
101
|
+
version_requirements: *id005
|
102
|
+
description: |-
|
103
|
+
RubyPython is a bridge between the Ruby and Python interpreters. It embeds a
|
104
|
+
running Python interpreter in the Ruby application's process using FFI and
|
105
|
+
provides a means for wrapping, converting, and calling Python objects and
|
106
|
+
methods.
|
107
|
+
|
108
|
+
RubyPython uses FFI to marshal the data between the Ruby and Python VMs and
|
109
|
+
make Python calls. You can:
|
110
|
+
|
111
|
+
* Inherit from Python classes.
|
112
|
+
* Configure callbacks from Python.
|
113
|
+
* Run Python generators (on Ruby 1.9.2 or later).
|
91
114
|
email:
|
115
|
+
- swiuzzz+rubypython@gmail.com
|
116
|
+
- austin@rubyforge.org
|
92
117
|
- raineszm+rubypython@gmail.com
|
93
118
|
executables: []
|
94
119
|
|
95
120
|
extensions: []
|
96
121
|
|
97
122
|
extra_rdoc_files:
|
98
|
-
- License.txt
|
99
123
|
- Manifest.txt
|
100
124
|
- PostInstall.txt
|
101
|
-
-
|
125
|
+
- Contributors.rdoc
|
126
|
+
- History.rdoc
|
127
|
+
- License.rdoc
|
128
|
+
- README.rdoc
|
102
129
|
files:
|
103
|
-
-
|
104
|
-
-
|
130
|
+
- .autotest
|
131
|
+
- .gitignore
|
132
|
+
- .hgignore
|
133
|
+
- .hgtags
|
134
|
+
- .rspec
|
135
|
+
- Contributors.rdoc
|
136
|
+
- History.rdoc
|
137
|
+
- License.rdoc
|
105
138
|
- Manifest.txt
|
106
139
|
- PostInstall.txt
|
107
|
-
- README.
|
140
|
+
- README.rdoc
|
108
141
|
- Rakefile
|
109
|
-
- .
|
142
|
+
- autotest/discover.rb
|
110
143
|
- lib/rubypython.rb
|
111
144
|
- lib/rubypython/blankobject.rb
|
112
145
|
- lib/rubypython/conversion.rb
|
113
|
-
- lib/rubypython/core_ext/string.rb
|
114
146
|
- lib/rubypython/legacy.rb
|
115
147
|
- lib/rubypython/macros.rb
|
116
148
|
- lib/rubypython/operators.rb
|
117
149
|
- lib/rubypython/options.rb
|
150
|
+
- lib/rubypython/pygenerator.rb
|
118
151
|
- lib/rubypython/pymainclass.rb
|
119
152
|
- lib/rubypython/pyobject.rb
|
120
153
|
- lib/rubypython/python.rb
|
121
154
|
- lib/rubypython/pythonerror.rb
|
155
|
+
- lib/rubypython/pythonexec.rb
|
122
156
|
- lib/rubypython/rubypyproxy.rb
|
123
|
-
- lib/rubypython/
|
157
|
+
- lib/rubypython/type.rb
|
158
|
+
- spec/basic_spec.rb
|
124
159
|
- spec/callback_spec.rb
|
125
160
|
- spec/conversion_spec.rb
|
126
161
|
- spec/legacy_spec.rb
|
127
162
|
- spec/pymainclass_spec.rb
|
128
163
|
- spec/pyobject_spec.rb
|
164
|
+
- spec/python_helpers/basics.py
|
129
165
|
- spec/python_helpers/objects.py
|
130
|
-
- spec/python_helpers/objects.pyc
|
131
166
|
- spec/pythonerror_spec.rb
|
132
167
|
- spec/refcnt_spec.rb
|
133
168
|
- spec/rubypyclass_spec.rb
|
134
169
|
- spec/rubypyproxy_spec.rb
|
135
170
|
- spec/rubypython_spec.rb
|
136
171
|
- spec/spec_helper.rb
|
137
|
-
|
138
|
-
|
172
|
+
- .gemtest
|
173
|
+
has_rdoc: true
|
174
|
+
homepage:
|
139
175
|
licenses: []
|
140
176
|
|
141
|
-
post_install_message:
|
142
|
-
A number of things have changed with version 0.3.0. If you are upgrading from a previous version of RubyPython, you should check the docs for instructions on how to get your code working with the new version of RubyPython.
|
143
|
-
|
144
|
-
For more information on RubyPython, see http://raineszm.bitbucket.org/rubypython/index.html
|
145
|
-
|
146
|
-
If you find a bug, or have any suggestions, email me at: raineszm+rubypython@gmail.com
|
147
|
-
|
148
|
-
If you would like to help develop RubyPython, also send me an email.
|
149
|
-
|
150
|
-
|
177
|
+
post_install_message:
|
151
178
|
rdoc_options:
|
152
|
-
- --
|
153
|
-
-
|
154
|
-
- --title
|
155
|
-
- RubyPython Documentation
|
156
|
-
- --quiet
|
179
|
+
- --main
|
180
|
+
- README.rdoc
|
157
181
|
require_paths:
|
158
182
|
- lib
|
159
183
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -175,11 +199,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
199
|
- 0
|
176
200
|
version: "0"
|
177
201
|
requirements:
|
178
|
-
- Python, ~>2.4
|
202
|
+
- Python, ~> 2.4
|
179
203
|
rubyforge_project: rubypython
|
180
|
-
rubygems_version: 1.
|
204
|
+
rubygems_version: 1.5.2
|
181
205
|
signing_key:
|
182
206
|
specification_version: 3
|
183
|
-
summary:
|
207
|
+
summary: RubyPython is a bridge between the Ruby and Python interpreters
|
184
208
|
test_files: []
|
185
209
|
|