rubypython 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/.autotest
ADDED
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/.hgignore
ADDED
data/.hgtags
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
910a6e5ac94959fd6d9b04caea995afd354531f6 v0.2.3
|
2
|
+
7361975ce7bbbdd284e1d9f84344d4f8df6e9eab v0.2.8
|
3
|
+
09e65f05148ae3e1ba5f54156cd7bcf159cfe14f v0.2.9
|
4
|
+
7ebd15a009f37aefab52e8e669080eed165320a0 v0.2.10
|
5
|
+
fe1fe7136461a92e4012cd7c8f23c8c446d4fbc1 v0.2.11
|
6
|
+
746fffb7ee3db61278d592c303939daeb6a17a03 v0.3.1
|
7
|
+
e61cfeb18e14c8d0d86e68459bf7957535c4452b v0.3.2
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--colour
|
2
|
-
--format
|
2
|
+
--format documentation
|
data/Contributors.rdoc
ADDED
data/History.rdoc
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
=== 0.5.0 / 2011-03-dd
|
2
|
+
* Major Enhancements:
|
3
|
+
* Procs and methods can be passed to Python. [raineszm]
|
4
|
+
* Python to Ruby inheritance: A Ruby class can inherit from a Python class
|
5
|
+
(EXPERIMENTAL). [steeve]
|
6
|
+
* The Python library can now be reloaded (EXPERIMENTAL). There is a good
|
7
|
+
chance of a segfault if this is used with a native extension. [raineszm]
|
8
|
+
* Python functions and methods can be called with a terminal exclamation
|
9
|
+
point to enable keyword argument processing in Python (EXPERIMENTAL). [tmm1]
|
10
|
+
* Minor Enhancements:
|
11
|
+
* Improved Python generator support. [steeve]
|
12
|
+
* PythonError now inherits from RuntimeError. [halostatue]
|
13
|
+
* Added a Py_REFCNT macro for debugging reference counting. [tmm1]
|
14
|
+
* Changes:
|
15
|
+
* Moved to RSpec2. [halostatue]
|
16
|
+
* Moved Rakefile to hoe; added autotest. [halostatue]
|
17
|
+
* Bug Fixes:
|
18
|
+
* Fixed a reference counting bug that could crash the Python VM. [steeve]
|
19
|
+
* Fixed a memory leak/reference counting bug related to method invocation
|
20
|
+
(when turning the argument list into a tuple, PyList_SetItem steals
|
21
|
+
references). Depends on FFI 1.0.7 (or higher) with modifications to
|
22
|
+
aggressively free temporary Python objects created. [tmm1]
|
23
|
+
* Restored Ruby 1.8.7 compatibility where possible. [halostatue]
|
24
|
+
* Fixed FFI loader to be more robust and do more through FFI. [halostatue]
|
25
|
+
* Fixed documentation errors. [halostatue]
|
26
|
+
* Project Management:
|
27
|
+
* Rupy has been merged back into RubyPython.
|
28
|
+
* Made the project website on RubyForge generatable from the readme and a
|
29
|
+
template. Adopted the 960 grid system and modern CSS techniques.
|
30
|
+
* Added a contributors document.
|
31
|
+
|
32
|
+
=== 0.4.1 / / 2011-01-10
|
33
|
+
* Rupy was created as an active fork of Zach Raines's RubyPython and released
|
34
|
+
indepdently.
|
35
|
+
* Major Enhancements:
|
36
|
+
* Python/Ruby callbacks [steeve]
|
37
|
+
* Virtualenv support [steeve]
|
38
|
+
* Python-style generators with Ruby (generators only work on Ruby 1.9).
|
39
|
+
[steeve]
|
40
|
+
|
41
|
+
=== 0.3.2 / 2011-02-02
|
42
|
+
* Major Enhancements
|
43
|
+
* Allow procs and methods to be passed to Ruby.
|
44
|
+
* Allow configuration of the loaded Python library.
|
45
|
+
|
46
|
+
=== 0.3.1 / 2011-01-19
|
47
|
+
* Compatability Updates
|
48
|
+
* Cleanup of code which finds Python library thanks to Austin Ziegler.
|
49
|
+
|
50
|
+
=== 0.3.0 / 2010-09-06
|
51
|
+
* Major Enhancements
|
52
|
+
* Version 0.3.0 represents an almost complete rewrite of the RubyPython
|
53
|
+
codebase.
|
54
|
+
* A native C extension is no longer required. RubyPython uses the 'ffi' gem.
|
55
|
+
* RubyPython by default now returns proxy instances for all Ruby objects. See
|
56
|
+
the documentation for more information.
|
57
|
+
* Compatibility Updates
|
58
|
+
* Version 0.3.0 was created with the goal of being compatible with as many
|
59
|
+
Ruby versions as possible. It should at the very least run on MRI 1.8.6 -
|
60
|
+
1.9.1.
|
61
|
+
* A legacy mode option has been added to provide partial compatibility with
|
62
|
+
version 0.2.x.
|
63
|
+
|
64
|
+
=== 0.2.11 / 2010-07-12
|
65
|
+
* Bug Fixes
|
66
|
+
* Fixed some issues with building the extension under ruby 1.9. Should now be
|
67
|
+
truly 1.9 compatible.
|
68
|
+
|
69
|
+
=== 0.2.10 / 2010-07-08
|
70
|
+
* Bug Fixes
|
71
|
+
* Made some changes to how the native extension is configured and build.
|
72
|
+
|
73
|
+
=== 0.2.9 / 2009-10-19
|
74
|
+
* Minor Enhancements
|
75
|
+
* Updated the C code to make it cleaner, more readable, and more
|
76
|
+
maintainable.
|
77
|
+
|
78
|
+
=== 0.2.8 / 2009-10-05
|
79
|
+
* Bug Fixes
|
80
|
+
* Some test files were improperly formatted (minor bug fix).
|
81
|
+
|
82
|
+
=== 0.2.7 / 2009-3-30
|
83
|
+
* Bug Fixes
|
84
|
+
* Fixed some bugs which caused rubypython to be unable to determine python
|
85
|
+
version correctly.
|
86
|
+
|
87
|
+
=== 0.2.6 / 2009-3-19
|
88
|
+
* Bug Fixes
|
89
|
+
* Further updates to increase compatibility with 1.9.
|
90
|
+
|
91
|
+
=== 0.2.5 / 2009-3-18
|
92
|
+
* Bug Fixes
|
93
|
+
* Updated to build and run under Ruby 1.9.
|
94
|
+
|
95
|
+
=== 0.2.4 / 2008-10-24
|
96
|
+
* Major Enhancements
|
97
|
+
* Provided setter methods for object attributes. Python object attributes can
|
98
|
+
now be set from within ruby.
|
99
|
+
* Made wrapper classes a subclass of custom made blank object class to try to
|
100
|
+
avoid name collisions.
|
101
|
+
* Bug Fix
|
102
|
+
* Changed part of extconf.rb file that would not work under windows.
|
103
|
+
|
104
|
+
=== 0.2.3 / 2008-08-29
|
105
|
+
* 2 Major Enhancements
|
106
|
+
* Introduced PyMain object as a singleton wrapper for the Python __main__ and
|
107
|
+
__builtin__ modules.
|
108
|
+
* Introduced block functionality for PyMain object.
|
109
|
+
* Compatibility Updates
|
110
|
+
* Changed some declarations in the C code to make RubyPython more compatible
|
111
|
+
with the style conventions of the Ruby C API.
|
112
|
+
* Update how RubyPython locates the Python headers and library.
|
113
|
+
* 1 Bug Fix
|
114
|
+
* Fixed an error in ptor.c that might have prevented RubyPython from building
|
115
|
+
correctly on certain systems.
|
116
|
+
|
117
|
+
=== 0.2.2 / 2008-08-07
|
118
|
+
* Major Enhancements
|
119
|
+
* Wrapped classes and instances should now behave as expected.
|
120
|
+
* Gave RubyPyClasses a "new" method for creating instances.
|
121
|
+
* Callable class can now be called provided that at least one argument is
|
122
|
+
given.
|
123
|
+
* A wrapped object's respond_to? method now has some relation to its actual
|
124
|
+
methods.
|
125
|
+
* Bug fixes
|
126
|
+
* Fixed bug with inspect method of RubyPyObject that caused a bus error when
|
127
|
+
inspecting certain objects
|
128
|
+
|
129
|
+
=== 0.2.1 / 2008-08-02
|
130
|
+
* 1 Bug Fix
|
131
|
+
* Incorrect require fixed
|
132
|
+
|
133
|
+
=== 0.2.0 / 2008-08-02
|
134
|
+
* 3 major enhancements
|
135
|
+
* RubyPython can now effectively convert or wrap most types from Python.
|
136
|
+
* Errors in the Python interpreter are relayed to Ruby errors.
|
137
|
+
* Less seg faults by mass.
|
138
|
+
* Bug Fixes
|
139
|
+
* RubyPython.run did not work correctly. This is fixed now.
|
140
|
+
* Cleanup in RubyPython.stop fixes some issues in RubyPythonBridge.stop
|
141
|
+
|
142
|
+
=== 0.1.0 / 2008-08-01
|
143
|
+
* A lot of major enhancements
|
144
|
+
* Too many to name. Hey I'm still developing
|
145
|
+
|
146
|
+
=== 0.0.1 / 2008-07-30
|
147
|
+
* 1 major enhancement:
|
148
|
+
* Initial release
|
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
== License
|
2
|
+
|
3
|
+
This software is available under the terms of the MIT license.
|
4
|
+
|
5
|
+
* Copyright 2011 Zach Raines, Steeve Morin, Austin Ziegler, and other
|
6
|
+
contributors.
|
7
|
+
* Copyright 2008–2010 Zach Raines.
|
2
8
|
|
3
9
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
10
|
a copy of this software and associated documentation files (the
|
data/Manifest.txt
CHANGED
@@ -1,34 +1,39 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
.autotest
|
2
|
+
.gitignore
|
3
|
+
.hgignore
|
4
|
+
.hgtags
|
5
|
+
.rspec
|
6
|
+
Contributors.rdoc
|
7
|
+
History.rdoc
|
8
|
+
License.rdoc
|
3
9
|
Manifest.txt
|
4
10
|
PostInstall.txt
|
5
|
-
README.
|
11
|
+
README.rdoc
|
6
12
|
Rakefile
|
7
|
-
.
|
8
|
-
lib/rubypython
|
13
|
+
autotest/discover.rb
|
9
14
|
lib/rubypython.rb
|
10
15
|
lib/rubypython/blankobject.rb
|
11
16
|
lib/rubypython/conversion.rb
|
12
|
-
lib/rubypython/core_ext
|
13
|
-
lib/rubypython/core_ext/string.rb
|
14
17
|
lib/rubypython/legacy.rb
|
15
18
|
lib/rubypython/macros.rb
|
16
19
|
lib/rubypython/operators.rb
|
17
20
|
lib/rubypython/options.rb
|
21
|
+
lib/rubypython/pygenerator.rb
|
18
22
|
lib/rubypython/pymainclass.rb
|
19
23
|
lib/rubypython/pyobject.rb
|
20
24
|
lib/rubypython/python.rb
|
21
25
|
lib/rubypython/pythonerror.rb
|
26
|
+
lib/rubypython/pythonexec.rb
|
22
27
|
lib/rubypython/rubypyproxy.rb
|
23
|
-
lib/rubypython/
|
28
|
+
lib/rubypython/type.rb
|
29
|
+
spec/basic_spec.rb
|
24
30
|
spec/callback_spec.rb
|
25
31
|
spec/conversion_spec.rb
|
26
32
|
spec/legacy_spec.rb
|
27
33
|
spec/pymainclass_spec.rb
|
28
34
|
spec/pyobject_spec.rb
|
29
|
-
spec/python_helpers
|
35
|
+
spec/python_helpers/basics.py
|
30
36
|
spec/python_helpers/objects.py
|
31
|
-
spec/python_helpers/objects.pyc
|
32
37
|
spec/pythonerror_spec.rb
|
33
38
|
spec/refcnt_spec.rb
|
34
39
|
spec/rubypyclass_spec.rb
|
data/PostInstall.txt
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
1
|
+
RubyPython version 0.3 and higher are different than RubyPython through
|
2
|
+
version 0.2.x. If you're upgrading from such an earlier version, make sure you
|
3
|
+
read the documents for instructions on how your code needs to change to work
|
4
|
+
with modern RubyPython.
|
2
5
|
|
3
|
-
For more information on RubyPython, see http://
|
6
|
+
For more information on RubyPython, see: http://rubypython.rubyforge.org/
|
4
7
|
|
5
|
-
If you find a bug, or have any suggestions,
|
8
|
+
If you find a bug, or have any suggestions, please feel free to enter them on
|
9
|
+
the tracker:
|
6
10
|
|
7
|
-
|
11
|
+
https://bitbucket.org/raineszm/rubypython/issues?status=new&status=open
|
8
12
|
|
13
|
+
If you would like to help develop RubyPython, please check out the source on
|
14
|
+
Bitbucket:
|
9
15
|
|
16
|
+
https://bitbucket.org/raineszm/rubypython/
|
data/README.rdoc
ADDED
@@ -0,0 +1,272 @@
|
|
1
|
+
= rubypython
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
RubyPython is a bridge between the Ruby and Python interpreters. It embeds a
|
6
|
+
running Python interpreter in the Ruby application's process using FFI and
|
7
|
+
provides a means for wrapping, converting, and calling Python objects and
|
8
|
+
methods.
|
9
|
+
|
10
|
+
RubyPython uses FFI to marshal the data between the Ruby and Python VMs and
|
11
|
+
make Python calls. You can:
|
12
|
+
|
13
|
+
* Inherit from Python classes.
|
14
|
+
* Configure callbacks from Python.
|
15
|
+
* Run Python generators (on Ruby 1.9.2 or later).
|
16
|
+
|
17
|
+
== Where
|
18
|
+
|
19
|
+
* {RubyForge}[http://rubypython.rubyforge.org/]
|
20
|
+
* {RubyGems}[http://rubygems.org/gems/rubypython]
|
21
|
+
* {Bitbucket}[http://raineszm.bitbucket.org/rubypython/]
|
22
|
+
* {GitHub}[https://github.com/halostatue/rubypython]
|
23
|
+
|
24
|
+
The RubyPython homepage, project description, and main downloads can be found
|
25
|
+
on {RubyForge}[http://rubypython.rubyforge.org/].
|
26
|
+
|
27
|
+
Source is kept in sync between
|
28
|
+
{Bitbucket}[http://raineszm.bitbucket.org/rubypython/] and
|
29
|
+
{GitHub}[https://github.com/halostatue/rubypython], but the Bitbucket
|
30
|
+
repository is the canonical repository and where the {issue
|
31
|
+
tracker}[https://bitbucket.org/raineszm/rubypython/issues?status=new&status=open]
|
32
|
+
resides. We use {Hg-Git}[http://hg-git.github.com/] to keep the two
|
33
|
+
repositories in sync.
|
34
|
+
|
35
|
+
== Synopsis
|
36
|
+
|
37
|
+
RubyPython is fairly easy to start using; there are three phases to its use:
|
38
|
+
|
39
|
+
1. Start the Python interpreter (+RubyPython.start+).
|
40
|
+
2. Import and use Python code (+RubyPython.import+).
|
41
|
+
3. Stop the Python interpreter (+RubyPython.stop+).
|
42
|
+
|
43
|
+
There are also two methods, +RubyPython.session+ and +RubyPython.run+ that will
|
44
|
+
start before running the code provided in the block and stop it afterwards.
|
45
|
+
|
46
|
+
=== Basic Usage
|
47
|
+
|
48
|
+
require "rubypython"
|
49
|
+
|
50
|
+
RubyPython.start # start the Python interpreter
|
51
|
+
|
52
|
+
cPickle = RubyPython.import("cPickle")
|
53
|
+
p cPickle.dumps("Testing RubyPython.").rubify
|
54
|
+
|
55
|
+
RubyPython.stop # stop the Python interpreter
|
56
|
+
|
57
|
+
=== Specific Python Version
|
58
|
+
|
59
|
+
require "rubypython"
|
60
|
+
|
61
|
+
RubyPython.start(:python_exe => "python2.7") # Can also be a full path
|
62
|
+
|
63
|
+
cPickle = RubyPython.import("cPickle")
|
64
|
+
p cPickle.dumps("Testing RubyPython.").rubify
|
65
|
+
|
66
|
+
RubyPython.stop # stop the Python interpreter
|
67
|
+
|
68
|
+
=== VirtualEnv
|
69
|
+
|
70
|
+
# Easy
|
71
|
+
RubyPython.start_from_virtualenv("/path/to/virtualenv")
|
72
|
+
|
73
|
+
# Or verbose
|
74
|
+
RubyPython.start(:python => "/path/to/virtualenv/bin/python")
|
75
|
+
RubyPython.activate
|
76
|
+
|
77
|
+
=== Iterator support
|
78
|
+
|
79
|
+
# Python
|
80
|
+
def readfile():
|
81
|
+
for line in open("/some/file"):
|
82
|
+
yield line
|
83
|
+
|
84
|
+
# Ruby
|
85
|
+
readfile.to_enum.each do |line|
|
86
|
+
puts line
|
87
|
+
end
|
88
|
+
|
89
|
+
# Python
|
90
|
+
def iterate_list():
|
91
|
+
for item in [ 1, 2, 3 ]:
|
92
|
+
yield item
|
93
|
+
|
94
|
+
# Ruby
|
95
|
+
items = []
|
96
|
+
iterate_list.to_enum.each { |item| items << item }
|
97
|
+
puts items == [ 1, 2, 3 ] # => true
|
98
|
+
|
99
|
+
=== Python to Ruby callbacks
|
100
|
+
|
101
|
+
# Python
|
102
|
+
def simple_callback(callback, value):
|
103
|
+
return callback(value)
|
104
|
+
|
105
|
+
# Ruby
|
106
|
+
simple_callback(lambda { |v| v * v }, 4) # => 16
|
107
|
+
|
108
|
+
def triple(v)
|
109
|
+
v * 3
|
110
|
+
end
|
111
|
+
|
112
|
+
simple_callback(method(:triple), 4) # => 12
|
113
|
+
|
114
|
+
=== Python-style Generators
|
115
|
+
|
116
|
+
# Python
|
117
|
+
def test_generator(callback):
|
118
|
+
for i in callback():
|
119
|
+
print "Got %d" % i
|
120
|
+
|
121
|
+
# Ruby 1.9.2 or later
|
122
|
+
test_generator(RubyPython.generator do
|
123
|
+
(0..10).each { |i| RubyPython.yield i }
|
124
|
+
end)
|
125
|
+
|
126
|
+
=== Python named arguments (Experimental)
|
127
|
+
|
128
|
+
This format is experimental and may be changed.
|
129
|
+
|
130
|
+
# Python
|
131
|
+
def foo(arg1, arg2):
|
132
|
+
pass
|
133
|
+
|
134
|
+
# Ruby
|
135
|
+
foo!(:arg2 => "bar2", :arg1 => "bar1")
|
136
|
+
|
137
|
+
# with Ruby 1.9
|
138
|
+
foo!(arg2: "bar2", arg1: "bar1")
|
139
|
+
|
140
|
+
== Features / Problems
|
141
|
+
|
142
|
+
=== Features
|
143
|
+
|
144
|
+
* Simple two-way conversion of built-in types between Ruby and Python.
|
145
|
+
* Python module import and arbitrary method execution.
|
146
|
+
* Python objects can be treated as Ruby objects.
|
147
|
+
* Python's standard library available from within Ruby.
|
148
|
+
* Pass Ruby methods and procs as callbacks and call them from within Python
|
149
|
+
code.
|
150
|
+
* Specify the Python executable to be loaded, including using virtualenv.
|
151
|
+
|
152
|
+
==== Experimental Features
|
153
|
+
|
154
|
+
* Calling Python methods or functions that expect keyword arguments, or call
|
155
|
+
any Python method or function with named parameters.
|
156
|
+
|
157
|
+
# Python
|
158
|
+
def func(a, b, c):
|
159
|
+
pass
|
160
|
+
|
161
|
+
# Ruby
|
162
|
+
func!(:b => 2, :c => 3, :a => 1) # => [ 1, 2, 3 ]
|
163
|
+
|
164
|
+
While we are committed to keeping this feature in place, we have not yet
|
165
|
+
determined that the form (+method!+) is the best way to achieve this
|
166
|
+
functionality.
|
167
|
+
|
168
|
+
This mechanism is experimental because the use of the bang at the end of the
|
169
|
+
method to indicate the use of keyword arguments may not be the best use of
|
170
|
+
that feature of Ruby naming.
|
171
|
+
|
172
|
+
* Changing Python interpreters in a single Ruby program. Under some
|
173
|
+
circumstances, this will partially work. If a native Python extension has
|
174
|
+
been imported (such as +cPickle+), there is a very high likelihood that there
|
175
|
+
will be a segmentation fault because the newly loaded DLL will still refer to
|
176
|
+
the other version's loaded extension. This is not a recommended workflow.
|
177
|
+
|
178
|
+
=== Known Problems
|
179
|
+
|
180
|
+
* Built-in Python methods requiring a top-level frame object (such as eval(),
|
181
|
+
dir(), and the like) do not work properly at present.
|
182
|
+
* There is no support for passing complicated (non-basic) Ruby types to Python.
|
183
|
+
|
184
|
+
== What's planned
|
185
|
+
There are features that are not currently supported in RubyPython that may be
|
186
|
+
considered for future releases, dependent on need, interest, and solutions.
|
187
|
+
|
188
|
+
=== Python 3
|
189
|
+
We do plan on working this, but as none of the projects any of us are working
|
190
|
+
on require Python 3 as of yet, this is not yet started.
|
191
|
+
|
192
|
+
=== Simpler Imports
|
193
|
+
It might be nice to have some nice import helpers provided by RubyPython to
|
194
|
+
make the interface more seamless and provide advanced import features:
|
195
|
+
|
196
|
+
==== Import Aliasing
|
197
|
+
|
198
|
+
# Python
|
199
|
+
from mod2.mod1 import sym as mysym
|
200
|
+
|
201
|
+
# Ruby
|
202
|
+
py :from => "mod2.mod1", :import => "sym", :as => "mysym"
|
203
|
+
py :from => "mod2.mod1", :import => :sym, :as => :mysym
|
204
|
+
py :from => [ :mod2, :mod1 ], :import => :sym, :as => :mysym
|
205
|
+
|
206
|
+
# Python
|
207
|
+
import mod1 as mymod
|
208
|
+
|
209
|
+
# Ruby
|
210
|
+
py :import => "mod1", :as => "mymod"
|
211
|
+
py :import => :mod1, :as => :mymod
|
212
|
+
|
213
|
+
# Python
|
214
|
+
from mod2.mod1 import *
|
215
|
+
|
216
|
+
# Ruby
|
217
|
+
py :from => "mod2.mod1", :import => :*
|
218
|
+
pyrequire "mod2/mod1" # ruby style imports
|
219
|
+
|
220
|
+
=== Catch Exceptions from Ruby
|
221
|
+
|
222
|
+
# Python
|
223
|
+
class MyFirstException(Exception):
|
224
|
+
pass
|
225
|
+
|
226
|
+
class MySecondException(MyFirstException):
|
227
|
+
pass
|
228
|
+
|
229
|
+
def test():
|
230
|
+
raise MySecondException
|
231
|
+
|
232
|
+
# Ruby
|
233
|
+
begin
|
234
|
+
test
|
235
|
+
rescue MyFirstException => e
|
236
|
+
# We may need to work out name collisions
|
237
|
+
puts e.message
|
238
|
+
end
|
239
|
+
|
240
|
+
== Requirements
|
241
|
+
|
242
|
+
* Python >= 2.4, < 3.0
|
243
|
+
* Ruby >= 1.8.6, or JRuby >= 1.6.0
|
244
|
+
* You must either have the ability to build the Ruby
|
245
|
+
{FFI}[https://github.com/ffi/ffi] gem, version 1.0.7 or better in your
|
246
|
+
environment or have a pre-built one that you can install.
|
247
|
+
|
248
|
+
=== Python Support
|
249
|
+
RubyPython has been tested with the C-based Python interpreter (cpython),
|
250
|
+
versions 2.4 through 2.7. Work is planned to enable Python 3 support, but has
|
251
|
+
not yet been started. If you're interested in helping us enable Python 3
|
252
|
+
support, please let us know.
|
253
|
+
|
254
|
+
=== Ruby Support
|
255
|
+
* Ruby 1.8.7 and 1.9.2 (MRI)
|
256
|
+
* JRuby 1.6.0
|
257
|
+
|
258
|
+
It should work with other implementations that support the Ruby FFI gem with no
|
259
|
+
modification.
|
260
|
+
|
261
|
+
=== OS Support
|
262
|
+
RubyPython has been tested on Mac OS 10.5 and 10.6, and Ubuntu 10.10 (64-bit
|
263
|
+
Intel). If your platform has a DLL or shared object version of Python and
|
264
|
+
supports the FFI gem, it should work. Feedback on other platforms is always
|
265
|
+
welcome.
|
266
|
+
|
267
|
+
== Install
|
268
|
+
gem install rubypython
|
269
|
+
|
270
|
+
:include: Contributors.rdoc
|
271
|
+
|
272
|
+
:include: License.rdoc
|