squared 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,7 +80,7 @@ module Squared
80
80
  if flag == :target
81
81
  task flag, [:dir, :opts] do |_, args|
82
82
  dir = guard_params(action, flag, args: args, key: :dir)
83
- depend(flag, dir: dir, opts: args.to_a[1..-1] || [])
83
+ depend(flag, dir: dir, opts: args.to_a.drop(1))
84
84
  end
85
85
  else
86
86
  task flag do |_, args|
@@ -106,7 +106,7 @@ module Squared
106
106
  cmd << '--user'
107
107
  append_pip opts, OPT_USER
108
108
  when :target
109
- cmd << "--target=#{shell_escape(basepath(dir), quote: true)}"
109
+ cmd << shell_option('target', basepath(dir), quote: true)
110
110
  append_pip opts, OPT_USER + ['upgrade']
111
111
  append_eager opts
112
112
  when :upgrade
@@ -127,10 +127,10 @@ module Squared
127
127
  end
128
128
  end
129
129
 
130
- def outdated(*)
130
+ def outdated(*, sync: invoked_sync?('outdated'))
131
131
  pip_session 'list', '--outdated'
132
132
  append_pip
133
- run
133
+ run(sync: sync)
134
134
  end
135
135
 
136
136
  def variable_set(key, *val, **)
@@ -164,21 +164,20 @@ module Squared
164
164
 
165
165
  def append_pip(opts = [], list = [])
166
166
  opts.each do |opt|
167
- next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (v = opt.match(/^v+$/))
167
+ next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (v = opt.match(/^verbose|(v+)$/))
168
168
 
169
169
  @session << case opt
170
170
  when 'venv'
171
171
  '--require-virtualenv'
172
172
  else
173
- (v ? "-#{v[0]}" : "--#{opt}")
173
+ (v && v[1] ? "-#{v[1]}" : "--#{opt}")
174
174
  end
175
175
  end
176
- if (val = option('proxy', ignore: false))
177
- @session << "--proxy=#{shell_escape(val, quote: true)}"
178
- end
179
- @session << "--python=#{shell_escape(basepath(val), quote: true)}" if (val = option('python', ignore: false))
180
- @session << "--log=#{shell_escape(basepath(val), quote: true)}" if (val = option('log', ignore: false))
181
- @session << '--user' if option('user')
176
+ val = nil
177
+ @session << shell_option('proxy', val, quote: true) if (val = option('proxy'))
178
+ @session << shell_option('python', basepath(val), quote: true) if (val = option('python'))
179
+ @session << shell_option('log', basepath(val), quote: true) if (val = option('log', ignore: false))
180
+ @session << '--user' if !list.empty? && option('user')
182
181
  @session << '--no-input' if option('no-input')
183
182
  append_nocolor option('no-color')
184
183
  end
@@ -103,9 +103,10 @@ module Squared
103
103
  elsif exception
104
104
  indexerror n, list
105
105
  else
106
- next log.warn "rake task #{n} of #{list.size} (out of range)"
106
+ log.warn "rake task #{n} of #{list.size} (out of range)"
107
+ next
107
108
  end
