rubypython 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.autotest +9 -0
  2. data/History.txt +17 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +45 -0
  5. data/PostInstall.txt +6 -0
  6. data/README.txt +56 -0
  7. data/Rakefile +4 -0
  8. data/config/hoe.rb +73 -0
  9. data/config/requirements.rb +16 -0
  10. data/ext/rubypython_bridge/cbridge.c +149 -0
  11. data/ext/rubypython_bridge/cbridge.h +25 -0
  12. data/ext/rubypython_bridge/config.h +14 -0
  13. data/ext/rubypython_bridge/extconf.rb +7 -0
  14. data/ext/rubypython_bridge/ptor.c +178 -0
  15. data/ext/rubypython_bridge/ptor.h +31 -0
  16. data/ext/rubypython_bridge/rp_error.c +23 -0
  17. data/ext/rubypython_bridge/rp_error.h +8 -0
  18. data/ext/rubypython_bridge/rp_object.c +237 -0
  19. data/ext/rubypython_bridge/rp_object.h +46 -0
  20. data/ext/rubypython_bridge/rtop.c +151 -0
  21. data/ext/rubypython_bridge/rtop.h +22 -0
  22. data/ext/rubypython_bridge/rubypython_bridge.c +100 -0
  23. data/ext/rubypython_bridge/rubypython_bridge.h +7 -0
  24. data/ext/rubypython_bridge/test.rb +25 -0
  25. data/lib/rubypython.rb +84 -0
  26. data/lib/rubypython/version.rb +9 -0
  27. data/lib/rubypython/wrapper_extensions.rb +34 -0
  28. data/script/console +10 -0
  29. data/script/destroy +14 -0
  30. data/script/generate +14 -0
  31. data/script/txt2html +82 -0
  32. data/setup.rb +1585 -0
  33. data/tasks/deployment.rake +34 -0
  34. data/tasks/environment.rake +7 -0
  35. data/tasks/extconf.rake +13 -0
  36. data/tasks/extconf/rubypython_bridge.rake +49 -0
  37. data/tasks/website.rake +17 -0
  38. data/test/test_helper.rb +2 -0
  39. data/test/test_rubypython.rb +57 -0
  40. data/test/test_rubypython_bridge_extn.rb +31 -0
  41. data/website/index.html +83 -0
  42. data/website/index.txt +77 -0
  43. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  44. data/website/stylesheets/screen.css +138 -0
  45. data/website/template.html.erb +48 -0
  46. metadata +113 -0
