taski 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -110
  3. data/examples/README.md +8 -5
  4. data/examples/context_demo.rb +22 -16
  5. data/lib/taski/context.rb +36 -38
  6. data/lib/taski/section.rb +7 -0
  7. data/lib/taski/static_analysis/analyzer.rb +27 -6
  8. data/lib/taski/static_analysis/visitor.rb +30 -6
  9. data/lib/taski/task.rb +60 -16
  10. data/lib/taski/version.rb +1 -1
  11. data/lib/taski.rb +23 -0
  12. metadata +1 -62
  13. data/.gem_rbs_collection/ast/2.4/.rbs_meta.yaml +0 -9
  14. data/.gem_rbs_collection/ast/2.4/ast.rbs +0 -73
  15. data/.gem_rbs_collection/minitest/5.25/.rbs_meta.yaml +0 -9
  16. data/.gem_rbs_collection/minitest/5.25/minitest/abstract_reporter.rbs +0 -52
  17. data/.gem_rbs_collection/minitest/5.25/minitest/assertion.rbs +0 -17
  18. data/.gem_rbs_collection/minitest/5.25/minitest/assertions.rbs +0 -590
  19. data/.gem_rbs_collection/minitest/5.25/minitest/backtrace_filter.rbs +0 -23
  20. data/.gem_rbs_collection/minitest/5.25/minitest/bench_spec.rbs +0 -102
  21. data/.gem_rbs_collection/minitest/5.25/minitest/benchmark.rbs +0 -259
  22. data/.gem_rbs_collection/minitest/5.25/minitest/composite_reporter.rbs +0 -25
  23. data/.gem_rbs_collection/minitest/5.25/minitest/compress.rbs +0 -13
  24. data/.gem_rbs_collection/minitest/5.25/minitest/error_on_warning.rbs +0 -3
  25. data/.gem_rbs_collection/minitest/5.25/minitest/expectation.rbs +0 -2
  26. data/.gem_rbs_collection/minitest/5.25/minitest/expectations.rbs +0 -21
  27. data/.gem_rbs_collection/minitest/5.25/minitest/guard.rbs +0 -64
  28. data/.gem_rbs_collection/minitest/5.25/minitest/mock.rbs +0 -64
  29. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/executor.rbs +0 -46
  30. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test/class_methods.rbs +0 -5
  31. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test.rbs +0 -3
  32. data/.gem_rbs_collection/minitest/5.25/minitest/parallel.rbs +0 -2
  33. data/.gem_rbs_collection/minitest/5.25/minitest/pride_io.rbs +0 -62
  34. data/.gem_rbs_collection/minitest/5.25/minitest/pride_lol.rbs +0 -19
  35. data/.gem_rbs_collection/minitest/5.25/minitest/progress_reporter.rbs +0 -11
  36. data/.gem_rbs_collection/minitest/5.25/minitest/reportable.rbs +0 -53
  37. data/.gem_rbs_collection/minitest/5.25/minitest/reporter.rbs +0 -5
  38. data/.gem_rbs_collection/minitest/5.25/minitest/result.rbs +0 -28
  39. data/.gem_rbs_collection/minitest/5.25/minitest/runnable.rbs +0 -163
  40. data/.gem_rbs_collection/minitest/5.25/minitest/skip.rbs +0 -6
  41. data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl/instance_methods.rbs +0 -48
  42. data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl.rbs +0 -129
  43. data/.gem_rbs_collection/minitest/5.25/minitest/spec.rbs +0 -11
  44. data/.gem_rbs_collection/minitest/5.25/minitest/statistics_reporter.rbs +0 -81
  45. data/.gem_rbs_collection/minitest/5.25/minitest/summary_reporter.rbs +0 -18
  46. data/.gem_rbs_collection/minitest/5.25/minitest/test/lifecycle_hooks.rbs +0 -92
  47. data/.gem_rbs_collection/minitest/5.25/minitest/test.rbs +0 -69
  48. data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_error.rbs +0 -12
  49. data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_warning.rbs +0 -6
  50. data/.gem_rbs_collection/minitest/5.25/minitest/unit/test_case.rbs +0 -3
  51. data/.gem_rbs_collection/minitest/5.25/minitest/unit.rbs +0 -4
  52. data/.gem_rbs_collection/minitest/5.25/minitest.rbs +0 -115
  53. data/.gem_rbs_collection/parallel/1.20/.rbs_meta.yaml +0 -9
  54. data/.gem_rbs_collection/parallel/1.20/parallel.rbs +0 -86
  55. data/.gem_rbs_collection/parser/3.2/.rbs_meta.yaml +0 -9
  56. data/.gem_rbs_collection/parser/3.2/manifest.yaml +0 -7
  57. data/.gem_rbs_collection/parser/3.2/parser.rbs +0 -193
  58. data/.gem_rbs_collection/parser/3.2/polyfill.rbs +0 -4
  59. data/.gem_rbs_collection/rainbow/3.0/.rbs_meta.yaml +0 -9
  60. data/.gem_rbs_collection/rainbow/3.0/global.rbs +0 -7
  61. data/.gem_rbs_collection/rainbow/3.0/presenter.rbs +0 -209
  62. data/.gem_rbs_collection/rainbow/3.0/rainbow.rbs +0 -5
  63. data/.gem_rbs_collection/rake/13.0/.rbs_meta.yaml +0 -9
  64. data/.gem_rbs_collection/rake/13.0/manifest.yaml +0 -2
  65. data/.gem_rbs_collection/rake/13.0/rake.rbs +0 -39
  66. data/.gem_rbs_collection/regexp_parser/2.8/.rbs_meta.yaml +0 -9
  67. data/.gem_rbs_collection/regexp_parser/2.8/regexp_parser.rbs +0 -17
  68. data/.gem_rbs_collection/rubocop/1.57/.rbs_meta.yaml +0 -9
  69. data/.gem_rbs_collection/rubocop/1.57/rubocop.rbs +0 -129
  70. data/.gem_rbs_collection/rubocop-ast/1.30/.rbs_meta.yaml +0 -9
  71. data/.gem_rbs_collection/rubocop-ast/1.30/rubocop-ast.rbs +0 -771
  72. data/.gem_rbs_collection/simplecov/0.22/.rbs_meta.yaml +0 -9
  73. data/.gem_rbs_collection/simplecov/0.22/simplecov.rbs +0 -54
