lokeshh_rubypython 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +3 -0
  3. data/.gitignore +18 -0
  4. data/.hgignore +20 -0
  5. data/.hgtags +12 -0
  6. data/.rspec +2 -0
  7. data/Contributors.rdoc +11 -0
  8. data/History.rdoc +214 -0
  9. data/License.rdoc +26 -0
  10. data/Manifest.txt +46 -0
  11. data/PostInstall.txt +16 -0
  12. data/README.rdoc +272 -0
  13. data/Rakefile +118 -0
  14. data/autotest/discover.rb +1 -0
  15. data/lib/rubypython/blankobject.rb +23 -0
  16. data/lib/rubypython/conversion.rb +332 -0
  17. data/lib/rubypython/interpreter.rb +262 -0
  18. data/lib/rubypython/macros.rb +56 -0
  19. data/lib/rubypython/operators.rb +120 -0
  20. data/lib/rubypython/pygenerator.rb +61 -0
  21. data/lib/rubypython/pymainclass.rb +80 -0
  22. data/lib/rubypython/pyobject.rb +189 -0
  23. data/lib/rubypython/python.rb +199 -0
  24. data/lib/rubypython/pythonerror.rb +80 -0
  25. data/lib/rubypython/rubypyproxy.rb +328 -0
  26. data/lib/rubypython/tuple.rb +10 -0
  27. data/lib/rubypython/type.rb +20 -0
  28. data/lib/rubypython.rb +229 -0
  29. data/spec/basic_spec.rb +50 -0
  30. data/spec/callback_spec.rb +53 -0
  31. data/spec/conversion_spec.rb +68 -0
  32. data/spec/pymainclass_spec.rb +24 -0
  33. data/spec/pyobject_spec.rb +202 -0
  34. data/spec/python_helpers/basics.py +23 -0
  35. data/spec/python_helpers/errors.py +2 -0
  36. data/spec/python_helpers/objects.py +48 -0
  37. data/spec/pythonerror_spec.rb +52 -0
  38. data/spec/refcnt_spec.rb +98 -0
  39. data/spec/rubypyclass_spec.rb +10 -0
  40. data/spec/rubypyproxy_spec.rb +261 -0
  41. data/spec/rubypython_spec.rb +59 -0
  42. data/spec/spec_helper.rb +71 -0
  43. data/website/index.rhtml +36 -0
  44. data/website/robots.txt +5 -0
  45. data/website/stylesheets/960.css +549 -0
  46. data/website/stylesheets/border-radius.htc +143 -0
  47. data/website/stylesheets/screen.css +132 -0
  48. metadata +297 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f0665777af943ef082b7e6dbd37a10037226bb6