data/.autotest ADDED
@@ -0,0 +1,9 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.add_mapping(/ext\/.*\/(.*)\.[ch]/) do |_, m|
3
+ ["test/test_#{m[1]}_extn.rb"]
4
+ end
5
+ end
6
+
7
+ Autotest.add_hook :run_command do |at|
8
+ system "rake compile"
9
+ end
data/History.txt ADDED
@@ -0,0 +1,17 @@
1
+ == 0.2.0 2008-08-02
2
+ * 3 major enhancements
3
+ * RubyPython can now effectively convert or wrap most types from Python.
4
+ * Errors in the Python interpreter are relayed to Ruby errors.
5
+ * Less seg faults by mass.
6
+ * Bug Fixes
7
+ * RubyPython.run did not work correctly. This is fixed now.
8
+ * Cleanup in RubyPython.stop fixes some issues in RubyPythonBridge.stop
9
+
10
+ == 0.1.0 2008-08-01
11
+ * A lot of major enhancements
12
+ * Too many to name. Hey I'm still developing
13
+
14
+ == 0.0.1 2008-07-30
15
+
16
+ * 1 major enhancement:
17
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,45 @@
1
+ .autotest
2
+ History.txt
3
+ License.txt
4
+ Manifest.txt
5
+ PostInstall.txt
6
+ README.txt
7
+ Rakefile
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ ext/rubypython_bridge/cbridge.c
11
+ ext/rubypython_bridge/cbridge.h
12
+ ext/rubypython_bridge/config.h
13
+ ext/rubypython_bridge/extconf.rb
14
+ ext/rubypython_bridge/ptor.c
15
+ ext/rubypython_bridge/ptor.h
16
+ ext/rubypython_bridge/rp_error.c
17
+ ext/rubypython_bridge/rp_error.h
18
+ ext/rubypython_bridge/rp_object.c
19
+ ext/rubypython_bridge/rp_object.h
20
+ ext/rubypython_bridge/rtop.c
21
+ ext/rubypython_bridge/rtop.h
22
+ ext/rubypython_bridge/rubypython_bridge.c
23
+ ext/rubypython_bridge/rubypython_bridge.h
24
+ ext/rubypython_bridge/test.rb
25
+ lib/rubypython.rb
26
+ lib/rubypython/version.rb
27
+ lib/rubypython/wrapper_extensions.rb
28
+ script/console
29
+ script/destroy
30
+ script/generate
31
+ script/txt2html
32
+ setup.rb
33
+ tasks/deployment.rake
34
+ tasks/environment.rake
35
+ tasks/extconf.rake
36
+ tasks/extconf/rubypython_bridge.rake
37
+ tasks/website.rake
38
+ test/test_helper.rb
39
+ test/test_rubypython.rb
40
+ test/test_rubypython_bridge_extn.rb
41
+ website/index.html
42
+ website/index.txt
43
+ website/javascripts/rounded_corners_lite.inc.js
44
+ website/stylesheets/screen.css
45
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,6 @@
1
+
2
+ For more information on rubypython, see http://rubypython.rubyforge.org
3
+
4
+ If you find a bug, or have any suggestions, email me at: achatesavc+rubypython@gmail.com
5
+
6
+
data/README.txt ADDED
@@ -0,0 +1,56 @@
1
+ = rubypython
2
+
3
+ * htp://rubypython.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ RubyPython is a a C bridge between ruby and python with a ruby interface.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Features:
12
+ * Can handle simple conversion of Python builtin types to ruby builtin types and vice versa
13
+ * Can import python modules
14
+ * Can execute arbitrary methods on imported modules and return the result
15
+ * Python objects can be treated as Ruby objects!
16
+
17
+ Problems:
18
+ * Issues with the run method
19
+
20
+ == SYNOPSIS:
21
+ RubyPython.start
22
+ cPickle=RubyPython.import("cPickle")
23
+ p cPickle.dumps("RubyPython is awesome!")
24
+ RubyPython.stop
25
+
26
+ == REQUIREMENTS:
27
+
28
+
29
+ == INSTALL:
30
+
31
+ sudo gem install rubypython
32
+
33
+ == LICENSE:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2008 Zach Raines
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'rubypython/version'
2
+
3
+ AUTHOR = 'Zach Raines'
4
+ EMAIL = "achatesavc+rubypython@gmail.com"
5
+ DESCRIPTION = "A bridge between ruby and python"
6
+ GEM_NAME = 'rubypython'
7
+ RUBYFORGE_PROJECT = 'rubypython'
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "sentient6"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = RubyPython::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'rubypython documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. ext rubypython_bridge]))
@@ -0,0 +1,149 @@
1
+ #include "cbridge.h"
2
+
3
+ #define SAFE_START(reg) do { \
4
+ reg=0; \
5
+ if(!Py_IsInitialized())\
6
+ {\
7
+ Py_Initialize();\
8
+ reg=1;\
9
+ }\
10
+ } while(0)
11
+
12
+ #define SAFE_END(reg) do {\
13
+ if(reg && Py_IsInitialized()) \
14
+ {\
15
+ Py_Finalize(); \
16
+ } \
17
+ } while(0)
18
+
19
+ int safe_start()
20
+ {
21
+ int here;
22
+ SAFE_START(here);
23
+ return here;
24
+ }
25
+
26
+ void safe_stop(int here)
27
+ {
28
+ SAFE_END(here);
29
+ }
30
+
31
+
32
+
33
+ VALUE rp_call_func_with_module_name(VALUE module,VALUE name,VALUE args)
34
+ {
35
+ char* func_name=STR2CSTR(name);
36
+ VALUE rArgs;
37
+ VALUE rReturn;
38
+ if(!(TYPE(args)==T_ARRAY))
39
+ {
40
+ rArgs=rb_ary_new();
41
+ rb_ary_push(rArgs,args);
42
+ }
43
+ else
44
+ {
45
+ rArgs=args;
46
+ }
47
+
48
+ PyObject *pModuleName,*pModule,*pFunc,*pArgs,*pReturn;
49
+ if(rb_eql(module,rb_str_new2("builtins")))
50
+ {
51
+ module=rb_str_new2("__builtins__");
52
+ }
53
+ pModuleName=rtop_obj(module,0);
54
+ pModule=PyImport_Import(pModuleName);
55
+ Py_XDECREF(pModuleName);
56
+ if(PyErr_Occurred())
57
+ {
58
+ rp_pythonerror();
59
+ return Qnil;
60
+ }
61
+
62
+
63
+ pFunc=PyObject_GetAttrString(pModule,func_name);
64
+
65
+ pArgs=rtop_obj(rArgs,1);
66
+
67
+ pReturn=PyObject_CallObject(pFunc,pArgs);
68
+
69
+ if(PyErr_Occurred())
70
+ {
71
+ Py_XDECREF(pReturn);
72
+ Py_XDECREF(pArgs);
73
+ Py_XDECREF(pFunc);
74
+ Py_XDECREF(pModule);
75
+ rp_pythonerror();
76
+ return Qnil;
77
+ }
78
+
79
+ rReturn=ptor_obj(pReturn);
80
+
81
+ Py_XDECREF(pArgs);
82
+ Py_XDECREF(pFunc);
83
+ Py_XDECREF(pModule);
84
+ return rReturn;
85
+ }
86
+
87
+ PyObject* rp_get_module(VALUE mname)
88
+ {
89
+ if(rb_eql(mname,rb_str_new2("builtins")))
90
+ {
91
+ mname=rb_str_new2("__builtins__");
92
+ }
93
+ PyObject *pModule,*pModuleName;
94
+ pModuleName=rtop_string(mname);
95
+ pModule=PyImport_Import(pModuleName);
96
+ Py_XDECREF(pModuleName);
97
+ if(PyErr_Occurred())
98
+ {
99
+ Py_XDECREF(pModule);
100
+ rp_pythonerror();
101
+ return Py_None;
102
+ }
103
+ return pModule;
104
+ }
105
+
106
+ PyObject* rp_get_func_with_module(PyObject* pModule,VALUE name)
107
+ {
108
+ PyObject *pFunc;
109
+ pFunc=PyObject_GetAttrString(pModule,STR2CSTR(name));
110
+ if(PyErr_Occurred())
111
+ {
112
+ Py_XDECREF(pFunc);
113
+ rp_pythonerror();
114
+ return Py_None;
115
+ }
116
+ return pFunc;
117
+ }
118
+
119
+ VALUE rp_call_func(PyObject* pFunc, VALUE args)
120
+ {
121
+ VALUE rArgs,rReturn;
122
+ PyObject *pReturn,*pArgs;
123
+ if(!(TYPE(args)==T_ARRAY))
124
+ {
125
+ rArgs=rb_ary_new();
126
+ rb_ary_push(rArgs,args);
127
+ }
128
+ else
129
+ {
130
+ rArgs=args;
131
+ }
132
+ pArgs=rtop_obj(rArgs,1);
133
+ pReturn=PyObject_CallObject(pFunc,pArgs);
134
+
135
+ if(PyErr_Occurred())
136
+ {
137
+ Py_XDECREF(pArgs);
138
+ Py_XDECREF(pReturn);
139
+ rp_pythonerror();
140
+ return Qnil;
141
+ }
142
+ rReturn=ptor_obj(pReturn);
143
+
144
+ Py_XDECREF(pArgs);
145
+ Py_XDECREF(pReturn);
146
+
147
+ return rReturn;
148
+ }
149
+
@@ -0,0 +1,25 @@
1
+ #include "config.h"
2
+ #include "ptor.h"
3
+ #include "rtop.h"
4
+ #include "rp_error.h"
5
+
6
+ #ifndef _BRIDGE_H_
7
+ #define _BRIDGE_H_
8
+
9
+ int safe_start();
10
+
11
+ void safe_stop(int here);
12
+
13
+
14
+ VALUE rp_call_func_with_module_name(VALUE module,VALUE name,VALUE args);
15
+
16
+ PyObject* rp_get_module(VALUE mname);
17
+
18
+ PyObject* rp_get_func_with_module(PyObject* pModule,VALUE name);
19
+
20
+ VALUE rp_call_func(PyObject* pFunc, VALUE args);
21
+
22
+
23
+ #endif /* _BRIDGE_H_ */
24
+
25
+
@@ -0,0 +1,14 @@
1
+ #ifndef _PYTHON_H_
2
+ #define _PYTHON_H_
3
+ #include "python2.5/Python.h"
4
+ #endif /* _PYTHON_H_ */
5
+
6
+ #ifndef _STDLIB_H_
7
+ #define _STDLIB_H_
8
+ #include "stdlib.h"
9
+ #endif /* _STDLIB_H_ */
10
+
11
+ #ifndef _RUBY_H_
12
+ #define _RUBY_H_
13
+ #include "ruby.h"
14
+ #endif /* _RUBY_H_ */