data/lib/taski/task.rb CHANGED
@@ -39,14 +39,14 @@ module Taski
39
39
  @dependencies_cache = nil
40
40
  end
41
41
 
42
- def run
43
- Taski::Context.set_root_task(self)
42
+ def run(context: {})
43
+ Taski.start_context(options: context, root_task: self)
44
44
  validate_no_circular_dependencies!
45
45
  cached_wrapper.run
46
46
  end
47
47
 
48
- def clean
49
- Taski::Context.set_root_task(self)
48
+ def clean(context: {})
49
+ Taski.start_context(options: context, root_task: self)
50
50
  validate_no_circular_dependencies!
51
51
  cached_wrapper.clean
52
52
  end
@@ -65,37 +65,64 @@ module Taski
65
65
  def reset!
66
66
  registry.reset!
67
67
  Taski.reset_global_registry!
68
- Taski::Context.reset!
68
+ Taski.reset_context!
69
69
  @coordinator = nil
70
70
  @circular_dependency_checked = false
71
71
  end
72
72
 
73
73
  def tree
74
- build_tree(self, "", Set.new)
74
+ build_tree(self, "", {}, false)
75
75
  end
76
76
 
77
77
  private
78
78
 
79
- def build_tree(task_class, prefix, visited)
80
- result = "#{task_class.name}\n"
81
- return result if visited.include?(task_class)
79
+ # ANSI color codes
80
+ COLORS = {
81
+ reset: "\e[0m",
82
+ task: "\e[32m", # green
83
+ section: "\e[34m", # blue
84
+ impl: "\e[33m", # yellow
85
+ tree: "\e[90m", # gray
86
+ name: "\e[1m" # bold
87
+ }.freeze
88
+
89
+ def build_tree(task_class, prefix, task_index_map, is_impl, ancestors = Set.new)
90
+ type_label = colored_type_label(task_class)
91
+ impl_prefix = is_impl ? "#{COLORS[:impl]}[impl]#{COLORS[:reset]} " : ""
92
+ task_number = get_task_number(task_class, task_index_map)
93
+ name = "#{COLORS[:name]}#{task_class.name}#{COLORS[:reset]}"
94
+
95
+ # Detect circular reference
96
+ if ancestors.include?(task_class)
97
+ circular_marker = "#{COLORS[:impl]}(circular)#{COLORS[:reset]}"
98
+ return "#{impl_prefix}#{task_number} #{name} #{type_label} #{circular_marker}\n"
99
+ end
100
+
101
+ result = "#{impl_prefix}#{task_number} #{name} #{type_label}\n"
102
+
103
+ # Register task number if not already registered
104
+ task_index_map[task_class] = task_index_map.size + 1 unless task_index_map.key?(task_class)
82
105
 
