lib/rbbt/util/python.rb in rbbt-util-5.32.12 vs lib/rbbt/util/python.rb in rbbt-util-5.32.13

- old
+ new

@@ -1,26 +1,35 @@ require 'rbbt-util' require 'pycall/import' module RbbtPython extend PyCall::Import + + def self.exec(script) + PyCall.exec(script) + end + def self.run(mod = nil, imports = nil, &block) if mod - if imports + if Array === imports pyfrom mod, :import => imports + elsif Hash === imports + pyimport mod, imports else pyimport mod end end module_eval(&block) end def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block) if mod - if imports + if Array === imports pyfrom mod, :import => imports + elsif Hash === imports + pyimport mod, imports else pyimport mod end end @@ -29,12 +38,14 @@ end end def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block) if mod - if imports + if Array === imports pyfrom mod, :import => imports + elsif Hash === imports + pyimport mod, imports else pyimport mod end end @@ -47,6 +58,16 @@ self.run 'sys' do sys.path.append path end end + def self.add_paths(paths) + self.run 'sys' do + paths.each do |path| + sys.path.append path + end + end + end + + RbbtPython.add_paths Rbbt.python.find_all + RbbtPython.pyimport "rbbt" end