rubypython 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.hgignore DELETED
@@ -1,14 +0,0 @@
1
- syntax:glob
2
- *.o
3
- *.so
4
- *.bundle
5
- *.pyc
6
- *.log
7
- *~
8
- doc/*
9
- ext/*/Makefile
10
- *.swp
11
- .yardoc/*
12
- .DS_Store
13
- pkg/*
14
- website/index.html
data/.hgtags DELETED
@@ -1,9 +0,0 @@
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
@@ -1,66 +0,0 @@
1
- require 'ostruct'
2
-
3
- module RubyPython
4
- # A hash for storing RubyPython execution options.
5
- @options = {}
6
-
7
- # A list of options which require the \Python library to be reloaded.
8
- NEED_RELOAD = [ :python_exe ] #:nodoc
9
- # 20110316 AZ: This option has been removed because it isn't supported in
10
- # the current code.
11
- # :python_lib -> The full path to the python library you wish to load.
12
-
13
- class << self
14
- # Allows one to set options for RubyPython's execution. Parameters may
15
- # be set either by supplying a hash argument or by supplying a block and
16
- # calling setters on the provided OpenStruct. Returns a copy of the
17
- # updated options hash.
18
- #
19
- # [options] A Hash of options to set.
20
- #
21
- # The option currently supported is:
22
- # [:python_exe] The name of or path to the \Python executable for the
23
- # version of \Python you wish to use.
24
- #
25
- # RubyPython.run do
26
- # RubyPython.import('sys').version.rubify.to_f # => 2.7
27
- # end
28
- #
29
- # RubyPython.configure :python_exe => 'python2.6'
30
- # # => { :python_exe => "python2.6" }
31
- # RubyPython.run do
32
- # RubyPython.import('sys').version.rubify.to_f # => 2.6
33
- # end
34
- #
35
- # The options hash can also be passed directly to +RubyPython.start+,
36
- # +RubyPython.session+, or +RubyPython.run+.
37
- def configure(options = {})
38
- old_values = Hash[*@options.select { |k, v| NEED_RELOAD.include? k }]
39
-
40
- if block_given?
41
- ostruct = OpenStruct.new @options
42
- yield ostruct
43
- olist = ostruct.instance_variable_get('@table').map { |k, v| [ k.to_sym, v ] }
44
- @options = Hash[*olist]
45
- end
46
- @options.merge!(options)
47
-
48
- @reload = true if NEED_RELOAD.any? { |k| @options[k] != old_values[k] }
49
- options
50
- end
51
-
52
- # Returns a copy of the hash currently being used to determine run
53
- # options. This allows the user to determine what options have been set.
54
- # Modification of options should be done via the configure method.
55
- def options
56
- @options.dup
57
- end
58
-
59
- # Reset the options hash.
60
- # @return [void]
61
- def clear_options
62
- @reload = @options.keys.any? { |k| NEED_RELOAD.include? k }
63
- @options.clear
64
- end
65
- end
66
- end
@@ -1,145 +0,0 @@
1
- # A class that represents a \Python executable.
2
- #
3
- # End users may get the instance that represents the current running \Python
4
- # interpreter (from +RubyPython.python+), but should not directly
5
- # instantiate this class.
6
- class RubyPython::PythonExec
7
- # Based on the name of or path to the \Python executable provided, will
8
- # determine:
9
- #
10
- # * The full path to the \Python executable.
11
- # * The version of \Python being run.
12
- # * The system prefix.
13
- # * The main loadable \Python library for this version.
14
- def initialize(python_executable)
15
- @python = python_executable || "python"
16
- @python = %x(#{@python} -c "import sys; print sys.executable").chomp
17
-
18
- @version = run_command "import sys; print '%d.%d' % sys.version_info[:2]"
19
-
20
- @dirname = File.dirname(@python)
21
- @realname = @python.dup
22
- if (@realname !~ /#{@version}$/ and @realname !~ /\.exe$/)
23
- @realname = "#{@python}#{@version}"
24
- else
25
- basename = File.basename(@python, '.exe')
26
- @realname = File.join(@dirname, "#{basename}#{@version.gsub(/\./, '')}")
27
- end
28
- @basename = File.basename(@realname)
29
-
30
- @sys_prefix = run_command 'import sys; print sys.prefix'
31
- @library = find_python_lib
32
- end
33
-
34
- def find_python_lib
35
- # By default, the library name will be something like
36
- # libpython2.6.so, but that won't always work.
37
- libbase = "#{FFI::Platform::LIBPREFIX}#{@basename}"
38
- libext = FFI::Platform::LIBSUFFIX
39
- libname = "#{libbase}.#{libext}"
40
-
41
- # We may need to look in multiple locations for Python, so let's
42
- # build this as an array.
43
- locations = [ File.join(@sys_prefix, "lib", libname) ]
44
-
45
- if FFI::Platform.mac?
46
- # On the Mac, let's add a special case that has even a different
47
- # libname. This may not be fully useful on future versions of OS
48
- # X, but it should work on 10.5 and 10.6. Even if it doesn't, the
49
- # next step will (/usr/lib/libpython<version>.dylib is a symlink
50
- # to the correct location).
51
- locations << File.join(@sys_prefix, "Python")
52
- # Let's also look in the location that was originally set in this
53
- # library:
54
- File.join(@sys_prefix, "lib", "#{@realname}", "config", libname)
55
- end
56
-
57
- if FFI::Platform.unix?
58
- # On Unixes, let's look in some standard alternative places, too.
59
- # Just in case. Some Unixes don't include a .so symlink when they
60
- # should, so let's look for the base case of .so.1, too.
61
- [ libname, "#{libname}.1" ].each do |name|
62
- locations << File.join("/opt/local/lib", name)
63
- locations << File.join("/opt/lib", name)
64
- locations << File.join("/usr/local/lib", name)
65
- locations << File.join("/usr/lib", name)
66
- locations << File.join("/opt/local/lib64", name)
67
- locations << File.join("/opt/lib64", name)
68
- locations << File.join("/usr/local/lib64", name)
69
- locations << File.join("/usr/lib64", name)
70
- end
71
- end
72
-
73
- if FFI::Platform.windows?
74
- # On Windows, the appropriate DLL is usually be found in
75
- # %SYSTEMROOT%\system or %SYSTEMROOT%\system32; as a fallback we'll
76
- # use C:\Windows\system{,32} as well as the install directory and the
77
- # install directory + libs.
78
- system_root = File.expand_path(ENV['SYSTEMROOT']).gsub(/\\/, '/')
79
- locations << File.join(system_root, 'system', libname)
80
- locations << File.join(system_root, 'system32', libname)
81
- locations << File.join("C:/WINDOWS", "System", libname)
82
- locations << File.join("C:/WINDOWS", "System32", libname)
83
- locations << File.join(@dirname, libname)
84
- locations << File.join(@dirname, 'libs', libname)
85
- end
86
-
87
- # Let's add alternative extensions; again, just in case.
88
- locations.dup.each do |location|
89
- path = File.dirname(location)
90
- base = File.basename(location, ".#{libext}")
91
- locations << File.join(path, "#{base}.so") # Standard Unix
92
- locations << File.join(path, "#{base}.dylib") # Mac OS X
93
- locations << File.join(path, "#{base}.dll") # Windows
94
- locations << File.join(path, "#{base}.a") # Non-DLL
95
- end
96
-
97
- # Remove redundant locations
98
- locations.uniq!
99
-
100
- library = nil
101
-
102
- locations.each do |location|
103
- if File.exists? location
104
- library = location
105
- break
106
- end
107
- end
108
-
109
- library
110
- end
111
- private :find_python_lib
112
-
113
- # The python executable to use.
114
- attr_reader :python
115
- # The real name of the python executable (with version).
116
- attr_reader :realname
117
- # The sys.prefix for Python.
118
- attr_reader :sys_prefix
119
- # The Python library.
120
- attr_reader :library
121
- # The Python version
122
- attr_reader :version
123
-
124
- # Run a Python command-line command.
125
- def run_command(command)
126
- %x(#{@python} -c "#{command}").chomp if @python
127
- end
128
-
129
- def to_s
130
- @realname
131
- end
132
-
133
- def inspect
134
- if @python
135
- "#<#{realname} #{sys_prefix}>"
136
- else
137
- "#<invalid interpreter>"
138
- end
139
- end
140
-
141
- def invalidate!
142
- @python = @version = @realname = @sys_prefix = @library = nil
143
- end
144
- private :invalidate!
145
- end