rbbt-util 5.44.0 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +3 -3
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/sharder.rb +1 -1
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +10 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +308 -0
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/info.rb +2 -2
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +16 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +42 -3
data/lib/rbbt/util/procpath.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'scout/cmd'
|
2
2
|
module ProcPath
|
3
3
|
CMD.tool :procpath do
|
4
4
|
'pip install procpath'
|
@@ -6,11 +6,11 @@ module ProcPath
|
|
6
6
|
|
7
7
|
def self.record(pid, path, options = {})
|
8
8
|
IndiferentHash.setup(options)
|
9
|
-
options =
|
9
|
+
options = IndiferentHash.add_defaults options, "interval" => 30
|
10
10
|
|
11
11
|
cmd_options = %w(interval recnum reevalnum).inject({}){|acc,k| acc[k] = options[k]; acc}
|
12
12
|
|
13
|
-
Log.debug "ProcPath recording #{pid} in #{path} (#{
|
13
|
+
Log.debug "ProcPath recording #{pid} in #{path} (#{Log.fingerprint options})"
|
14
14
|
procpath_thread = Thread.new do
|
15
15
|
begin
|
16
16
|
procpath_pid = CMD.cmd_pid(:procpath, "record --database-file '#{path}' '$..children[?(@.stat.pid == #{pid})]'", cmd_options.merge(:nofail => true, :add_option_dashes => true))
|
@@ -28,7 +28,7 @@ module ProcPath
|
|
28
28
|
|
29
29
|
def self.plot(path, output, options = {})
|
30
30
|
IndiferentHash.setup(options)
|
31
|
-
options =
|
31
|
+
options = IndiferentHash.add_defaults options, "query-name" => 'rss', 'epsilon' => 0.5, "moving-average-window" => 10
|
32
32
|
|
33
33
|
cmd_options = %w(query-name epsilon monitor-average-window title logarithmic after before custom-query-file custom-value-expr).inject({}){|acc,k| acc[k] = options[k]; acc}
|
34
34
|
CMD.cmd_log(:procpath, "plot --database-file '#{path}' --plot-file '#{output}' ", cmd_options.merge(:nofail => true, :add_option_dashes => true))
|
@@ -36,10 +36,10 @@ module ProcPath
|
|
36
36
|
|
37
37
|
def self.monitor(pid, path)
|
38
38
|
database, options_str = path.split("#")
|
39
|
-
options = options_str.nil? ? {} :
|
39
|
+
options = options_str.nil? ? {} : IndiferentHash.string2hash(options_str)
|
40
40
|
|
41
41
|
database = File.expand_path database
|
42
|
-
Log.low "ProcPath monitor #{pid} in #{database} (#{
|
42
|
+
Log.low "ProcPath monitor #{pid} in #{database} (#{Log.fingerprint options})"
|
43
43
|
|
44
44
|
ProcPath.record(pid, database + '.sqlite3', options)
|
45
45
|
ProcPath.plot(database + '.sqlite3', database + '.cpu.svg', options.merge("query-name" => 'cpu'))
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RbbtPython
|
2
|
+
class << self
|
3
|
+
attr_accessor :paths
|
4
|
+
def paths
|
5
|
+
@paths ||= []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.add_path(path)
|
10
|
+
self.paths << path
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.add_paths(paths)
|
14
|
+
self.paths.concat paths
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.process_paths
|
18
|
+
RbbtPython.run_direct 'sys' do
|
19
|
+
RbbtPython.paths.each do |path|
|
20
|
+
sys.path.append path
|
21
|
+
end
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
add_paths(Rbbt.python.find_all)
|
27
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module RbbtPython
|
2
|
+
class << self
|
3
|
+
attr_accessor :thread
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.thread
|
7
|
+
@thread ||= defined?(@thread) ? @thread : nil
|
8
|
+
end
|
9
|
+
|
10
|
+
MUTEX= Mutex.new
|
11
|
+
QUEUE_IN ||= Queue.new
|
12
|
+
QUEUE_OUT ||= Queue.new
|
13
|
+
def self.synchronize(&block)
|
14
|
+
MUTEX.synchronize &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.init_thread
|
18
|
+
if defined?(self.thread) && (self.thread && ! self.thread.alive?)
|
19
|
+
Log.warn "Reloading RbbtPython thread"
|
20
|
+
self.thread.join
|
21
|
+
self.thread = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
self.thread ||= Thread.new do
|
25
|
+
require 'pycall'
|
26
|
+
RbbtPython.process_paths
|
27
|
+
begin
|
28
|
+
while block = QUEUE_IN.pop
|
29
|
+
break if block == :stop
|
30
|
+
res =
|
31
|
+
begin
|
32
|
+
module_eval(&block)
|
33
|
+
rescue Exception
|
34
|
+
Log.exception $!
|
35
|
+
raise $!
|
36
|
+
end
|
37
|
+
|
38
|
+
QUEUE_OUT.push res
|
39
|
+
end
|
40
|
+
rescue Exception
|
41
|
+
Log.exception $!
|
42
|
+
raise $!
|
43
|
+
ensure
|
44
|
+
PyCall.finalize if PyCall.respond_to?(:finalize)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.run_in_thread(&block)
|
50
|
+
self.synchronize do
|
51
|
+
init_thread
|
52
|
+
QUEUE_IN.push block
|
53
|
+
QUEUE_OUT.pop
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.stop_thread
|
58
|
+
self.synchronize do
|
59
|
+
QUEUE_IN.push :stop
|
60
|
+
end if self.thread && self.thread.alive?
|
61
|
+
self.thread.join if self.thread
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.run_direct(mod = nil, imports = nil, &block)
|
65
|
+
if mod
|
66
|
+
if Hash === imports
|
67
|
+
pyimport mod, **imports
|
68
|
+
elsif imports.nil?
|
69
|
+
pyimport mod
|
70
|
+
else
|
71
|
+
pyfrom mod, :import => imports
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module_eval(&block)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.run_threaded(mod = nil, imports = nil, &block)
|
79
|
+
run_in_thread do
|
80
|
+
if Hash === imports
|
81
|
+
pyimport mod, **imports
|
82
|
+
elsif imports.nil?
|
83
|
+
pyimport mod
|
84
|
+
else
|
85
|
+
pyfrom mod, :import => imports
|
86
|
+
end
|
87
|
+
end if mod
|
88
|
+
|
89
|
+
run_in_thread(&block)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.run_simple(mod = nil, imports = nil, &block)
|
93
|
+
self.synchronize do
|
94
|
+
RbbtPython.process_paths
|
95
|
+
run_direct(mod, imports, &block)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class << self
|
100
|
+
alias run run_simple
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
|
104
|
+
Log.trap_std("Python STDOUT", "Python STDERR", severity, severity_err) do
|
105
|
+
run(mod, imports, &block)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
|
110
|
+
Log.trap_stderr("Python STDERR", severity) do
|
111
|
+
run(mod, imports, &block)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module RbbtPython
|
2
|
+
def self.ruby2python(object)
|
3
|
+
case object
|
4
|
+
when Float::INFINITY
|
5
|
+
"inf"
|
6
|
+
when nil
|
7
|
+
"None"
|
8
|
+
when ":NA"
|
9
|
+
"None"
|
10
|
+
when Symbol
|
11
|
+
"#{ object }"
|
12
|
+
when String
|
13
|
+
object = object.dup if Path === object
|
14
|
+
object[0] == ":" ? object[1..-1] : "'#{ object }'"
|
15
|
+
when Numeric
|
16
|
+
object
|
17
|
+
when TrueClass
|
18
|
+
"True"
|
19
|
+
when FalseClass
|
20
|
+
"False"
|
21
|
+
when Array
|
22
|
+
"[#{object.collect{|e| ruby2python(e) } * ", "}]"
|
23
|
+
when Hash
|
24
|
+
"{" << object.collect{|k,v| [ruby2python(k.to_s), ruby2python(v)] * ":"} * ", " << "}"
|
25
|
+
else
|
26
|
+
raise "Type of object not known: #{ object.inspect }"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load_script_variables(variables = {})
|
31
|
+
code = "# Variables\nimport rbbt\n"
|
32
|
+
tmp_files = []
|
33
|
+
variables.each do |name,value|
|
34
|
+
case value
|
35
|
+
when TSV
|
36
|
+
tmp_file = TmpFile.tmp_file
|
37
|
+
tmp_files << tmp_file
|
38
|
+
Open.write(tmp_file, value.to_s)
|
39
|
+
code << "#{name} = rbbt.tsv('#{tmp_file}')" << "\n"
|
40
|
+
else
|
41
|
+
code << "#{name} = #{RbbtPython.ruby2python(value)}" << "\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
[code, tmp_files]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.save_script_result_pickle(file)
|
49
|
+
<<-EOF
|
50
|
+
|
51
|
+
# Save
|
52
|
+
try: result
|
53
|
+
except NameError: result = None
|
54
|
+
if result is not None:
|
55
|
+
import pickle
|
56
|
+
file = open('#{file}', 'wb')
|
57
|
+
# dump information to that file
|
58
|
+
pickle.dump(result, file)
|
59
|
+
EOF
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.load_pickle(file)
|
63
|
+
require 'python/pickle'
|
64
|
+
Log.debug ("Loading pickle #{file}")
|
65
|
+
Python::Pickle.load_file(file)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.save_script_result_json(file)
|
69
|
+
<<-EOF
|
70
|
+
|
71
|
+
# Save
|
72
|
+
try: result
|
73
|
+
except NameError: result = None
|
74
|
+
if result is not None:
|
75
|
+
import json
|
76
|
+
file = open('#{file}', 'w', encoding='utf-8')
|
77
|
+
# dump information to that file
|
78
|
+
file.write(json.dumps(result))
|
79
|
+
file.flush
|
80
|
+
file.close
|
81
|
+
EOF
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.load_json(file)
|
85
|
+
JSON.load_file(file)
|
86
|
+
end
|
87
|
+
|
88
|
+
class << self
|
89
|
+
alias save_script_result save_script_result_pickle
|
90
|
+
alias load_result load_pickle
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.script(text, variables = {})
|
94
|
+
if variables.any?
|
95
|
+
variable_definitions, tmp_files = load_script_variables(variables)
|
96
|
+
text = variable_definitions + "\n# Script\n" + text
|
97
|
+
end
|
98
|
+
|
99
|
+
TmpFile.with_file do |tmp_file|
|
100
|
+
text += save_script_result(tmp_file)
|
101
|
+
Log.debug "Running python script:\n#{text.dup}"
|
102
|
+
path_env = RbbtPython.paths * ":"
|
103
|
+
CMD.cmd_log("env PYTHONPATH=#{path_env} python", {in: text})
|
104
|
+
tmp_files.each{|file| Open.rm_rf file } if tmp_files
|
105
|
+
if Open.exists?(tmp_file)
|
106
|
+
load_result(tmp_file)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -10,7 +10,7 @@ module RbbtPython
|
|
10
10
|
|
11
11
|
def self.tsv2df(tsv)
|
12
12
|
df = nil
|
13
|
-
RbbtPython.
|
13
|
+
RbbtPython.run_direct 'pandas' do
|
14
14
|
df = pandas.DataFrame.new(tsv.values, columns: tsv.fields, index: tsv.keys)
|
15
15
|
df.columns.name = tsv.key_field
|
16
16
|
end
|
@@ -21,9 +21,9 @@ module RbbtPython
|
|
21
21
|
options = Misc.add_defaults options, :type => :list
|
22
22
|
IndiferentHash.setup options
|
23
23
|
tsv = TSV.setup({}, options)
|
24
|
-
tsv.key_field = options[:key_field] || tuple.columns.name
|
24
|
+
tsv.key_field = options[:key_field] || tuple.columns.name.to_s
|
25
25
|
tsv.fields = py2ruby_a(tuple.columns.values)
|
26
|
-
keys = tuple.index.values
|
26
|
+
keys = py2ruby_a(tuple.index.values)
|
27
27
|
PyCall.len(tuple.index).times do |i|
|
28
28
|
k = keys[i]
|
29
29
|
tsv[k] = py2ruby_a(tuple.values[i])
|
data/lib/rbbt/util/python.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'rbbt-util'
|
2
|
-
require '
|
2
|
+
require 'rbbt/util/python/paths'
|
3
|
+
require 'rbbt/util/python/run'
|
3
4
|
require 'rbbt/util/python/util'
|
5
|
+
require 'rbbt/util/python/script'
|
6
|
+
|
7
|
+
require 'pycall/import'
|
4
8
|
|
5
9
|
module RbbtPython
|
6
10
|
extend PyCall::Import
|
@@ -15,41 +19,19 @@ module RbbtPython
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
def self.script(text, options = {})
|
19
|
-
Log.debug "Running python script:\n#{text.dup}"
|
20
|
-
text = StringIO.new text unless IO === text
|
21
|
-
CMD.cmd_log(:python, options.merge(:in => text))
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.add_path(path)
|
25
|
-
begin
|
26
|
-
self.run 'sys' do
|
27
|
-
sys.path.append path
|
28
|
-
end
|
29
|
-
rescue
|
30
|
-
raise RbbtPythonException,
|
31
|
-
"Could not add path #{Misc.fingerprint path} to python sys: " + $!.message
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.add_paths(paths)
|
36
|
-
self.run 'sys' do
|
37
|
-
paths.each do |path|
|
38
|
-
sys.path.append path
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
22
|
def self.init_rbbt
|
44
23
|
if ! defined?(@@__init_rbbt_python) || ! @@__init_rbbt_python
|
45
|
-
|
46
|
-
RbbtPython.
|
47
|
-
|
24
|
+
RbbtPython.process_paths
|
25
|
+
res = RbbtPython.run do
|
26
|
+
Log.debug "Loading python 'rbbt' module into pycall RbbtPython module"
|
27
|
+
pyimport("rbbt")
|
28
|
+
end
|
48
29
|
@@__init_rbbt_python = true
|
49
30
|
end
|
50
31
|
end
|
51
32
|
|
52
33
|
def self.import_method(module_name, method_name, as = nil)
|
34
|
+
init_rbbt
|
53
35
|
RbbtPython.pyfrom module_name, import: method_name
|
54
36
|
RbbtPython.method(method_name)
|
55
37
|
end
|
@@ -57,11 +39,17 @@ module RbbtPython
|
|
57
39
|
def self.call_method(module_name, method_name, *args)
|
58
40
|
RbbtPython.import_method(module_name, method_name).call(*args)
|
59
41
|
end
|
60
|
-
|
61
|
-
def self.
|
42
|
+
|
43
|
+
def self.get_module(module_name)
|
44
|
+
init_rbbt
|
62
45
|
save_module_name = module_name.to_s.gsub(".", "_")
|
63
46
|
RbbtPython.pyimport(module_name, as: save_module_name)
|
64
|
-
RbbtPython.send(save_module_name)
|
47
|
+
RbbtPython.send(save_module_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.get_class(module_name, class_name)
|
51
|
+
mod = get_module(module_name)
|
52
|
+
mod.send(class_name)
|
65
53
|
end
|
66
54
|
|
67
55
|
def self.class_new_obj(module_name, class_name, args={})
|
@@ -73,7 +61,6 @@ module RbbtPython
|
|
73
61
|
end
|
74
62
|
|
75
63
|
def self.iterate_index(elem, options = {})
|
76
|
-
iii :interate_index
|
77
64
|
bar = options[:bar]
|
78
65
|
|
79
66
|
len = PyCall.len(elem)
|
@@ -152,54 +139,6 @@ module RbbtPython
|
|
152
139
|
acc
|
153
140
|
end
|
154
141
|
|
155
|
-
def self.run(mod = nil, imports = nil, &block)
|
156
|
-
if mod
|
157
|
-
if Hash === imports
|
158
|
-
pyimport mod, **imports
|
159
|
-
elsif imports.nil?
|
160
|
-
pyimport mod
|
161
|
-
else
|
162
|
-
pyfrom mod, :import => imports
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
module_eval(&block)
|
167
|
-
end
|
168
|
-
|
169
|
-
def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
|
170
|
-
if mod
|
171
|
-
if imports == "*" || imports == ["*"]
|
172
|
-
pyfrom mod
|
173
|
-
elsif Array === imports
|
174
|
-
pyfrom mod, :import => imports
|
175
|
-
elsif Hash === imports
|
176
|
-
pyimport mod, imports
|
177
|
-
else
|
178
|
-
pyimport mod
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
Log.trap_std("Python STDOUT", "Python STDERR", severity, severity_err) do
|
183
|
-
module_eval(&block)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
|
188
|
-
if mod
|
189
|
-
if Array === imports
|
190
|
-
pyfrom mod, :import => imports
|
191
|
-
elsif Hash === imports
|
192
|
-
pyimport mod, imports
|
193
|
-
else
|
194
|
-
pyimport mod
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
Log.trap_stderr("Python STDERR", severity) do
|
199
|
-
module_eval(&block)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
142
|
def self.new_binding
|
204
143
|
Binding.new
|
205
144
|
end
|
@@ -209,3 +148,5 @@ module RbbtPython
|
|
209
148
|
binding.instance_exec *args, &block
|
210
149
|
end
|
211
150
|
end
|
151
|
+
|
152
|
+
RbbtPython.add_path Rbbt.python.find(:lib)
|