83
- visited.add(task_class)
84
- dependencies = task_class.cached_dependencies.to_a
106
+ # Add to ancestors for circular detection
107
+ new_ancestors = ancestors + [task_class]
108
+
109
+ # Use static analysis to include Section.impl candidates for visualization
110
+ dependencies = StaticAnalysis::Analyzer.analyze(task_class).to_a
111
+ is_section = section_class?(task_class)
85
112
 
86
113
  dependencies.each_with_index do |dep, index|
87
114
  is_last = (index == dependencies.size - 1)
88
- result += format_dependency_branch(dep, prefix, is_last, visited)
115
+ result += format_dependency_branch(dep, prefix, is_last, task_index_map, is_section, new_ancestors)
89
116
  end
90
117
 
91
118
  result
92
119
  end
93
120
 
94
- def format_dependency_branch(dep, prefix, is_last, visited)
121
+ def format_dependency_branch(dep, prefix, is_last, task_index_map, is_impl, ancestors)
95
122
  connector, extension = tree_connector_chars(is_last)
96
- dep_tree = build_tree(dep, "#{prefix}#{extension}", visited)
123
+ dep_tree = build_tree(dep, "#{prefix}#{extension}", task_index_map, is_impl, ancestors)
97
124
 
98
- result = "#{prefix}#{connector}"
125
+ result = "#{prefix}#{COLORS[:tree]}#{connector}#{COLORS[:reset]}"
99
126
  lines = dep_tree.lines
100
127
  result += lines.first
101
128
  lines.drop(1).each { |line| result += line }
@@ -110,6 +137,23 @@ module Taski
110
137
  end
111
138
  end
112
139
 
140
+ def get_task_number(task_class, task_index_map)
141
+ number = task_index_map[task_class] || (task_index_map.size + 1)
142
+ "#{COLORS[:tree]}[#{number}]#{COLORS[:reset]}"
143
+ end
144
+
145
+ def colored_type_label(klass)
146
+ if section_class?(klass)
147
+ "#{COLORS[:section]}(Section)#{COLORS[:reset]}"
148
+ else
149
+ "#{COLORS[:task]}(Task)#{COLORS[:reset]}"
150
+ end
151
+ end
152
+
153
+ def section_class?(klass)
154
+ defined?(Taski::Section) && klass < Taski::Section
155
+ end
156
+
113
157
  # Use allocate + initialize instead of new to avoid infinite loop
114
158
  # since new is overridden to return TaskWrapper
115
159
  def cached_wrapper
@@ -137,7 +181,7 @@ module Taski
137
181
  singleton_class.undef_method(method) if singleton_class.method_defined?(method)
138
182
 
139
183
  define_singleton_method(method) do
140
- Taski::Context.set_root_task(self)
184
+ Taski.start_context(options: {}, root_task: self)
141
185
  validate_no_circular_dependencies!
142
186
  cached_wrapper.get_exported_value(method)
143
187
  end
data/lib/taski/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taski
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.2"
5
5
  end
data/lib/taski.rb CHANGED
@@ -28,6 +28,29 @@ module Taski
28
28
  end
29
29
  end
30
30
 
31
+ @context_monitor = Monitor.new
32
+
33
+ # Get the current execution context
34
+ # @return [Context, nil] The current context or nil if no task is running
35
+ def self.context
36
+ @context_monitor.synchronize { @context }
37
+ end
38
+
39
+ # Start a new execution context (internal use only)
40
+ # @api private
41
+ def self.start_context(options:, root_task:)
42
+ @context_monitor.synchronize do
43
+ return if @context
44
+ @context = Context.new(options: options, root_task: root_task)
45
+ end
46
+ end
47
+
48
+ # Reset the execution context (internal use only)
49
+ # @api private
50
+ def self.reset_context!
51
+ @context_monitor.synchronize { @context = nil }
52
+ end
53
+
31
54
  def self.global_registry
32
55
  @global_registry ||= Execution::Registry.new
33
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taski
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ahogappa
@@ -49,67 +49,6 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
- - ".gem_rbs_collection/ast/2.4/.rbs_meta.yaml"
53
- - ".gem_rbs_collection/ast/2.4/ast.rbs"
54
- - ".gem_rbs_collection/minitest/5.25/.rbs_meta.yaml"
55
- - ".gem_rbs_collection/minitest/5.25/minitest.rbs"
56
- - ".gem_rbs_collection/minitest/5.25/minitest/abstract_reporter.rbs"
57
- - ".gem_rbs_collection/minitest/5.25/minitest/assertion.rbs"
58
- - ".gem_rbs_collection/minitest/5.25/minitest/assertions.rbs"
59
- - ".gem_rbs_collection/minitest/5.25/minitest/backtrace_filter.rbs"
60
- - ".gem_rbs_collection/minitest/5.25/minitest/bench_spec.rbs"
61
- - ".gem_rbs_collection/minitest/5.25/minitest/benchmark.rbs"
62
- - ".gem_rbs_collection/minitest/5.25/minitest/composite_reporter.rbs"
63
- - ".gem_rbs_collection/minitest/5.25/minitest/compress.rbs"
64
- - ".gem_rbs_collection/minitest/5.25/minitest/error_on_warning.rbs"
65
- - ".gem_rbs_collection/minitest/5.25/minitest/expectation.rbs"
66
- - ".gem_rbs_collection/minitest/5.25/minitest/expectations.rbs"
67
- - ".gem_rbs_collection/minitest/5.25/minitest/guard.rbs"
68
- - ".gem_rbs_collection/minitest/5.25/minitest/mock.rbs"
69
- - ".gem_rbs_collection/minitest/5.25/minitest/parallel.rbs"
70
- - ".gem_rbs_collection/minitest/5.25/minitest/parallel/executor.rbs"
71
- - ".gem_rbs_collection/minitest/5.25/minitest/parallel/test.rbs"
72
- - ".gem_rbs_collection/minitest/5.25/minitest/parallel/test/class_methods.rbs"
73
- - ".gem_rbs_collection/minitest/5.25/minitest/pride_io.rbs"
74
- - ".gem_rbs_collection/minitest/5.25/minitest/pride_lol.rbs"
75
- - ".gem_rbs_collection/minitest/5.25/minitest/progress_reporter.rbs"
76
- - ".gem_rbs_collection/minitest/5.25/minitest/reportable.rbs"
77
- - ".gem_rbs_collection/minitest/5.25/minitest/reporter.rbs"
78
- - ".gem_rbs_collection/minitest/5.25/minitest/result.rbs"
79
- - ".gem_rbs_collection/minitest/5.25/minitest/runnable.rbs"
80
- - ".gem_rbs_collection/minitest/5.25/minitest/skip.rbs"
81
- - ".gem_rbs_collection/minitest/5.25/minitest/spec.rbs"
82
- - ".gem_rbs_collection/minitest/5.25/minitest/spec/dsl.rbs"
83
- - ".gem_rbs_collection/minitest/5.25/minitest/spec/dsl/instance_methods.rbs"
84
- - ".gem_rbs_collection/minitest/5.25/minitest/statistics_reporter.rbs"
85
- - ".gem_rbs_collection/minitest/5.25/minitest/summary_reporter.rbs"
86
- - ".gem_rbs_collection/minitest/5.25/minitest/test.rbs"
87
- - ".gem_rbs_collection/minitest/5.25/minitest/test/lifecycle_hooks.rbs"
88
- - ".gem_rbs_collection/minitest/5.25/minitest/unexpected_error.rbs"
89
- - ".gem_rbs_collection/minitest/5.25/minitest/unexpected_warning.rbs"
90
- - ".gem_rbs_collection/minitest/5.25/minitest/unit.rbs"
91
- - ".gem_rbs_collection/minitest/5.25/minitest/unit/test_case.rbs"
92
- - ".gem_rbs_collection/parallel/1.20/.rbs_meta.yaml"
93
- - ".gem_rbs_collection/parallel/1.20/parallel.rbs"
94
- - ".gem_rbs_collection/parser/3.2/.rbs_meta.yaml"
95
- - ".gem_rbs_collection/parser/3.2/manifest.yaml"
96
- - ".gem_rbs_collection/parser/3.2/parser.rbs"
97
- - ".gem_rbs_collection/parser/3.2/polyfill.rbs"
98
- - ".gem_rbs_collection/rainbow/3.0/.rbs_meta.yaml"
99
- - ".gem_rbs_collection/rainbow/3.0/global.rbs"
100
- - ".gem_rbs_collection/rainbow/3.0/presenter.rbs"
101
- - ".gem_rbs_collection/rainbow/3.0/rainbow.rbs"
102
- - ".gem_rbs_collection/rake/13.0/.rbs_meta.yaml"
103
- - ".gem_rbs_collection/rake/13.0/manifest.yaml"
104
- - ".gem_rbs_collection/rake/13.0/rake.rbs"
105
- - ".gem_rbs_collection/regexp_parser/2.8/.rbs_meta.yaml"
106
- - ".gem_rbs_collection/regexp_parser/2.8/regexp_parser.rbs"
107
- - ".gem_rbs_collection/rubocop-ast/1.30/.rbs_meta.yaml"
108
- - ".gem_rbs_collection/rubocop-ast/1.30/rubocop-ast.rbs"
109
- - ".gem_rbs_collection/rubocop/1.57/.rbs_meta.yaml"
110
- - ".gem_rbs_collection/rubocop/1.57/rubocop.rbs"
111
- - ".gem_rbs_collection/simplecov/0.22/.rbs_meta.yaml"
112
- - ".gem_rbs_collection/simplecov/0.22/simplecov.rbs"
113
52
  - ".standard.yml"
