bahuvrihi-tap 0.10.4 → 0.10.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rap +112 -0
- data/bin/tap +21 -10
- data/cmd/destroy.rb +1 -1
- data/cmd/generate.rb +1 -1
- data/cmd/run.rb +4 -48
- data/cmd/server.rb +3 -1
- data/lib/tap/constants.rb +1 -1
- data/lib/tap/env.rb +37 -39
- data/lib/tap/exe.rb +59 -29
- data/lib/tap/generator/base.rb +1 -1
- data/lib/tap/generator/generators/config/templates/doc.erb +1 -1
- data/lib/tap/generator/generators/file_task/templates/test.erb +1 -1
- data/lib/tap/generator/generators/root/templates/README +0 -0
- data/lib/tap/generator/generators/root/templates/gemspec +3 -4
- data/lib/tap/generator/generators/root/templates/tapfile +3 -3
- data/lib/tap/parser.rb +35 -0
- data/lib/tap/patches/optparse/summarize.rb +62 -0
- data/lib/tap/root.rb +24 -18
- data/lib/tap/support/class_configuration.rb +1 -1
- data/lib/tap/support/configurable_class.rb +3 -1
- data/lib/tap/support/configuration.rb +19 -0
- data/lib/tap/support/constant.rb +14 -2
- data/lib/tap/support/declarations.rb +33 -39
- data/lib/tap/support/dependable.rb +21 -2
- data/lib/tap/support/gems.rb +4 -30
- data/lib/tap/support/gems/rack.rb +14 -11
- data/lib/tap/support/lazy_attributes.rb +1 -1
- data/lib/tap/support/lazydoc.rb +257 -340
- data/lib/tap/support/lazydoc/comment.rb +499 -0
- data/lib/tap/support/lazydoc/config.rb +17 -0
- data/lib/tap/support/lazydoc/declaration.rb +20 -0
- data/lib/tap/support/lazydoc/document.rb +118 -0
- data/lib/tap/support/lazydoc/method.rb +24 -0
- data/lib/tap/support/manifest.rb +33 -4
- data/lib/tap/support/validation.rb +56 -0
- data/lib/tap/task.rb +46 -44
- data/lib/tap/tasks/dump.rb +15 -10
- data/lib/tap/tasks/load.rb +25 -0
- data/lib/tap/tasks/rake.rb +2 -2
- data/lib/tap/test.rb +55 -36
- data/lib/tap/test/file_methods.rb +204 -178
- data/lib/tap/test/file_methods_class.rb +4 -18
- data/lib/tap/test/script_methods.rb +76 -90
- data/lib/tap/test/script_methods/regexp_escape.rb +92 -0
- data/lib/tap/test/script_methods/script_test.rb +4 -2
- data/lib/tap/test/subset_methods.rb +46 -49
- data/lib/tap/test/subset_methods_class.rb +17 -54
- data/lib/tap/test/tap_methods.rb +1 -5
- data/lib/tap/test/utils.rb +142 -32
- metadata +12 -3
- data/lib/tap/support/command_line.rb +0 -55
- data/lib/tap/support/comment.rb +0 -270
data/lib/tap/generator/base.rb
CHANGED
@@ -6,7 +6,7 @@ module Tap
|
|
6
6
|
class << self
|
7
7
|
def lazydoc(resolve=true)
|
8
8
|
lazydoc = super(false)
|
9
|
-
lazydoc.
|
9
|
+
lazydoc[self.to_s]['args'] ||= lazydoc.register_method(:manifest, Task::Args)
|
10
10
|
super
|
11
11
|
end
|
12
12
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
###############################################################################
|
4
4
|
<% configurations.each do |key, config| %>
|
5
5
|
|
6
|
-
<% Comment.wrap(config.desc.to_s
|
6
|
+
<% Lazydoc::Comment.wrap(config.desc.to_s, 50, 2).each do |line| %>
|
7
7
|
# <%= line %>
|
8
8
|
<% end %>
|
9
9
|
<%= config.default == nil ? '#' : '' %><%= yamlize({key.to_s => config.default}) %>
|
@@ -17,7 +17,7 @@ class <%= const.name %>Test < Test::Unit::TestCase
|
|
17
17
|
t = <%= const.name %>.new
|
18
18
|
assert_files do |input_files|
|
19
19
|
input_files.each do |source|
|
20
|
-
target =
|
20
|
+
target = method_root.filepath(:output, 'result.yml')
|
21
21
|
t.enq(source, target)
|
22
22
|
end
|
23
23
|
|
File without changes
|
@@ -5,24 +5,23 @@ Gem::Specification.new do |s|
|
|
5
5
|
#s.email = "your.email@pubfactory.edu"
|
6
6
|
#s.homepage = "http://rubyforge.org/projects/<%= project_name %>/"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.summary = "<%= project_name %>
|
8
|
+
s.summary = "<%= project_name %>"
|
9
9
|
s.require_path = "lib"
|
10
10
|
s.test_file = "test/tap_test_suite.rb"
|
11
11
|
#s.rubyforge_project = "<%= project_name %>"
|
12
12
|
#s.has_rdoc = true
|
13
13
|
s.add_dependency("tap", "~> <%= Tap::VERSION %>")
|
14
14
|
|
15
|
-
# list extra rdoc files
|
15
|
+
# list extra rdoc files here.
|
16
16
|
s.extra_rdoc_files = %W{
|
17
|
+
README
|
17
18
|
}
|
18
19
|
|
19
20
|
# list the files you want to include here. you can
|
20
21
|
# check this manifest using 'rake :print_manifest'
|
21
22
|
s.files = %W{
|
22
23
|
<%= config_file ? " tap.yml\n" : '' %>
|
23
|
-
<%= tapfile ? " tapfile.rb\n" : '' %>
|
24
24
|
test/tap_test_helper.rb
|
25
25
|
test/tap_test_suite.rb
|
26
|
-
test/tapfile_test.rb
|
27
26
|
}
|
28
27
|
end
|
@@ -2,7 +2,7 @@ require 'tap'
|
|
2
2
|
|
3
3
|
# Goodnight::manifest your basic goodnight moon task
|
4
4
|
# Prints the input with a configurable message.
|
5
|
-
Tap.
|
6
|
-
|
7
|
-
|
5
|
+
Tap.tasc('goodnight', :message => 'goodnight') do |name|
|
6
|
+
log message, name
|
7
|
+
"#{message} #{name}"
|
8
8
|
end
|
data/lib/tap/parser.rb
CHANGED
@@ -378,6 +378,41 @@ module Tap
|
|
378
378
|
segments
|
379
379
|
end
|
380
380
|
|
381
|
+
def build(app)
|
382
|
+
# attempt lookup and instantiation of the task classes
|
383
|
+
# note that instances is actually an array of [instance, args]
|
384
|
+
# pairs, where the instance will be enqued with the args
|
385
|
+
instances = tasks.collect do |args|
|
386
|
+
yield(args)
|
387
|
+
end
|
388
|
+
|
389
|
+
# build the workflow
|
390
|
+
workflow.each_with_index do |(type, target_indicies), source_index|
|
391
|
+
next if type == nil
|
392
|
+
|
393
|
+
targets = if target_indicies.kind_of?(Array)
|
394
|
+
target_indicies.collect {|i| instances[i][0] }
|
395
|
+
else
|
396
|
+
instances[target_indicies][0]
|
397
|
+
end
|
398
|
+
|
399
|
+
instances[source_index][0].send(type, *targets)
|
400
|
+
end
|
401
|
+
|
402
|
+
# build queues
|
403
|
+
queues = rounds.collect do |round|
|
404
|
+
round.each do |index|
|
405
|
+
task, args = instances[index]
|
406
|
+
task.enq(*args)
|
407
|
+
end
|
408
|
+
|
409
|
+
app.queue.clear
|
410
|
+
end
|
411
|
+
queues.delete_if {|queue| queue.empty? }
|
412
|
+
|
413
|
+
queues
|
414
|
+
end
|
415
|
+
|
381
416
|
protected
|
382
417
|
|
383
418
|
# Returns the index of the next argv to be parsed.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# This patch fixes some formatting errors in OptParse.
|
3
|
+
# In particular, long config names and config names of
|
4
|
+
# 13 characters in length cause either ugly wrapping,
|
5
|
+
# or an outright error. It could also wrap long comments,
|
6
|
+
# although that feature is currently disabled.
|
7
|
+
#
|
8
|
+
# See:
|
9
|
+
# - http://bahuvrihi.lighthouseapp.com/projects/9908/tickets/97-unlucky-13-character-config-name#ticket-97-1
|
10
|
+
|
11
|
+
class OptionParser # :nodoc:
|
12
|
+
class Switch # :nodoc:
|
13
|
+
undef_method :summarize
|
14
|
+
|
15
|
+
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
|
16
|
+
sopts, lopts = [], []
|
17
|
+
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
|
18
|
+
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
|
19
|
+
return if sopts.empty? and lopts.empty? # completely hidden
|
20
|
+
|
21
|
+
left = [sopts.join(', ')]
|
22
|
+
right = desc.dup
|
23
|
+
|
24
|
+
while str = lopts.shift
|
25
|
+
l = left[-1].length + str.length
|
26
|
+
l += arg.length if left.size == 1 && arg
|
27
|
+
#l < max or left << ''
|
28
|
+
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << str
|
29
|
+
end
|
30
|
+
|
31
|
+
#left[0] << arg if arg
|
32
|
+
left[-1] << arg if arg
|
33
|
+
|
34
|
+
mlen = left.collect {|s| s.length}.max.to_i
|
35
|
+
while mlen > width and l = left.shift
|
36
|
+
mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
|
37
|
+
yield(indent + l)
|
38
|
+
end
|
39
|
+
|
40
|
+
# uncomment to justify long comments
|
41
|
+
# comment_indent = width + indent.length + 2
|
42
|
+
# split_right = []
|
43
|
+
# right.each do |obj|
|
44
|
+
# start_index = 0
|
45
|
+
# str = obj.to_str
|
46
|
+
# while start_index < str.length
|
47
|
+
# split_right << str[start_index, comment_indent].strip
|
48
|
+
# start_index += comment_indent
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
# right = split_right
|
52
|
+
|
53
|
+
while begin l = left.shift; r = right.shift; l or r end
|
54
|
+
l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
|
55
|
+
#yield(indent + l)
|
56
|
+
yield(indent + l) unless l == nil
|
57
|
+
end
|
58
|
+
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/tap/root.rb
CHANGED
@@ -78,19 +78,19 @@ module Tap
|
|
78
78
|
# as in: relative_filepath('/path', '/path') then the first arg returns nil, and an
|
79
79
|
# empty string is returned
|
80
80
|
expanded_path[( expanded_dir.chomp("/").length + 1)..-1] || ""
|
81
|
-
end
|
82
|
-
|
83
|
-
# Generates a target filepath translated from the source_dir to
|
84
|
-
# the target_dir. Raises an error if the filepath is not relative
|
85
|
-
# to the source_dir.
|
86
|
-
#
|
87
|
-
# Root.translate("/path/to/file.txt", "/path", "/another/path") # => '/another/path/to/file.txt'
|
88
|
-
#
|
89
|
-
def translate(path, source_dir, target_dir)
|
90
|
-
unless relative_path = relative_filepath(source_dir, path)
|
91
|
-
raise ArgumentError, "\n#{path}\nis not relative to:\n#{source_dir}"
|
92
|
-
end
|
93
|
-
File.join(target_dir, relative_path)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Generates a target filepath translated from the source_dir to
|
84
|
+
# the target_dir. Raises an error if the filepath is not relative
|
85
|
+
# to the source_dir.
|
86
|
+
#
|
87
|
+
# Root.translate("/path/to/file.txt", "/path", "/another/path") # => '/another/path/to/file.txt'
|
88
|
+
#
|
89
|
+
def translate(path, source_dir, target_dir)
|
90
|
+
unless relative_path = relative_filepath(source_dir, path)
|
91
|
+
raise ArgumentError, "\n#{path}\nis not relative to:\n#{source_dir}"
|
92
|
+
end
|
93
|
+
File.join(target_dir, relative_path)
|
94
94
|
end
|
95
95
|
|
96
96
|
# Lists all unique paths matching the input glob patterns.
|
@@ -293,8 +293,7 @@ module Tap
|
|
293
293
|
# Tap::Root.minimal_match?('dir/file-0.1.0.txt', 'r/file') # => true
|
294
294
|
#
|
295
295
|
def minimal_match?(path, mini_path)
|
296
|
-
extname =
|
297
|
-
extname = '' if extname =~ /^\.\d+$/
|
296
|
+
extname = non_version_extname(mini_path)
|
298
297
|
version = mini_path =~ /(-\d+(\.\d+)*)#{extname}$/ ? $1 : ''
|
299
298
|
|
300
299
|
match_path = case
|
@@ -303,10 +302,10 @@ module Tap
|
|
303
302
|
path
|
304
303
|
when !version.empty?
|
305
304
|
# match up to version
|
306
|
-
path.chomp(
|
305
|
+
path.chomp(non_version_extname(path))
|
307
306
|
else
|
308
307
|
# match up base
|
309
|
-
path.chomp(
|
308
|
+
path.chomp(non_version_extname(path)).sub(/(-\d+(\.\d+)*)$/, '')
|
310
309
|
end
|
311
310
|
|
312
311
|
# key ends with pattern AND basenames of each are equal...
|
@@ -398,6 +397,13 @@ module Tap
|
|
398
397
|
just_one
|
399
398
|
end
|
400
399
|
|
400
|
+
# utility method for minimal_match -- returns a non-version
|
401
|
+
# extname, or an empty string if the path ends in a version.
|
402
|
+
def non_version_extname(path) # :nodoc:
|
403
|
+
extname = File.extname(path)
|
404
|
+
extname =~ /^\.\d+$/ ? '' : extname
|
405
|
+
end
|
406
|
+
|
401
407
|
end
|
402
408
|
|
403
409
|
include Support::Versions
|
@@ -540,7 +546,7 @@ module Tap
|
|
540
546
|
#
|
541
547
|
# fp = r.filepath(:in, 'path/to/file.txt') # => '/root_dir/in/path/to/file.txt'
|
542
548
|
# r.translate(fp, :in, :out) # => '/root_dir/out/path/to/file.txt'
|
543
|
-
def translate(filepath, source_dir, target_dir)
|
549
|
+
def translate(filepath, source_dir, target_dir)
|
544
550
|
Root.translate(filepath, self[source_dir], self[target_dir])
|
545
551
|
end
|
546
552
|
|
@@ -125,7 +125,7 @@ module Tap
|
|
125
125
|
def code_comments
|
126
126
|
code_comments = []
|
127
127
|
values.each do |config|
|
128
|
-
code_comments << config.desc if config.desc.kind_of?(Comment)
|
128
|
+
code_comments << config.desc if config.desc.kind_of?(Lazydoc::Comment)
|
129
129
|
end
|
130
130
|
code_comments
|
131
131
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tap/support/class_configuration'
|
2
2
|
require 'tap/support/validation'
|
3
3
|
require 'tap/support/lazy_attributes'
|
4
|
+
require 'tap/support/lazydoc/config'
|
4
5
|
|
5
6
|
module Tap
|
6
7
|
module Support
|
@@ -251,7 +252,7 @@ module Tap
|
|
251
252
|
case line
|
252
253
|
when /in .config.$/ then next
|
253
254
|
when Lazydoc::CALLER_REGEXP
|
254
|
-
options[:desc] = Lazydoc.register($1, $3.to_i - 1)
|
255
|
+
options[:desc] = Lazydoc.register($1, $3.to_i - 1, Lazydoc::Config)
|
255
256
|
break
|
256
257
|
end
|
257
258
|
end if options[:desc] == nil
|
@@ -288,6 +289,7 @@ module Tap
|
|
288
289
|
else nil
|
289
290
|
end
|
290
291
|
end
|
292
|
+
|
291
293
|
end
|
292
294
|
end
|
293
295
|
end
|
@@ -119,6 +119,25 @@ module Tap
|
|
119
119
|
self.default(false) == another.default(false)
|
120
120
|
end
|
121
121
|
|
122
|
+
def to_optparse_argv
|
123
|
+
argtype = case arg_type
|
124
|
+
when :optional
|
125
|
+
"#{long} [#{arg_name}]"
|
126
|
+
when :switch
|
127
|
+
long(true)
|
128
|
+
when :flag
|
129
|
+
long
|
130
|
+
when :list
|
131
|
+
"#{long} a,b,c"
|
132
|
+
when :mandatory, nil
|
133
|
+
"#{long} #{arg_name}"
|
134
|
+
else
|
135
|
+
raise "unknown arg_type: #{arg_type}"
|
136
|
+
end
|
137
|
+
|
138
|
+
[short, argtype, desc].compact
|
139
|
+
end
|
140
|
+
|
122
141
|
end
|
123
142
|
end
|
124
143
|
end
|
data/lib/tap/support/constant.rb
CHANGED
@@ -53,18 +53,30 @@ module Tap
|
|
53
53
|
require_path ? Support::Lazydoc[require_path] : nil
|
54
54
|
end
|
55
55
|
|
56
|
+
# True if another is a Constant with the same name
|
57
|
+
# and require_path as self.
|
56
58
|
def ==(another)
|
57
59
|
another.kind_of?(Constant) &&
|
58
60
|
another.name == self.name &&
|
59
61
|
another.require_path == self.require_path
|
60
62
|
end
|
61
|
-
|
63
|
+
|
64
|
+
# Looks up and returns the constant indicated by name.
|
65
|
+
# If the constant cannot be found, the constantize
|
66
|
+
# requires require_path and tries again. Raises an
|
67
|
+
# NameError if the constant cannot be found.
|
62
68
|
def constantize
|
63
69
|
name.try_constantize do |const_name|
|
64
|
-
require require_path
|
70
|
+
require require_path if require_path
|
65
71
|
name.constantize
|
66
72
|
end
|
67
73
|
end
|
74
|
+
|
75
|
+
# Returns a string like:
|
76
|
+
# "#<Tap::Support::Constant:object_id Const::Name (require_path)>"
|
77
|
+
def inspect
|
78
|
+
"#<#{self.class}:#{object_id} #{name}#{@require_path == nil ? "" : " (#{@require_path})"}>"
|
79
|
+
end
|
68
80
|
end
|
69
81
|
end
|
70
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'tap/support/lazydoc/declaration'
|
2
|
+
|
1
3
|
module Tap
|
2
4
|
module Support
|
3
5
|
module Declarations
|
@@ -20,18 +22,6 @@ module Tap
|
|
20
22
|
def tasc(name, configs={}, &block)
|
21
23
|
declare(Tap::Task, name, configs, &block)
|
22
24
|
end
|
23
|
-
|
24
|
-
def task(name, configs={}, &block)
|
25
|
-
mod_declare(Tap::Task, name, configs, &block)
|
26
|
-
end
|
27
|
-
|
28
|
-
def file_tasc(name, configs={}, &block)
|
29
|
-
declare(Tap::FileTask, name, configs, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def file_task(name, configs={}, &block)
|
33
|
-
mod_declare(Tap::FileTask, name, configs, &block)
|
34
|
-
end
|
35
25
|
|
36
26
|
protected
|
37
27
|
|
@@ -70,7 +60,7 @@ module Tap
|
|
70
60
|
arity
|
71
61
|
end
|
72
62
|
|
73
|
-
def
|
63
|
+
def parse(declaration)
|
74
64
|
# Extract name and dependencies from declaration
|
75
65
|
name, dependencies = case declaration
|
76
66
|
when Hash then declaration.to_a[0]
|
@@ -100,38 +90,42 @@ module Tap
|
|
100
90
|
end
|
101
91
|
end
|
102
92
|
|
103
|
-
|
93
|
+
[name, dependencies]
|
94
|
+
end
|
95
|
+
|
96
|
+
def declare(klass, declaration, configs={}, options={}, &block)
|
97
|
+
# parse the declaration
|
98
|
+
name, dependencies = parse(declaration)
|
99
|
+
|
100
|
+
# nest the constant name
|
104
101
|
base = (self.kind_of?(Module) ? self : self.class).instance_variable_get(:@tap_declaration_base)
|
105
102
|
name = File.join(base, name.to_s)
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def mod_declare(klass, declaration, configs={}, &block)
|
111
|
-
options = {}
|
112
|
-
options[:arity] = arity(block) if block_given?
|
113
|
-
|
114
|
-
subclass = declare(klass, declaration, configs, options)
|
104
|
+
# generate the subclass
|
105
|
+
subclass = klass.subclass(name, configs, dependencies, options, &block)
|
115
106
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
107
|
+
# register documentation
|
108
|
+
caller[1] =~ Lazydoc::CALLER_REGEXP
|
109
|
+
subclass.source_file = File.expand_path($1)
|
110
|
+
lazydoc = subclass.lazydoc(false)
|
111
|
+
lazydoc[subclass.to_s]['manifest'] = lazydoc.register($3.to_i - 1, Lazydoc::Declaration)
|
112
|
+
|
113
|
+
arity = options[:arity] || (block_given? ? block.arity : -1)
|
114
|
+
comment = Lazydoc::Comment.new
|
115
|
+
comment.subject = case
|
116
|
+
when arity > 0
|
117
|
+
Array.new(arity, "INPUT").join(' ')
|
118
|
+
when arity < 0
|
119
|
+
array = Array.new(-1 * arity - 1, "INPUT")
|
120
|
+
array << "INPUTS..."
|
121
|
+
array.join(' ')
|
122
|
+
else ""
|
131
123
|
end
|
132
|
-
subclass.
|
124
|
+
lazydoc[subclass.to_s]['args'] ||= comment
|
125
|
+
|
126
|
+
subclass
|
133
127
|
end
|
134
|
-
|
128
|
+
|
135
129
|
end
|
136
130
|
end
|
137
131
|
end
|