4
+ data.tar.gz: 353b34f7bf0c5cb0084fb194336a3bc18d756401
5
+ SHA512:
6
+ metadata.gz: c22371a487b107c862c64dce35a6d7703718b7a6e7922dc84b3cfebab3dd6c38062f21da1fc974616814aa44435bf1300948a0adca17a988ef66fdf0a2117ab2
7
+ data.tar.gz: fda0c8641b9e0efe3467eaeab0098a8a994f9abdf18f741642111b318749bf9b17c3e60bfb88b0353a8290d1f336de7741fef2ba480cce75f7a4802a5c13edbb
data/.autotest ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+
3
+ # vim: syntax=ruby
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.bundle
2
+ *.log
3
+ *.o
4
+ *.pyc
5
+ *.so
6
+ *.swp
7
+ *~
8
+ .DS_Store
9
+ .rake_tasks~
10
+ .rvmrc
11
+ .yardoc/
12
+ coverage.info
13
+ coverage/
14
+ doc/
15
+ html/
16
+ pkg/
17
+ publish/
18
+ website/index.html
data/.hgignore ADDED
@@ -0,0 +1,20 @@
1
+ syntax:glob
2
+ *.bundle
3
+ *.log
4
+ *.o
5
+ *.pyc
6
+ *.so
7
+ *.swp
8
+ *~
9
+ .DS_Store
10
+ .rake_tasks~
11
+ .rvmrc
12
+ .yardoc/*
13
+ coverage.info
14
+ coverage/*
15
+ doc/*
16
+ ext/*/Makefile
17
+ html/*
18
+ pkg/*
19
+ publish/*
20
+ website/index.html
data/.hgtags ADDED
@@ -0,0 +1,12 @@
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
8
+ 0e18cecdd4b7d6261a708a9b60b80a4794efac89 r0.5.0
9
+ cd45222e2319bf006798c50f5c18669ae6160246 r0.5.2
10
+ b82963530f976af0cc0f4e62488b5112028fdfc9 r0.5.3
11
+ 4e39510b4683d1394361106ddb387e5b85f18789 r0.6.0
12
+ 898514bedf99296b48fdb95945745ff523ad3b11 r0.6.1
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/Contributors.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ == Contributors
2
+
3
+ RubyPython has a growing list of contributors.
4
+
5
+ * Zach Raines (raineszm)
6
+ * The creator of RubyPython.
7
+ * Steeve Morin (steeve)
8
+ * Austin Ziegler (halostatue)
9
+ * Aman Gupta (tmm1)
10
+ * Ben Doerr (bendoerr)
11
+ * Akzhan Abdulin (azkhan)
data/History.rdoc ADDED
@@ -0,0 +1,214 @@
1
+ === 0.6.4 / 2017-06-20
2
+ * Fix long conversion issue
3
+ * Fix lib path for Debian/Ubuntu
4
+
5
+ === 0.6.4 / 2012-09-25
6
+ * Major Enhancements
7
+ * Legacy Mode removed
8
+ * Minor Enhancements
9
+ * Depend on newer versions of FFI
10
+ * Make RubyPython correctly detect python on archlinux. [madjar]
11
+ * Bug Fixes:
12
+ * Fixed some memory leaks, but still looking for others.
13
+
14
+ === 0.6.2 / 2012-05-24
15
+ * Bug Fixes:
16
+ * Fixed a possible namespace collision bug with the FFI library. [Akzhan]
17
+
18
+ === 0.6.1 / 2012-05-18
19
+ * Bug Fixes:
20
+ * Widened the library naming schemes that RubyPython will search for the Python library. [Akzhan]
21
+ * Better handling of 64-bit systems which also have 32-bit libraries. [Akzhan]
22
+
23
+ === 0.6 / 2012-04-17
24
+ * Major Enhancements:
25
+ * Previous versions of RubyPython theoretically allowed the loading of
26
+ different Python interpreters during a single Ruby session. Because of the
27
+ likelihood of crashes, this functionality has been removed. Now, if you
28
+ attempt to start RubyPython more than once while specifying different
29
+ Python interpreters, RubyPython will print a warning and continue working
30
+ with the already loaded interpreter.
31
+ * The Python interpreter DLL will only be loaded once. It is configured with
32
+ a self-removing method, Interpreter#infect! instead of require/load reload
33
+ hacks.
34
+ * Removed RubyPython.configure; since the interpreter can only be configured
35
+ once, independent configuration no longer makes sense.
36
+ * Minor Enhancements:
37
+ * RubyPython interpreter initialization is done with a Mutex synchronization
38
+ to ensure that only one Python interpreter DLL is loaded.
39
+ * Added RubyPython::Tuple, a simple subclass of ::Array that will correctly
40
+ be converted to a Python tuple object such that isinstance(x, tuple)
41
+ returns True.
42
+ * Renamed RubyPython::PythonExec to RubyPython::Interpreter. Added some
43
+ helper methods to assist with comparison. Construction is with an options
44
+ hash.
45
+ * The #update methods on Python interpreter observers are now private. This
46
+ is an implementation detail, not a public interface. (The methods have also
47
+ been renamed to #python_interpreter_update.)
48
+ * Deprecation:
49
+ * RubyPython's legacy mode (automatic unboxing of Python proxy objects where
50
+ possible) has been deprecated and will be removed in the next non-bugfix
51
+ release after this version. Introduced a new private method
52
+ (RubyPython.legacy_mode?) to check if legacy mode is turned on so that the
53
+ deprecation warning is not printed in all uses of RubyPython.
54
+
55
+ === 0.5.3 / 2011-10-22
56
+ * Bug Fixes:
57
+ * Improved 64-bit Python detection on Unixes with Linux-like semantics (e.g.,
58
+ .../lib64). Resolves issue #7 on bitbucket.
59
+
60
+ === 0.5.2 / 2011-10-21
61
+ * Minor Enhancements:
62
+ * The traceback for Python exceptions is now returned usefully. [raineszm]
63
+ * Bug Fixes:
64
+ * Improved the robustness of Windows DLL detection. Based on work by
65
+ bendoerr, raineszm, and halostatue.
66
+
67
+ === 0.5.1 / 2011-03-17
68
+ * Major Enhancements:
69
+ * Procs and methods can be passed to Python. [raineszm]
70
+ * Python to Ruby inheritance: A Ruby class can inherit from a Python class
71
+ (EXPERIMENTAL). [steeve]
72
+ * The Python library can now be reloaded (EXPERIMENTAL). There is a good
73
+ chance of a segfault if this is used with a native extension. [raineszm]
74
+ * Python functions and methods can be called with a terminal exclamation
75
+ point to enable keyword argument processing in Python (EXPERIMENTAL). [tmm1]
76
+ * Minor Enhancements:
77
+ * Improved Python generator support. [steeve]
78
+ * PythonError now inherits from RuntimeError. [halostatue]
79
+ * Added a Py_REFCNT macro for debugging reference counting. [tmm1]
80
+ * Changes:
81
+ * Moved to RSpec2. [halostatue]
82
+ * Moved Rakefile to hoe; added autotest. [halostatue]
83
+ * Bug Fixes:
84
+ * Fixed a reference counting bug that could crash the Python VM. [steeve]
85
+ * Fixed a memory leak/reference counting bug related to method invocation
86
+ (when turning the argument list into a tuple, PyList_SetItem steals
87
+ references). Depends on FFI 1.0.7 (or higher) with modifications to
88
+ aggressively free temporary Python objects created. [tmm1]
89
+ * Restored Ruby 1.8.7 compatibility where possible. [halostatue]
90
+ * Fixed FFI loader to be more robust and do more through FFI. [halostatue]
91
+ * Fixed documentation errors. [halostatue]
92
+ * Project Management:
93
+ * Rupy has been merged back into RubyPython.
94
+ * Made the project website on RubyForge generatable from the readme and a
95
+ template. Adopted the 960 grid system and modern CSS techniques.
96
+ * Added a contributors document.
97
+
98
+ === 0.4.1 / / 2011-01-10
99
+ * Rupy was created as an active fork of Zach Raines's RubyPython and released
100
+ indepdently.
101
+ * Major Enhancements:
102
+ * Python/Ruby callbacks [steeve]
103
+ * Virtualenv support [steeve]
104
+ * Python-style generators with Ruby (generators only work on Ruby 1.9).
105
+ [steeve]
106
+
107
+ === 0.3.2 / 2011-02-02
108
+ * Major Enhancements
109
+ * Allow procs and methods to be passed to Ruby.
110
+ * Allow configuration of the loaded Python library.
111
+
112
+ === 0.3.1 / 2011-01-19
113
+ * Compatability Updates
114
+ * Cleanup of code which finds Python library thanks to Austin Ziegler.
115
+
116
+ === 0.3.0 / 2010-09-06
117
+ * Major Enhancements
118
+ * Version 0.3.0 represents an almost complete rewrite of the RubyPython
119
+ codebase.
120
+ * A native C extension is no longer required. RubyPython uses the 'ffi' gem.
121
+ * RubyPython by default now returns proxy instances for all Ruby objects. See
122
+ the documentation for more information.
123
+ * Compatibility Updates
124
+ * Version 0.3.0 was created with the goal of being compatible with as many
125
+ Ruby versions as possible. It should at the very least run on MRI 1.8.6 -
126
+ 1.9.1.
127
+ * A legacy mode option has been added to provide partial compatibility with
128
+ version 0.2.x.
129
+
130
+ === 0.2.11 / 2010-07-12
131
+ * Bug Fixes
132
+ * Fixed some issues with building the extension under ruby 1.9. Should now be
133
+ truly 1.9 compatible.
134
+
135
+ === 0.2.10 / 2010-07-08
136
+ * Bug Fixes
137
+ * Made some changes to how the native extension is configured and build.
138
+
139
+ === 0.2.9 / 2009-10-19
140
+ * Minor Enhancements
141
+ * Updated the C code to make it cleaner, more readable, and more
142
+ maintainable.
143
+
144
+ === 0.2.8 / 2009-10-05
145
+ * Bug Fixes
146
+ * Some test files were improperly formatted (minor bug fix).
147
+
148
+ === 0.2.7 / 2009-3-30
149
+ * Bug Fixes
150
+ * Fixed some bugs which caused rubypython to be unable to determine python
151
+ version correctly.
152
+
153
+ === 0.2.6 / 2009-3-19
154
+ * Bug Fixes
155
+ * Further updates to increase compatibility with 1.9.
156
+
157
+ === 0.2.5 / 2009-3-18
158
+ * Bug Fixes
159
+ * Updated to build and run under Ruby 1.9.
160
+
161
+ === 0.2.4 / 2008-10-24
162
+ * Major Enhancements
163
+ * Provided setter methods for object attributes. Python object attributes can
164
+ now be set from within ruby.
165
+ * Made wrapper classes a subclass of custom made blank object class to try to
166
+ avoid name collisions.
167
+ * Bug Fix
168
+ * Changed part of extconf.rb file that would not work under windows.
169
+
170
+ === 0.2.3 / 2008-08-29
171
+ * 2 Major Enhancements
172
+ * Introduced PyMain object as a singleton wrapper for the Python __main__ and
173
+ __builtin__ modules.
174
+ * Introduced block functionality for PyMain object.
175
+ * Compatibility Updates
176
+ * Changed some declarations in the C code to make RubyPython more compatible
177
+ with the style conventions of the Ruby C API.
178
+ * Update how RubyPython locates the Python headers and library.
179
+ * 1 Bug Fix
180
+ * Fixed an error in ptor.c that might have prevented RubyPython from building
181
+ correctly on certain systems.
182
+
183
+ === 0.2.2 / 2008-08-07
184
+ * Major Enhancements
185
+ * Wrapped classes and instances should now behave as expected.
186
+ * Gave RubyPyClasses a "new" method for creating instances.
187
+ * Callable class can now be called provided that at least one argument is
188
+ given.
189
+ * A wrapped object's respond_to? method now has some relation to its actual
190
+ methods.
191
+ * Bug fixes
192
+ * Fixed bug with inspect method of RubyPyObject that caused a bus error when
193
+ inspecting certain objects
194
+
195
+ === 0.2.1 / 2008-08-02
196
+ * 1 Bug Fix
197
+ * Incorrect require fixed
198
+
199
+ === 0.2.0 / 2008-08-02
200
+ * 3 major enhancements
201
+ * RubyPython can now effectively convert or wrap most types from Python.
202
+ * Errors in the Python interpreter are relayed to Ruby errors.
203
+ * Less seg faults by mass.
204
+ * Bug Fixes
205
+ * RubyPython.run did not work correctly. This is fixed now.
206
+ * Cleanup in RubyPython.stop fixes some issues in RubyPythonBridge.stop
207
+
208
+ === 0.1.0 / 2008-08-01
209
+ * A lot of major enhancements
210
+ * Too many to name. Hey I'm still developing
211
+
212
+ === 0.0.1 / 2008-07-30
213
+ * 1 major enhancement:
214
+ * Initial release
data/License.rdoc ADDED
@@ -0,0 +1,26 @@
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.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining
10
+ a copy of this software and associated documentation files (the
11
+ "Software"), to deal in the Software without restriction, including
12
+ without limitation the rights to use, copy, modify, merge, publish,
13
+ distribute, sublicense, and/or sell copies of the Software, and to
14
+ permit persons to whom the Software is furnished to do so, subject to
15
+ the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be
18
+ included in all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,46 @@
1
+ .autotest
2
+ .gitignore
3
+ .hgignore
4
+ .hgtags
5
+ .rspec
6
+ Contributors.rdoc
7
+ History.rdoc
8
+ License.rdoc
9
+ Manifest.txt
10
+ PostInstall.txt
11
+ README.rdoc
12
+ Rakefile
13
+ autotest/discover.rb
14
+ lib/rubypython.rb
15
+ lib/rubypython/blankobject.rb
16
+ lib/rubypython/conversion.rb
17
+ lib/rubypython/interpreter.rb
18
+ lib/rubypython/macros.rb
19
+ lib/rubypython/operators.rb
20
+ lib/rubypython/pygenerator.rb
21
+ lib/rubypython/pymainclass.rb
22
+ lib/rubypython/pyobject.rb
23
+ lib/rubypython/python.rb
24
+ lib/rubypython/pythonerror.rb
25
+ lib/rubypython/rubypyproxy.rb
26
+ lib/rubypython/tuple.rb
27
+ lib/rubypython/type.rb
28
+ spec/basic_spec.rb
29
+ spec/callback_spec.rb
30
+ spec/conversion_spec.rb
31
+ spec/pymainclass_spec.rb
32
+ spec/pyobject_spec.rb
33
+ spec/python_helpers/basics.py
34
+ spec/python_helpers/errors.py
35
+ spec/python_helpers/objects.py
36
+ spec/pythonerror_spec.rb
37
+ spec/refcnt_spec.rb
38
+ spec/rubypyclass_spec.rb
39
+ spec/rubypyproxy_spec.rb
40
+ spec/rubypython_spec.rb
41
+ spec/spec_helper.rb
42
+ website/index.rhtml
43
+ website/robots.txt
44
+ website/stylesheets/960.css
45
+ website/stylesheets/border-radius.htc
46
+ website/stylesheets/screen.css
data/PostInstall.txt ADDED
@@ -0,0 +1,16 @@
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.
5
+
6
+ For more information on RubyPython, see: http://rubypython.rubyforge.org/
7
+
8
+ If you find a bug, or have any suggestions, please feel free to enter them on
9
+ the tracker:
10
+
11
+ https://bitbucket.org/raineszm/rubypython/issues?status=new&status=open
12
+
13
+ If you would like to help develop RubyPython, please check out the source on
14
+ Bitbucket:
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_exe => "/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 extensively tested on Mac OS 10.5 and 10.6, and Ubuntu
263
+ 10.10 (64-bit Intel). If your platform has a DLL or shared object version of
264
+ Python and supports the FFI gem, it should work. Feedback on other platforms is
265
+ always welcome.
266
+
267
+ == Install
268
+ gem install rubypython
269
+
270
+ :include: Contributors.rdoc
271
+
272
+ :include: License.rdoc