rbbt-util 5.26.85 → 5.26.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +3 -1
- data/lib/rbbt/hpc.rb +7 -2
- data/lib/rbbt/util/log.rb +70 -13
- data/lib/rbbt/util/python.rb +32 -10
- data/lib/rbbt/workflow/step/accessor.rb +2 -1
- data/test/rbbt/util/test_log.rb +34 -3
- data/test/rbbt/util/test_python.rb +25 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6102e3c95948e874ce0ef40256083bc5bbb61c27700dbab1e864a3ec14ebe3
|
4
|
+
data.tar.gz: 5267bbf2d76c3a1ec0920fa5ecb03acf711ae541198d220055afae0965fa9630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5fa3392feae0691db1b06276294be43f6f8e0c8dd2d553967cf4993277b2cee9284ccb10b4c1b27848c0fc6beb09c5e9b65f5b3235f97180eaad2d2279df05
|
7
|
+
data.tar.gz: 7cc7b7c0207712ff2541d9ced370131c431359f28de3f9aaee4d1ce840f59506c6e05776021f04fe47d8fe461362f7fbfa867cc2982afe760dc451178342ab08
|
data/bin/rbbt
CHANGED
@@ -55,11 +55,13 @@ $ rbbt <command> <subcommand> ... -a --arg1 --arg2='value' --arg3 'another-value
|
|
55
55
|
--update_tsv #{Log.color :yellow, "Update persisted TSV files also if source has been updated"}
|
56
56
|
--locate_file #{Log.color :yellow, "Report the location of the script instead of executing it"}
|
57
57
|
--dump_mem* #{Log.color :yellow, "Dump strings in memory each second into file"}
|
58
|
-
-nolock--no_lock_id
|
58
|
+
-nolock--no_lock_id #{Log.color :yellow, "Do not track lockfiles with ids (prevent stale file handlers for high-througput and high-concurrency)"}
|
59
59
|
-ji--jobname_show_inputs #{Log.color :yellow, "Show inputs as part of the jobname in workflows instead of digesting them"}
|
60
60
|
-ck--config_keys* #{Log.color :yellow, "Override some config keys"}
|
61
|
+
-srand--random_seed* #{Log.color :yellow, "Set the random seed"}
|
61
62
|
EOF
|
62
63
|
|
64
|
+
srand(options[:random_seed].to_i) if options[:random_seed]
|
63
65
|
if options[:jobname_show_inputs]
|
64
66
|
ENV["RBBT_INPUT_JOBNAME"] = "true"
|
65
67
|
end
|
data/lib/rbbt/hpc.rb
CHANGED
@@ -15,6 +15,7 @@ module Marenostrum
|
|
15
15
|
def self.template(args, options = {})
|
16
16
|
|
17
17
|
development = options.delete :drbbt
|
18
|
+
singularity = options.delete :singularity
|
18
19
|
contain = options.delete :contain
|
19
20
|
sync = options.delete :sync
|
20
21
|
contain_and_sync = options.delete :contain_and_sync
|
@@ -38,7 +39,7 @@ module Marenostrum
|
|
38
39
|
|
39
40
|
contain = File.expand_path(contain) if contain
|
40
41
|
|
41
|
-
singularity = true if contain
|
42
|
+
singularity = true if contain
|
42
43
|
|
43
44
|
|
44
45
|
name = options[:name] ||= Misc.obj2digest({:options => options.collect{|k,v| [k,v]}.sort_by{|k,v| k.to_s }, :args => args})
|
@@ -228,7 +229,11 @@ EOF
|
|
228
229
|
|
229
230
|
exec_cmd = singularity_exec + " " + exec_cmd
|
230
231
|
else
|
231
|
-
|
232
|
+
if development
|
233
|
+
exec_cmd << " " << %(~/git/rbbt-util/bin/rbbt --dev=~/git/)
|
234
|
+
else
|
235
|
+
exec_cmd << " " << 'rbbt'
|
236
|
+
end
|
232
237
|
end
|
233
238
|
|
234
239
|
|
data/lib/rbbt/util/log.rb
CHANGED
@@ -34,6 +34,70 @@ module Log
|
|
34
34
|
line.gsub('`', "'")
|
35
35
|
end
|
36
36
|
|
37
|
+
|
38
|
+
def self.trap_std(msg = "STDOUT", msge = "STDERR", severity = 0, severity_err = nil)
|
39
|
+
sout, sin = Misc.pipe
|
40
|
+
soute, sine = Misc.pipe
|
41
|
+
backup_stderr = STDERR.dup
|
42
|
+
backup_stdout = STDOUT.dup
|
43
|
+
old_logfile = Log.logfile
|
44
|
+
Log.logfile(backup_stderr)
|
45
|
+
|
46
|
+
severity_err ||= severity
|
47
|
+
th_log = Thread.new do
|
48
|
+
while line = sout.gets
|
49
|
+
Log.logn "#{msg}: " + line, severity
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
th_loge = Thread.new do
|
54
|
+
while line = soute.gets
|
55
|
+
Log.logn "#{msge}: " + line, severity_err
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
begin
|
60
|
+
STDOUT.reopen(sin)
|
61
|
+
STDERR.reopen(sine)
|
62
|
+
yield
|
63
|
+
ensure
|
64
|
+
STDERR.reopen backup_stderr
|
65
|
+
STDOUT.reopen backup_stdout
|
66
|
+
sin.close
|
67
|
+
sine.close
|
68
|
+
th_log.join
|
69
|
+
th_loge.join
|
70
|
+
backup_stdout.close
|
71
|
+
backup_stderr.close
|
72
|
+
Log.logfile = old_logfile
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.trap_stderr(msg = "STDERR", severity = 0)
|
77
|
+
sout, sin = Misc.pipe
|
78
|
+
backup_stderr = STDERR.dup
|
79
|
+
old_logfile = Log.logfile
|
80
|
+
Log.logfile(backup_stderr)
|
81
|
+
|
82
|
+
th_log = Thread.new do
|
83
|
+
while line = sout.gets
|
84
|
+
Log.logn "#{msg}: " + line, severity
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
begin
|
89
|
+
STDERR.reopen(sin)
|
90
|
+
yield
|
91
|
+
sin.close
|
92
|
+
ensure
|
93
|
+
STDERR.reopen backup_stderr
|
94
|
+
th_log.join
|
95
|
+
backup_stderr.close
|
96
|
+
Log.logfile = old_logfile
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
37
101
|
def self._ignore_stderr
|
38
102
|
backup_stderr = STDERR.dup
|
39
103
|
File.open('/dev/null', 'w') do |f|
|
@@ -47,6 +111,7 @@ module Log
|
|
47
111
|
end
|
48
112
|
end
|
49
113
|
|
114
|
+
|
50
115
|
def self.ignore_stderr(&block)
|
51
116
|
LOG_MUTEX.synchronize do
|
52
117
|
_ignore_stderr &block
|
@@ -174,9 +239,12 @@ module Log
|
|
174
239
|
str = prefix << " " << message.to_s
|
175
240
|
|
176
241
|
LOG_MUTEX.synchronize do
|
177
|
-
|
242
|
+
if logfile.nil?
|
243
|
+
STDERR.write str
|
244
|
+
else
|
245
|
+
logfile.write str
|
246
|
+
end
|
178
247
|
Log::LAST.replace "log"
|
179
|
-
logfile.write str unless logfile.nil?
|
180
248
|
nil
|
181
249
|
end
|
182
250
|
end
|
@@ -389,14 +457,3 @@ def eef(obj=nil, file = $stdout)
|
|
389
457
|
Log.log_obj_fingerprint(obj, :error, file)
|
390
458
|
end
|
391
459
|
|
392
|
-
if __FILE__ == $0
|
393
|
-
Log.severity = 0
|
394
|
-
|
395
|
-
(0..6).each do |level|
|
396
|
-
Log.log("Level #{level}", level)
|
397
|
-
end
|
398
|
-
|
399
|
-
require 'rbbt/util/misc'
|
400
|
-
eee [1,2,3]
|
401
|
-
eef [1,2,3]
|
402
|
-
end
|
data/lib/rbbt/util/python.rb
CHANGED
@@ -1,23 +1,45 @@
|
|
1
1
|
require 'rbbt-util'
|
2
|
-
|
3
2
|
require 'pycall/import'
|
4
3
|
|
5
4
|
module RbbtPython
|
6
5
|
extend PyCall::Import
|
7
6
|
def self.run(mod = nil, imports = nil, &block)
|
8
|
-
|
9
|
-
if
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
pyimport mod
|
14
|
-
end
|
7
|
+
if mod
|
8
|
+
if imports
|
9
|
+
pyfrom mod, :import => imports
|
10
|
+
else
|
11
|
+
pyimport mod
|
15
12
|
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module_eval(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
|
19
|
+
if mod
|
20
|
+
if imports
|
21
|
+
pyfrom mod, :import => imports
|
22
|
+
else
|
23
|
+
pyimport mod
|
24
|
+
end
|
25
|
+
end
|
16
26
|
|
27
|
+
Log.trap_std("Python STDOUT", "Python STDERR", severity, severity_err) do
|
17
28
|
module_eval(&block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
|
33
|
+
if mod
|
34
|
+
if imports
|
35
|
+
pyfrom mod, :import => imports
|
36
|
+
else
|
37
|
+
pyimport mod
|
38
|
+
end
|
39
|
+
end
|
18
40
|
|
19
|
-
|
20
|
-
|
41
|
+
Log.trap_stderr("Python STDERR", severity) do
|
42
|
+
module_eval(&block)
|
21
43
|
end
|
22
44
|
end
|
23
45
|
|
@@ -283,7 +283,7 @@ class Step
|
|
283
283
|
now = Time.now
|
284
284
|
str = Log.color :reset
|
285
285
|
str << "#{ Log.color status_color, status}"
|
286
|
-
str << ": #{ message }" if message
|
286
|
+
str << ": #{ message }" if message and message != :result
|
287
287
|
str << " -- #{Log.color :blue, path.to_s}" if path
|
288
288
|
str << " #{Log.color :yellow, Process.pid}"
|
289
289
|
str
|
@@ -293,6 +293,7 @@ class Step
|
|
293
293
|
Log.info do
|
294
294
|
now = Time.now
|
295
295
|
str = "#{ Log.color :cyan, status.to_s } +#{Log.color :green, "%.2f" % (eend - start)}"
|
296
|
+
str << ": #{ res }" if message == :result
|
296
297
|
str << " -- #{Log.color :blue, path.to_s}" if path
|
297
298
|
str << " #{Log.color :yellow, Process.pid}"
|
298
299
|
str
|
data/test/rbbt/util/test_log.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helpe
|
|
2
2
|
require 'rbbt/util/log'
|
3
3
|
|
4
4
|
class TestLog < Test::Unit::TestCase
|
5
|
-
def
|
5
|
+
def _test_get_level
|
6
6
|
assert_equal 0, Log.get_level(:debug)
|
7
7
|
assert_equal 1, Log.get_level(:low)
|
8
8
|
assert_equal 1, Log.get_level("LOW")
|
@@ -10,14 +10,45 @@ class TestLog < Test::Unit::TestCase
|
|
10
10
|
assert_equal 0, Log.get_level(nil)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def _test_color
|
14
14
|
assert Log.color(:green, "green")
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def _test_no_stderr
|
18
18
|
Log.ignore_stderr do
|
19
19
|
STDERR.puts "NOPRINT"
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
def _test_trap_stderr
|
24
|
+
Log.severity = 0
|
25
|
+
Log.trap_stderr do
|
26
|
+
STDERR.puts "NOPRINT"
|
27
|
+
STDERR.puts "NOPRINT"
|
28
|
+
STDERR.puts "NOPRINT"
|
29
|
+
STDOUT.puts "PRINT STDOUT"
|
30
|
+
STDOUT.puts "PRINT STDOUT"
|
31
|
+
end
|
32
|
+
Log.trap_stderr do
|
33
|
+
STDERR.puts "NOPRINT"
|
34
|
+
STDOUT.puts "PRINT STDOUT"
|
35
|
+
end
|
36
|
+
Log.trap_std do
|
37
|
+
STDERR.puts "NOPRINT"
|
38
|
+
STDOUT.puts "NOPRINT STDOUT"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_trap_std
|
43
|
+
Log.severity = 0
|
44
|
+
Log.trap_std do
|
45
|
+
STDERR.puts "NOPRINT STDERR"
|
46
|
+
STDOUT.puts "NOPRINT STDOUT"
|
47
|
+
end
|
48
|
+
Log.trap_std "OUT", "ERR", 4, 2 do
|
49
|
+
STDERR.puts "NOPRINT STDERR"
|
50
|
+
STDOUT.puts "NOPRINT STDOUT"
|
51
|
+
end
|
52
|
+
end
|
22
53
|
end
|
23
54
|
|
@@ -40,5 +40,29 @@ def python_test(a, b):
|
|
40
40
|
assert_equal 3, res
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
|
+
def test_run_log
|
45
|
+
Log.severity = 0
|
46
|
+
TmpFile.with_file do |tmpdir|
|
47
|
+
code =<<-EOF
|
48
|
+
import sys
|
49
|
+
def python_print():
|
50
|
+
print("Test STDERR", file=sys.stderr)
|
51
|
+
print("Test STDOUT")
|
52
|
+
EOF
|
53
|
+
Open.write(File.join(tmpdir, 'file_print.py'), code)
|
54
|
+
RbbtPython.add_path tmpdir
|
55
|
+
|
56
|
+
RbbtPython.run_log 'file_print' do
|
57
|
+
file_print.python_print
|
58
|
+
end
|
59
|
+
RbbtPython.run_log_stderr 'file_print' do
|
60
|
+
file_print.python_print
|
61
|
+
end
|
62
|
+
|
63
|
+
RbbtPython.run_log 'file_print' do
|
64
|
+
file_print.python_print
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
44
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.26.
|
4
|
+
version: 5.26.86
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|