rbbt-util 5.21.137 → 5.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba7c142553e810f2dbced269f0aed2a3b52051cb
4
- data.tar.gz: b58daa013d65a07b80ecf4e7de2cea5265ab387b
3
+ metadata.gz: 8d7a4ccc9fa31a719cf11e4b0c5341f610a05fbe
4
+ data.tar.gz: 6f001470b29bab8072d156f18039a13823176f89
5
5
  SHA512:
6
- metadata.gz: a94c595521d98f0f8bfaf15eac02e38f3a9603a65d77d29d34ed6e090b014ec6b269ff9606e6ed62e8a1de47d3b52d5cea210d79e9dba416802686a225be6cbb
7
- data.tar.gz: 3b647173c446127c0f29584f7097b39a4f144aef923b88b2d6ccef9f262ed24b070f28e722326d45e0e382e9e887034b07d3b33fe243a2d314d0af5997ababce
6
+ metadata.gz: 553306c45688f65865f87be18554a92d90a954d1f3402b6d657300c253d5ce6c21183fddd4fe60e99ef867da11338256165b3b30f1598ab4a15fe4f01d2e2be4
7
+ data.tar.gz: 8952ede274862e68aef03b6117560335fb7a552a146a1b36678ebe8bf606dcfc7483d1c060a3501361a6680d930b9c6628601e476e6b000fbd4f93024aad0157
data/bin/rbbt CHANGED
@@ -27,6 +27,7 @@ end
27
27
 
28
28
  require 'rbbt'
29
29
  require 'rbbt/util/simpleopt'
30
+ require 'rbbt/util/config'
30
31
 
31
32
  Log.nocolor = true if ARGV.include? "--nocolor"
32
33
 
@@ -49,6 +50,7 @@ $ rbbt <command> <subcommand> ... -a --arg1 --arg2='value' --arg3 'another-value
49
50
  --dump_mem* #{Log.color :yellow, "Dump strings in memory each second into file"}
50
51
  -nolock--no_lock_id #{Log.color :yellow, "Do not track lockfiles with ids (prevent stale file handlers for high-througput and high-concurrency)"}
51
52
  -ji--jobname_as_inputs #{Log.color :yellow, "Use inputs as part of the jobname in workflows instead of digesting them"}
53
+ -ck--config_keys* #{Log.color :yellow, "Override some config keys"}
52
54
  EOF
53
55
 
54
56
  if options[:jobname_as_inputs]
@@ -89,6 +91,18 @@ if mem_dump = options.delete(:dump_mem)
89
91
  Rbbt.dump_memory(mem_dump, String)
90
92
  end
91
93
 
94
+ if options[:config_keys]
95
+ options[:config_keys].split(",").each do |config|
96
+ key, value, *tokens = config.split(/\s/)
97
+ tokens = ['key:' << key << '::0'] if tokens.empty?
98
+ tokens = tokens.collect do |tok|
99
+ tok, _sep, prio = tok.partition("::")
100
+ prio = "0" if prio.nil? or prio.empty?
101
+ [tok, prio] * "::"
102
+ end
103
+ Rbbt::Config.set({key => value}, *tokens)
104
+ end
105
+ end
92
106
 
93
107
  if options.delete(:update_persist)
94
108
  ENV["RBBT_UPDATE_TSV_PERSIST"] = "true"
data/lib/rbbt-util.rb CHANGED
@@ -15,3 +15,5 @@ TmpFile.tmpdir = Rbbt.tmp.find :user
15
15
  require 'rbbt/util/cmd'
16
16
  require 'rbbt/tsv'
17
17
 
18
+ require 'rbbt/util/config'
19
+
data/lib/rbbt/persist.rb CHANGED
@@ -316,6 +316,8 @@ module Persist
316
316
 
317
317
  save_file(path, type, res, lockfile)
318
318
 
319
+ Open.notify_write(path)
320
+
319
321
  return path if persist_options[:no_load]
320
322
 
321
323
  res
@@ -0,0 +1,109 @@
1
+ require 'rbbt-util'
2
+ require 'rbbt/resource/path'
3
+
4
+ module Rbbt::Config
5
+
6
+ CACHE = IndiferentHash.setup({})
7
+
8
+ def self.add_entry(key, value, tokens)
9
+ CACHE[key.to_s] ||= []
10
+ CACHE[key.to_s] << [tokens, value]
11
+ end
12
+
13
+ def self.load_file(file)
14
+ Log.debug "Loading file: #{ file }"
15
+ TSV.traverse file, :type => :array do |line|
16
+ next if line =~ /^#/
17
+ key, value, *tokens = line.split(/\s/)
18
+
19
+ self.add_entry(key, value, tokens) if key
20
+ end
21
+ end
22
+
23
+ def self.load_config
24
+ Rbbt.etc.config.find_all.each do |file|
25
+ self.load_file(file)
26
+ end
27
+ end
28
+
29
+
30
+ def self.set(values, *tokens)
31
+ values.each do |key,value|
32
+ add_entry key, value, tokens
33
+ end
34
+ end
35
+
36
+ def self.token_priority(token)
37
+ token, _sep, priority = token.to_s.partition("::")
38
+
39
+ if priority.nil? || priority.empty?
40
+ type, _sep, rest = token.partition(":")
41
+ priority = case type
42
+ when "workflow"
43
+ 4
44
+ when "task"
45
+ 3
46
+ when "file"
47
+ 2
48
+ when "line"
49
+ 1
50
+ when "key"
51
+ 20
52
+ else
53
+ 10
54
+ end
55
+ else
56
+ priority = priority.to_i
57
+ end
58
+
59
+ [token, priority]
60
+ end
61
+
62
+ def self.match(entries, token)
63
+ priorities = {}
64
+ entries.each do |tokens, value|
65
+ best_prio = nil
66
+ tokens.each do |tok|
67
+ tok, prio = token_priority tok
68
+ best_prio = prio if best_prio.nil? or best_prio > prio
69
+ next if prio > best_prio
70
+ next unless tok == token
71
+ priorities[prio] ||= []
72
+ priorities[prio] << value
73
+ end
74
+ end
75
+ priorities
76
+ end
77
+
78
+ def self.get(key, *tokens)
79
+ tokens = tokens.flatten
80
+ file, _sep, line = caller.reject{|l|
81
+ l =~ /rbbt\/(?:resource\.rb|workflow\.rb)/ or
82
+ l =~ /rbbt\/resource\/path\.rb/ or
83
+ l =~ /rbbt\/util\/misc\.rb/ or
84
+ l =~ /progress-monitor\.rb/
85
+ }.first.partition(":")
86
+
87
+ File.expand_path(file)
88
+
89
+ tokens << ("file:" << file)
90
+ tokens << ("line:" << file << ":" << line)
91
+
92
+ entries = CACHE[key.to_s]
93
+ priorities = {}
94
+ tokens = tokens + ["key:" << key.to_s]
95
+ tokens.each do |token|
96
+ token_prio = match entries, token.to_s
97
+ token_prio.each do |prio, values|
98
+ priorities[prio] ||= []
99
+ priorities[prio].concat(values)
100
+ end
101
+ end
102
+
103
+ return nil if priorities.empty?
104
+
105
+ priorities.sort_by{|p,v| p}.first.last.first
106
+ end
107
+
108
+ self.load_config
109
+ end
@@ -97,5 +97,4 @@ end
97
97
  return true if String === string and string.length < 265 and File.exist? string
98
98
  return false
99
99
  end
100
-
101
100
  end
@@ -532,6 +532,23 @@ class Step
532
532
  end
533
533
  provenance
534
534
  end
535
+
536
+ def config(key, *tokens)
537
+ options = tokens.pop if Hash === tokens.last
538
+ default = options[:default] if options
539
+
540
+ new_tokens = []
541
+ if workflow
542
+ workflow_name = workflow.to_s
543
+ new_tokens << ("workflow:" << workflow_name)
544
+ new_tokens << ("task:" << workflow_name << "#" << task_name.to_s)
545
+ end
546
+ new_tokens << ("task:" << task_name.to_s)
547
+
548
+ value = Rbbt::Config.get(key, tokens + new_tokens)
549
+
550
+ value || default
551
+ end
535
552
  end
536
553
 
537
554
  module Workflow
@@ -21,6 +21,7 @@ class Step
21
21
  def resolve_input_steps
22
22
  step = false
23
23
  pos = 0
24
+ input_options = workflow.task_info(task_name)[:input_options]
24
25
  new_inputs = inputs.collect do |i|
25
26
  begin
26
27
  if Step === i
@@ -38,7 +39,11 @@ class Step
38
39
  if (task.input_options[task.inputs[pos]] || {})[:stream]
39
40
  TSV.get_stream i
40
41
  else
41
- i.load
42
+ if (task.input_options[task.inputs[pos]] || {})[:nofile]
43
+ i.path
44
+ else
45
+ i.load
46
+ end
42
47
  end
43
48
  elsif i.streaming? and (task.input_options[task.inputs[pos]] || {})[:stream]
44
49
  TSV.get_stream i
@@ -47,7 +52,11 @@ class Step
47
52
  if (task.input_options[task.inputs[pos]] || {})[:stream]
48
53
  TSV.get_stream i
49
54
  else
50
- i.load
55
+ if (task.input_options[task.inputs[pos]] || {})[:nofile]
56
+ i.path
57
+ else
58
+ i.load
59
+ end
51
60
  end
52
61
  end
53
62
  else
@@ -0,0 +1,18 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
+ require 'rbbt/util/config'
3
+
4
+ class TestConfig < Test::Unit::TestCase
5
+ def setup
6
+ Rbbt::Config.set({:cpus => 30}, :test_config, :test)
7
+ Rbbt::Config.set({:cpus => 5}, "slow::2", :test)
8
+ end
9
+
10
+ def test_simple
11
+ assert_equal 30, Rbbt::Config.get(:cpus, :test_config)
12
+ end
13
+
14
+ def test_prio
15
+ assert_equal 5, Rbbt::Config.get(:cpus, :slow, :test)
16
+ end
17
+ end
18
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.21.137
4
+ version: 5.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -274,6 +274,7 @@ files:
274
274
  - lib/rbbt/util/concurrency/processes/socket_old.rb
275
275
  - lib/rbbt/util/concurrency/processes/worker.rb
276
276
  - lib/rbbt/util/concurrency/threads.rb
277
+ - lib/rbbt/util/config.rb
277
278
  - lib/rbbt/util/docker.rb
278
279
  - lib/rbbt/util/excel2tsv.rb
279
280
  - lib/rbbt/util/filecache.rb
@@ -474,6 +475,7 @@ files:
474
475
  - test/rbbt/util/test_cmd.rb
475
476
  - test/rbbt/util/test_colorize.rb
476
477
  - test/rbbt/util/test_concurrency.rb
478
+ - test/rbbt/util/test_config.rb
477
479
  - test/rbbt/util/test_excel2tsv.rb
478
480
  - test/rbbt/util/test_filecache.rb
479
481
  - test/rbbt/util/test_log.rb
@@ -530,6 +532,7 @@ test_files:
530
532
  - test/rbbt/util/R/test_plot.rb
531
533
  - test/rbbt/util/R/test_eval.rb
532
534
  - test/rbbt/util/R/test_model.rb
535
+ - test/rbbt/util/test_config.rb
533
536
  - test/rbbt/util/test_log.rb
534
537
  - test/rbbt/util/test_simpleDSL.rb
535
538
  - test/rbbt/util/log/test_progress.rb