114
53
  - LICENSE
115
54
  - README.md
@@ -1,9 +0,0 @@
1
- ---
2
- name: ast
3
- version: '2.4'
4
- source:
5
- type: git
6
- name: ruby/gem_rbs_collection
7
- revision: 3a33fa6f8e486f880c80ca401f2be1c1f621cf11
8
- remote: https://github.com/ruby/gem_rbs_collection.git
9
- repo_dir: gems
@@ -1,73 +0,0 @@
1
- module AST
2
- interface _ToAst
3
- def to_ast: () -> Node
4
- end
5
-
6
- interface _ToSym
7
- def to_sym: () -> Symbol
8
- end
9
-
10
- class Node
11
- public
12
-
13
- attr_reader children: Array[untyped]
14
- attr_reader hash: String
15
- attr_reader type: Symbol
16
-
17
- alias + concat
18
-
19
- alias << append
20
-
21
- def ==: (untyped other) -> bool
22
-
23
- def append: (untyped element) -> self
24
-
25
- alias clone dup
26
-
27
- def concat: (_ToA[untyped] array) -> self
28
-
29
- def dup: () -> self
30
-
31
- def eql?: (untyped other) -> bool
32
-
33
- def inspect: (?Integer indent) -> String
34
-
35
- alias to_a children
36
-
37
- def to_ast: () -> self
38
-
39
- alias to_s to_sexp
40
-
41
- def to_sexp: (?Integer indent) -> String
42
-
43
- def to_sexp_array: () -> Array[untyped]
44
-
45
- def updated: (?_ToSym? `type`, ?_ToA[untyped]? children, ?Hash[Symbol, untyped]? properties) -> self
46
-
47
- private
48
-
49
- def initialize: (_ToSym `type`, ?_ToA[untyped]? children, ?Hash[Symbol, untyped] properties) -> void
50
-
51
- alias original_dup dup
52
- end
53
-
54
- class Processor
55
- include Mixin
56
-
57
- module Mixin
58
- public
59
-
60
- def handler_missing: (Node node) -> Node?
61
-
62
- def process: (_ToAst? node) -> Node?
63
-
64
- def process_all: (Array[_ToAst] nodes) -> Array[Node]
65
- end
66
- end
67
-
68
- module Sexp
69
- public
70
-
71
- def s: (_ToSym `type`, *untyped children) -> Node
72
- end
73
- end
@@ -1,9 +0,0 @@
1
- ---
2
- name: minitest
3
- version: '5.25'
4
- source:
5
- type: git
6
- name: ruby/gem_rbs_collection
7
- revision: 3a33fa6f8e486f880c80ca401f2be1c1f621cf11
8
- remote: https://github.com/ruby/gem_rbs_collection.git
9
- repo_dir: gems
@@ -1,52 +0,0 @@
1
- # <!-- rdoc-file=lib/minitest.rb -->
2
- # Defines the API for Reporters. Subclass this and override whatever you want.
3
- # Go nuts.
4
- #
5
- class Minitest::AbstractReporter
6
- @mutex: untyped
7
- def initialize: () -> void
8
-
9
- # <!--
10
- # rdoc-file=lib/minitest.rb
11
- # - start()
12
- # -->
13
- # Starts reporting on the run.
14
- #
15
- def start: () -> nil
16
-
17
- # <!--
18
- # rdoc-file=lib/minitest.rb
19
- # - prerecord(klass, name)
20
- # -->
21
- # About to start running a test. This allows a reporter to show that it is
22
- # starting or that we are in the middle of a test run.
23
- #
24
- def prerecord: (untyped klass, untyped name) -> nil
25
-
26
- # <!--
27
- # rdoc-file=lib/minitest.rb
28
- # - record(result)
29
- # -->
30
- # Output and record the result of the test. Call
31
- # [result#result_code](rdoc-ref:Runnable#result_code) to get the result
32
- # character string. Stores the result of the run if the run did not pass.
33
- #
34
- def record: (untyped result) -> nil
35
-
36
- # <!--
37
- # rdoc-file=lib/minitest.rb
38
- # - report()
39
- # -->
40
- # Outputs the summary of the run.
41
- #
42
- def report: () -> nil
43
-
44
- # <!--
45
- # rdoc-file=lib/minitest.rb
46
- # - passed?()
47
- # -->
48
- # Did this run pass?
49
- #
50
- def passed?: () -> true
51
- def synchronize: () { (?) -> untyped } -> untyped
52
- end
@@ -1,17 +0,0 @@
1
- # <!-- rdoc-file=lib/minitest.rb -->
2
- # Represents run failures.
3
- #
4
- class Minitest::Assertion < ::Exception
5
- def error: () -> self
6
-
7
- # <!--
8
- # rdoc-file=lib/minitest.rb
9
- # - location()
10
- # -->
11
- # Where was this run before an assertion was raised?
12
- #
13
- def location: () -> untyped
14
- def result_code: () -> untyped
15
- def result_label: () -> "Failure"
16
- RE: Regexp
17
- end