108
- rake(args.extras.empty? ? cmd : "#{cmd}[#{args.extras.join(',')}]")
109
+ rake(args.extras.empty? ? cmd : "#{cmd}#{shell_escape("[#{args.extras.join(',')}]")}")
109
110
  else
110
111
  rake(*args.to_a)
111
112
  end
@@ -182,20 +183,20 @@ module Squared
182
183
  when :redownload, :local, :'prefer-local'
183
184
  cmd = bundle_session 'install', "--#{flag}"
184
185
  if (val = option('trust-policy', ignore: false))
185
- cmd << "--trust-policy=#{case val
186
- when '0'
187
- 'NoSecurity'
188
- when '1'
189
- 'AlmostNoSecurity'
190
- when '2'
191
- 'LowSecurity'
192
- when '3'
193
- 'MediumSecurity'
194
- when '4'
195
- 'HighSecurity'
196
- else
197
- val
198
- end}"
186
+ cmd << shell_option('trust-policy', case val
187
+ when '0'
188
+ 'NoSecurity'
189
+ when '1'
190
+ 'AlmostNoSecurity'
191
+ when '2'
192
+ 'LowSecurity'
193
+ when '3'
194
+ 'MediumSecurity'
195
+ when '4'
196
+ 'HighSecurity'
197
+ else
198
+ val
199
+ end, escape: false)
199
200
  end
200
201
  append_bundle opts, OPT_INSTALL
201
202
  else
@@ -212,37 +213,36 @@ module Squared
212
213
 
213
214
  from = @copy[:from] if @copy.key?(:from)
214
215
  glob = @copy[:include] if @copy.key?(:include)
215
- pass = @copy[:exclude] if @copy.key?(:exclude)
216
+ exclude = @copy[:exclude] if @copy.key?(:exclude)
216
217
  into = @copy[:into] if @copy.key?(:into)
217
218
  end
218
219
  return unless into
219
220
 
220
221
  dest = Pathname.new(into).realpath
221
- print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
222
+ print_item unless @output[0] || task_invoked?(/\Acopy(?::#{Ruby.ref}|\z)/)
222
223
  glob = as_a(glob || '**/*')
223
224
  as_a(from).each_with_index do |val, i|
224
225
  a = basepath(val)
225
226
  b = dest.join(val)
226
227
  c = glob[i] || glob[0]
227
228
  log.info "cp #{a.join(c)} #{b}"
228
- copy_d(a, b, glob: c, pass: pass, verbose: verbose)
229
+ copy_d(a, b, glob: c, pass: exclude, verbose: verbose)
229
230
  end
230
231
  end
231
232
 
232
- def outdated(rev = nil, opts: [])
233
+ def outdated(rev = nil, opts: [], sync: invoked_sync?('outdated', rev))
233
234
  cmd = bundle_session 'outdated', rev && "--#{rev}"
234
235
  append_bundle opts, OPT_OUTDATED
235
236
  cmd = session_done(cmd)
236
237
  log.info cmd
237
238
  banner = format_banner(cmd)
238
- if invoked_sync?('outdated', rev)
239
- print_item banner
240
- banner = nil
241
- end
239
+ print_item banner if sync
242
240
  start = 0
243
241
  found = 0
244
242
  major = 0
245
243
  pwd_set do
244
+ buffer = []
245
+ out = ->(val) { sync ? puts(val) : buffer << val }
246
246
  IO.popen("#{cmd} --no-color").each do |line|
247
247
  if start > 0
248
248
  unless stdin?
@@ -302,24 +302,24 @@ module Squared
302
302
  when :yellow
303
303
  found += 1
304
304
  end
305
- styles = styles.compact
306
- .map { |s| s == :green || s == :yellow ? color(s) : s }
307
- .flatten
308
- line = sub_style(line, pat: /^((?:\S+\s+){2})(#{Regexp.escape(l)})(.*)$/, styles: styles,
309
- index: 2)
305
+ styles = styles.compact.map { |s| color(s) }.flatten
306
+ line = sub_style(line, pat: /^((?:\S+\s+){2})(#{Regexp.escape(l)})(.*)$/, index: 2, styles: styles)
310
307
  end
311
308
  end
312
- puts "#{start.to_s.rjust(2)}. #{line}"
309
+ out.("#{start.to_s.rjust(2)}. #{line}")
313
310
  start += 1
314
311
  elsif line =~ /^Gem /
315
- print_item banner if banner
316
312
  unless stdin?
317
313
  sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
318
- puts print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub])
314
+ out.(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
319
315
  end
320
316
  start += 1
321
317
  end
322
318
  end
319
+ unless sync
320
+ print_item banner
321
+ puts buffer
322
+ end
323
323
  if found > 0
324
324
  begin
325
325
  if major == 0 && (data = /\b(?:source\s+(["'])(.+?)\1|remote:\s+(\S+))/.match(dependfile.read))
@@ -353,7 +353,7 @@ module Squared
353
353
  cmd << '--all'
354
354
  append_repeat 'skip', opts
355
355
  when :version
356
- cmd << project << "--version=#{shell_escape(version)}"
356
+ cmd << project << shell_option('version', version)
357
357
  end
358
358
  run_rb
359
359
  end
@@ -364,10 +364,11 @@ module Squared
364
364
  end
365
365
 
366
366
  def rake(*cmd)
367
+ rakefile = shell_option('rakefile', Rake.application.rakefile, quote: true, escape: false)
367
368
  if cmd.empty?
368
- run_s 'rake'
369
+ run_s("rake #{rakefile}", chdir: workspace.pwd)
369
370
  else
370
- run_s(*cmd.map { |val| "rake #{val}" }, banner: false)
371
+ run_s(*cmd.map { |val| "rake #{rakefile} #{val}" }, chdir: workspace.pwd, banner: false)
371
372
  end
372
373
  end
373
374
 
@@ -386,9 +387,8 @@ module Squared
386
387
  return false unless @autodetect
387
388
 
388
389
  unsafe = ->(hint) { raise_error('failed to parse', hint: hint) }
389
- out = `gem -C #{shell_quote(path)} list --local -d #{project}`
390
- data = /#{Regexp.escape(project)} \(([^)]+)\)/.match(out)
391
- unsafe.('version') unless data
390
+ out = pwd_set { `gem list --local -d #{project}` }
391
+ unsafe.('version') unless (data = /#{Regexp.escape(project)} \(([^)]+)\)/.match(out))
392
392
  ver = data[1].split(/\s*,\s*/)
393
393
  ver.unshift(@version).uniq! if @version
394
394
  ver.each do |v|
@@ -429,7 +429,7 @@ module Squared
429
429
  if list.include?(opt)
430
430
  @session << "--#{opt}"
431
431
  elsif opt.match(/^g(?:roup)?=(.+)$/)
432
- @session << "--group=#{shell_escape($1)}"
432
+ @session << shell_option('group', $1)
433
433
  end
434
434
  end
435
435
  end
@@ -437,7 +437,7 @@ module Squared
437
437
  def gem_session(*cmd)
438
438
  ret = session('gem', *cmd)
439
439
  if (val = option('config-file', ignore: false))
440
- ret << "--config-file=#{shell_escape(basepath(val), quote: true)}"
440
+ ret << shell_option('config-file', basepath(val), quote: true)
441
441
  end
442
442
  ret << '--norc' if option('norc')
443
443
  ret
@@ -453,10 +453,13 @@ module Squared
453
453
  return @rakelist if @rakelist
454
454
 
455
455
  ret = []
456
- IO.popen("rake -C #{shell_quote(path)} -AT").each do |line|
457
- next unless (data = /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/.match(line))
456
+ pass = Rake::VERSION >= '13.0.4'
457
+ pwd_set(pass: pass) do
458
+ IO.popen("rake#{pass ? " -C #{shell_quote(path)}" : ''} -AT").each do |line|
459
+ next unless (data = /\Arake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/.match(line))
458
460
 
459
- ret << [data[1], data[2]]
461
+ ret << [data[1], data[2]]
462
+ end
460
463
  end
461
464
  @rakelist = ret
462
465
  end
@@ -33,11 +33,11 @@ module Squared
33
33
 
34
34
  def repo(url, manifest = 'latest', run: nil, script: nil, dev: nil, prod: nil, ref: @ref, group: @group)
35
35
  @home = if (val = env('REPO_HOME'))
36
- home = Pathname.new(val)
37
- if main == home.basename.to_s
38
- @root = home.parent
39
- if home.exist?
40
- @root = nil unless home.directory?
36
+ path = Pathname.new(val)
37
+ if main == path.basename.to_s
38
+ @root = path.parent
39
+ if path.exist?
40
+ @root = nil unless path.directory?
41
41
  elsif !@root.exist?
42
42
  @root.mkpath
43
43
  elsif !repo_install?
@@ -45,7 +45,7 @@ module Squared
45
45
  end
46
46
  end
47
47
  raise_error('REPO_HOME', val, hint: 'invalid') unless @root
48
- home.realdirpath
48
+ path.realdirpath
49
49
  elsif (val = env('REPO_ROOT'))
50
50
  @root = Pathname.new(val).realdirpath
51
51
  if !@root.exist?
@@ -54,12 +54,12 @@ module Squared
54
54
  raise_error('REPO_ROOT', val, hint: 'exist') unless repo_confirm
55
55
  end
56
56
  @root.join(main).realdirpath
57
+ elsif repo_install?(parent: true) && (!@home.exist? || @root.join(main) == @home)
58
+ @home
57
59
  elsif repo_install?(@home)
58
60
  @home.join(main)
59
- elsif @home != pwd && repo_install?(pwd)
60
- pwd.join(main)
61
61
  else
62
- @home
62
+ (path = pwd) == @home || !repo_install?(path) ? @home : path.join(main)
63
63
  end
64
64
  @root = @home.parent
65
65
  @manifest_url = url
@@ -106,7 +106,7 @@ module Squared
106
106
  found = true
107
107
  end
108
108
  script_set(data, group: group, ref: ref) unless found
109
- @warning = env_match('REPO_WARN', @warning && !Repo.empty?(@root), suffix: @envname) != false
109
+ @warning = env_match('REPO_WARN', @warning && !root?(@root, pass: ['.repo']), suffix: @envname) != false
110
110
  @extensions << :__repo__
111
111
  elsif script || run
112
112
  if script
@@ -153,7 +153,7 @@ module Squared
153
153
  status = lambda do |val, alt = nil|
154
154
  return 'inactive' unless (ver = branch || alt)
155
155
 
156
- message(@prefix, 'repo', val.sub('{0}', 'opts*=force,rebase,detach,gc,no-update,no-fail'), ver, empty: true)
156
+ message(task_name('repo'), val.sub('{0}', 'opts*=force,rebase,detach,gc,no-update,no-fail'), ver)
157
157
  end
158
158
 
159
159
  namespace(name = task_name('repo')) do |repo|
@@ -230,7 +230,7 @@ module Squared
230
230
  end
231
231
 
232
232
  def repo_install?(dir = root, parent: false)
233
- return true if Repo.empty?(dir) || dir.join('.repo').directory?
233
+ return true if root?(dir, pass: ['.repo']) || dir.join('.repo').directory?
234
234
 
235
235
  parent && root.children.none? { |ent| ent.directory? && ent.basename.to_s[0] != '.' && ent != home }
236
236
  end
@@ -8,13 +8,13 @@ module Squared
8
8
  include Rake::DSL
9
9
  extend Forwardable
10
10
 
11
- TASK_BASE = %i[build depend graph doc test copy clean]
11
+ TASK_BASE = []
12
12
  TASK_BATCH = {}
13
13
  TASK_EXTEND = {}
14
- TASK_KEYS = TASK_BASE + TASK_BATCH.keys
14
+ TASK_KEYS = []
15
15
  TASK_ALIAS = {}
16
16
  TASK_NAME = {}
17
- private_constant :TASK_BASE, :TASK_BATCH, :TASK_KEYS, :TASK_NAME, :TASK_EXTEND
17
+ private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
18
 
19
19
  class << self
20
20
  def add(task, obj)
@@ -47,6 +47,15 @@ module Squared
47
47
  TASK_NAME[key.to_sym] = task.to_sym
48
48
  end
49
49
 
50
+ def base_set(obj)
51
+ TASK_BASE.clear
52
+ .concat((if TASK_KEYS.empty?
53
+ obj.tasks.dup
54
+ else
55
+ obj.tasks.reject { |val| TASK_KEYS.include?(val) }
56
+ end).freeze)
57
+ end
58
+
50
59
  private
51
60
 
52
61
  def key_set(val)
@@ -72,7 +81,7 @@ module Squared
72
81
  id: []
73
82
  }
74
83
  @data = {}
75
- TASK_KEYS.each { |key| @data[key] = [] }
84
+ (TASK_BASE + TASK_KEYS).each { |key| @data[key] = [] }
76
85
  end
77
86
 
78
87
  def populate(proj)
@@ -88,8 +97,9 @@ module Squared
88
97
  items.concat(tasks)
89
98
  end
90
99
  if tasks.size > 1 && (data = batch_get(key)) && data.keys.any? { |ref| proj.ref?(ref) }
91
- desc ws.task_name(t = ws.task_join(proj.name, key), desc: true)
92
- task ws.task_name(t) => tasks
100
+ t = ws.task_join(proj.name, key)
101
+ desc Common::Format.message(*t.split(':'))
102
+ task t => tasks
93
103
  end
94
104
  next unless (b = ws.find_base(proj)) && (n = b.ref.to_s) != g
95
105
 
@@ -154,7 +164,21 @@ module Squared
154
164
  end
155
165
 
156
166
  def extend?(obj, key)
157
- TASK_EXTEND.fetch(key, []).any? { |kind| obj.is_a?(kind) && obj.ref?(kind.ref) }
167
+ return false unless (items = TASK_EXTEND[key]) && !(items = items.select { |kind| obj.is_a?(kind) }).empty?
168
+
169
+ meth = :"#{key}?"
170
+ allref = obj.allref.to_a
171
+ ret = false
172
+ items.each do |kind|
173
+ if kind.instance_methods.include?(meth)
174
+ out = obj.__send__(meth)
175
+ return true if out == 1
176
+ return out if obj.ref?(kind.ref)
177
+ elsif allref.include?(kind.ref)
178
+ ret = true
179
+ end
180
+ end
181
+ ret
158
182
  end
159
183
 
160
184
  def multiple?(val = nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-08 00:00:00.000000000 Z
11
+ date: 2024-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake