raka 0.3.8 → 0.3.11

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
  SHA256:
3
- metadata.gz: 011d4dda2d79391c732fb51b383a015ee6f0e6b10f4bd1eb8e976af16100bdf5
4
- data.tar.gz: 3e83d92014c4360dd0180db04e4d7abed90973e35a986dfa9b7afd25c16a1b86
3
+ metadata.gz: 8c18ff3ef2a33821e333fec106d2f64ade89ca0f416d02c914ce5b5eb1601ba0
4
+ data.tar.gz: ca858c3ea2807d209cceebe85ae1d4e987bd125597fd9575bb82d907785ed109
5
5
  SHA512:
6
- metadata.gz: 8fa7be1a0d0e86851c36cb6a57a1638a10eb52a15f03ebc73819dbf1e6984524ecf909ddbad754d72542f800a6ff10bdd80d6feb7e5f4dbe56b9b53d86f26f04
7
- data.tar.gz: f77dbe680509b21ceac1f13c1abe583c96d91ba6156efa88afc94519c4a837b220361851b5e4f56c7d2002eda79d6022c4cebcab6c341eea6af582d92ce919b8
6
+ metadata.gz: 9d8089d3f500a7f57789be879cd7f4f2fbadd2fd64ba0ca2957694289813587a5b603d7c0cb5fe8b5e84c442eccd7274f3203aef4f1e94f5830039e53cc7c3da
7
+ data.tar.gz: 37625d41c5e2d09d47254d0be9497a95fcbc2b33810fb5ab942050763db35f4c2b3d1958c52a478b72eefe2c65e48ae619be52ec252e0365d58978bafaa2b0f9
data/README.md CHANGED
@@ -338,7 +338,7 @@ In the host protocol and the block versions of other protocols, a raka task (the
338
338
  | scope | scope for current task, i.e. the common directory for output, input and dependencies |
339
339
  | target_scope | the inline scope defined in target |
340
340
  | target_scope_captures | captured values by inline scope defined in target |
341
- | rule_scopes | the inline scope defined in target |
341
+ | rule_scopes | the scope components bounded by the rule scopes |
342
342
 
343
343
  ```ruby
344
344
  require 'raka'
@@ -469,13 +469,61 @@ The `input_types` involves the strategy to find inputs. All possible input types
469
469
 
470
470
  ### Scope
471
471
 
472
- Scopes define constraints which help users create rules more precisely. A scope generally refer to a folder and can happen in several places.
472
+ Scopes represent the context of a running task and its components, which are generally folders physically. Users can define scope constraints with rules to help users create rules more precisely. and can happen in several places.
473
473
 
474
- **Task scope** is the scope when executing a task, a.k.a. **scope**. When a rule is matched given a desired output, a task is generated and its scope is the common folder of the output and all dependencies. For example, a rule `csv.out = [csv.in] | ...` can be matched given *out/out.csv* and the task scope is resolved *out/*. The task will thus search for *out/in.csv* as dependency.
474
+ Scope constraints:
475
475
 
476
- **Rule scope** is the scope to restrict possible task scope, given by `Raka::scope`. In the following example, the rule scopes are
476
+ **Rule scope** is the scope to restrict possible task scope. Rule scopes can be layered, each layer with several options, like:
477
477
 
478
- **Target scope.**
478
+ ```ruby
479
+ dsl.scope :de, :fr
480
+ dsl.scope :food, :med
481
+ ...rules
482
+ end
483
+ end
484
+ ```
485
+
486
+ **Target scope** is the scope to restrict a single target. It can be used in the left-hand part of a rule, or as dependencies in the right-hand. For example:
487
+
488
+ ```ruby
489
+ # The constraint "de" only apply to food.csv and fruit__food.csv, not classifier.csv
490
+ csv('de').food.fruit = [csv.classifier] | action
491
+ ```
492
+
493
+ When resolved, scope constraints are verified and scopes are extracted and parsed, including the following concepts:
494
+
495
+ **Scope**(**Task scope**) is the common scope of the task, every target is resolved under the scope.
496
+
497
+ **Rule bounded scopes** (abbr. rule scopes) are the parts of scope bounded by the **Rule scope** constraints.
498
+
499
+ **Target bounded scope** (abbr. target scope) is the part of scope bounded by the **Target scope** constraints.
500
+
501
+ **Output scope** is the scope of output, while **Dep scope** is the scope of dependencies.
502
+
503
+ The following example illustrates the relationships of the above concepts.
504
+
505
+ Rule definition:
506
+
507
+ ```ruby
508
+ dsl.scope :de, :fr,
509
+ dsl.scope :food, :med
510
+ csv('percent_(\d+)').data.cheap = [csv('base').price] | ...
511
+ end
512
+ end
513
+ ```
514
+
515
+ When running `raka out/de/food/percent_50/cheap__data.csv`, the extracted scopes are as follows:
516
+
517
+ ![](https://cdn.rawgit.com/yarray/raka/master/doc/scope.svg)
518
+
519
+ The auto variables are:
520
+
521
+ |var|value|var|value|
522
+ |---|-----|---|-----|
523
+ |$(scope)|out/de/food|$(output_scope)|out/de/food/percent_50|
524
+ |$(rule_scope0)|food|$(rule_scope1)|de|
525
+ |$(target_scope)|percent_50|$(target_scope0)|50|
526
+ |$(dep1_scope)|out/de/food/base|||
479
527
 
480
528
  ## Rakefile Template
481
529
 
@@ -483,4 +531,4 @@ Scopes define constraints which help users create rules more precisely. A scope
483
531
 
484
532
  ## Compare to other tools
485
533
 
486
- Raka borrows some ideas from Drake but not much (currently mainly the name "protocol"). Briefly we have different visions and maybe different suitable senarios.
534
+ Raka borrows some ideas from Drake but not much (currently mainly the name "protocol"). Briefly, we have different visions and maybe different suitable scenarios.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.11
data/bin/raka CHANGED
@@ -63,8 +63,12 @@ opt_str = "-f #{entry}"
63
63
  opt_str += " -m -j #{options[:jobs]}" if options.key?(:jobs)
64
64
  cmd += "#{env}rake #{opt_str} #{extra_args} #{targets}"
65
65
  dry_cmd = 'RUBYOPT="-W0" ' + cmd + ' --dry-run'
66
- _, dry_msg, status = Open3.capture3(dry_cmd)
67
- exit(status) if status != 0
66
+ dry_out, dry_msg, status = Open3.capture3(dry_cmd)
67
+ if status != 0
68
+ puts dry_out
69
+ puts dry_msg
70
+ exit(status.exitstatus)
71
+ end
68
72
  unless (dry_msg.lines.first.chomp =~ /^.*\(.*not_needed.*\)$/).nil?
69
73
  puts 'All targets are up to date'
70
74
  exit(0)
data/lib/raka/compile.rb CHANGED
@@ -34,6 +34,7 @@ class DSLCompiler
34
34
  name: name,
35
35
  deps: deps,
36
36
  deps_str: deps.join(','),
37
+ dep_scopes: deps.map { |d| File.dirname(d) },
37
38
  input: deps.first || '',
38
39
  task: task
39
40
  }
@@ -49,7 +49,7 @@ class Psql
49
49
  param_str = (@params || {}).map { |k, v| "-v #{k}=\"#{v}\"" }.join(' ')
50
50
 
51
51
  bash env, %(
52
- #{sh_cmd(task.scope)} #{param_str} -v _name_=#{task.stem} \
52
+ #{sh_cmd(task.rule_scopes.join('__'))} #{param_str} -v _name_=#{task.output_stem} \
53
53
  -f #{fname} | tee #{fname}.log
54
54
  mv #{fname}.log #{task.name}
55
55
  )
data/lib/raka/token.rb CHANGED
@@ -58,7 +58,7 @@ class Token
58
58
  res = Hash[info.names.zip(info.captures)]
59
59
  unless info[:scope].nil?
60
60
  rule_scopes = Regexp.new(_scope_pattern_).match(info[:scope]).captures
61
- res[:rule_scopes] = rule_scopes[1..-1].reverse
61
+ res[:rule_scopes] = rule_scopes[2..-1].reverse
62
62
  end
63
63
  if !@inline_scope.nil? && !info[:target_scope].nil?
64
64
  segs = Regexp.new(@inline_scope).match(info[:target_scope]).captures
@@ -80,7 +80,7 @@ class Token
80
80
 
81
81
  # attach a new item to the chain
82
82
  def _attach_(item)
83
- Token.new(@compiler, @context, @chain + [item], @inline_scope, @options)
83
+ Token.new(@compiler, @context, @chain + [item], @inline_scope, **@options)
84
84
  end
85
85
 
86
86
  # rubocop:disable Style/MissingRespondToMissing # for DSL not essential
@@ -130,8 +130,12 @@ class Token
130
130
  [auto_input]
131
131
  end
132
132
 
133
+ def _rule_scope_pattern_
134
+ (@context.scopes.map { |layer| "(#{layer.join('|')})" }).join('/') + ')'
135
+ end
136
+
133
137
  def _scope_pattern_
134
- '((?:(\S+)/)?' + (@context.scopes.map { |layer| "(#{layer.join('|')})" }).join('/') + ')'
138
+ '((?:(\S+)/)?' + _rule_scope_pattern_
135
139
  end
136
140
 
137
141
  def _pattern_
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - yarray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-07 00:00:00.000000000 Z
11
+ date: 2022-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake