squared 0.3.10 → 0.4.0

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.
@@ -7,31 +7,31 @@ module Squared
7
7
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
8
8
  DIR_RUBY = (GEMFILE + Rake::Application::DEFAULT_RAKEFILES + ['README.rdoc']).freeze
9
9
  OPT_BUNDLE = {
10
- common: %w[no-color V|verbose retry=i].freeze,
10
+ common: %w[no-color V verbose retry=i].freeze,
11
11
  install: %w[frozen no-cache no-prune system path=p binstubs=p? standalone=q? target-rbconfig=p trust-policy=b
12
12
  with=q without=q].freeze,
13
13
  install_base: %w[full-index quiet retry gemfile=p j|jobs=i].freeze,
14
- update: %w[conservative local pre redownload ruby strict bundler=e? g|group=q source=e].freeze,
14
+ update: %w[conservative local pre redownload ruby strict bundler=b? g|group=q source=b].freeze,
15
15
  outdated: %w[filter-major filter-minor filter-patch groups local parseable pre only-explicit strict
16
- update-strict g|group=q source=e].freeze,
16
+ update-strict g|group=q source=b].freeze,
17
17
  exec: %w[gemfile=p].freeze,
18
18
  check: %w[dry-run gemfile=p].freeze
19
19
  }.freeze
20
20
  OPT_GEM = {
21
21
  common: %w[backtrace debug q|quiet no-verbose norc silent V|verbose config-file=p].freeze,
22
- install: %w[version=e].freeze,
23
- update: %w[system=e?].freeze,
22
+ install: %w[version=b].freeze,
23
+ update: %w[system=b?].freeze,
24
24
  outdated: %w[b|both clear-sources l|local no-http-proxy r|remote B|bulk-threshold=i p|http-proxy=q?
25
25
  platform=q source=q].freeze,
26
- push: %w[no-http-proxy attestation=p host=q key=e otp=e p|http-proxy=q?].freeze,
26
+ push: %w[no-http-proxy attestation=p host=q key=b otp=b p|http-proxy=q?].freeze,
27
27
  build: %w[force strict o|output=p platform=q].freeze,
28
- exec: %w[conservative prerelease no-prerelease g|gem=v version=e].freeze,
28
+ exec: %w[conservative prerelease no-prerelease g|gem=b version=b].freeze,
29
29
  pristine: %w[all env-shebang extensions no-env-shebang no-extensions only-executables only-missing-extensions
30
- only-plugins n|bindir=p i|install-dir=p skip=e v|version=e].freeze,
30
+ only-plugins n|bindir=p i|install-dir=p skip=b v|version=b].freeze,
31
31
  shared: %w[f b|both clear-sources conservative default development development-all E|explain
32
32
  ignore-dependencies l|local N|no-document r|remote w|vendor n|bindir=p build-root=p
33
33
  bulk-threshold=i document=b? g|file=p? p|http-proxy=q i|install-dir=p platform=q s|source=q
34
- target-rbconfig=p? P|trust-policy=b without=e].freeze,
34
+ target-rbconfig=p? P|trust-policy=b without=b].freeze,
35
35
  shared_no: %w[env-shebang force format-executable http-proxy lock minimal-deps post-install-message
36
36
  prerelease suggestions user-install wrappers].freeze
37
37
  }.freeze
@@ -70,7 +70,7 @@ module Squared
70
70
  def initialize(*, autodetect: false, **kwargs)
71
71
  super
72
72
  if @pass.include?(Ruby.ref)
73
- initialize_ref(Ruby.ref)
73
+ initialize_ref Ruby.ref
74
74
  initialize_logger(**kwargs)
75
75
  else
76
76
  initialize_build(Ruby.ref, **kwargs)
@@ -83,7 +83,7 @@ module Squared
83
83
 
84
84
  begin
85
85
  File.foreach(file) do |line|
86
- next unless line =~ %r{\brequire\s+(["'])bundler/gem_tasks\1}
86
+ next unless line.match?(%r{\brequire\s+(["'])bundler/gem_tasks\1})
87
87
 
88
88
  cmd = bundle_output('exec', 'rake').to_s
89
89
  @output[0] = "#{cmd} build"
@@ -155,7 +155,7 @@ module Squared
155
155
  when 'gem'
156
156
  case flag
157
157
  when :outdated, :build, :push, :exec
158
- format_desc(action, flag, 'opts*', before: flag == :exec ? 'command+' : nil)
158
+ format_desc action, flag, 'opts*'
159
159
  task flag do |_, args|
160
160
  gemx flag, args.to_a
161
161
  end
@@ -178,6 +178,7 @@ module Squared
178
178
  if @depend
179
179
  super
180
180
  elsif outdated?
181
+ workspace.rev_clear name
181
182
  cmd = bundle_session 'install'
182
183
  if (n = option('jobs')).to_i > 0
183
184
  cmd << "-j#{n}"
@@ -186,15 +187,13 @@ module Squared
186
187
  end
187
188
  end
188
189
 
189
- def copy(from: 'lib', into: @gemdir, override: false, **kwargs)
190
- glob = kwargs[:include]
191
- pass = kwargs[:exclude]
190
+ def copy(from: 'lib', include: nil, exclude: nil, into: @gemdir, override: false)
192
191
  if @copy && !override
193
- return super if runnable?(@copy)
192
+ return super unless @copy.is_a?(Hash)
194
193
 
195
194
  from = @copy[:from] if @copy.key?(:from)
196
195
  glob = @copy[:include] if @copy.key?(:include)
197
- pass = @copy[:exclude] if @copy.key?(:exclude)
196
+ exclude = @copy[:exclude] if @copy.key?(:exclude)
198
197
  into = @copy[:into] if @copy.key?(:into)
199
198
  end
200
199
  return unless into
@@ -206,10 +205,10 @@ module Squared
206
205
  as_a(from).each_with_index do |val, i|
207
206
  a = basepath(val)
208
207
  b = dest.join(val)
209
- c = glob[i] || glob.first
208
+ c = glob[i] || glob[0]
210
209
  log.info "cp #{a.join(c)} #{b}"
211
210
  begin
212
- copy_dir(a, b, c, pass: pass, verbose: verbose)
211
+ copy_dir(a, b, c, pass: exclude, verbose: verbose)
213
212
  rescue StandardError => e
214
213
  log.error e
215
214
  ret = on(:error, :copy, e)
@@ -303,7 +302,7 @@ module Squared
303
302
  end
304
303
  end
305
304
  out.("#{start.to_s.rjust(2)}. #{line}")
306
- elsif line =~ /^Gem /
305
+ elsif line.start_with?('Gem')
307
306
  unless stdin?
308
307
  sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
309
308
  out.(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
@@ -344,8 +343,7 @@ module Squared
344
343
 
345
344
  def update(flag, opts = [])
346
345
  bundle_session 'update', "--#{flag}"
347
- append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
348
- append: flag != :all)
346
+ append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common]
349
347
  run_rb(from: :update)
350
348
  end
351
349
 
@@ -369,11 +367,8 @@ module Squared
369
367
  when :install, :'user-install', :update
370
368
  list += OPT_GEM[:shared]
371
369
  no = OPT_GEM[:shared_no]
372
- first = true
373
- when :pristine
374
- first = true
375
370
  end
376
- opts, pat = option_sanitize(opts, list, no: no, first: first)
371
+ opts, pat = option_sanitize(opts, list, no: no, first: true)
377
372
  out = []
378
373
  opts.each do |opt|
379
374
  if opt =~ pat
@@ -394,14 +389,14 @@ module Squared
394
389
  pwd_set(pass: !pwd.nil?, from: from) do
395
390
  items = [[%w[Gem Current Latest], nil]]
396
391
  IO.popen(cmd.done).each do |line|
397
- if (data = line.match(/^(\S+) \((\S+) < ([^)]+)\)$/))
398
- cur = semscan(data[2])
399
- lat = semscan(data[3])
400
- items << [data.to_a.drop(1), if semmajor?(cur, lat)
401
- %i[green bold]
402
- else
403
- cur[2] == lat[2] ? [:yellow] : [:green]
404
- end]
392
+ if line =~ /^(\S+) \((\S+) < ([^)]+)\)$/
393
+ cur = semscan($2)
394
+ lat = semscan($3)
395
+ items << [$~.to_a.drop(1), if semmajor?(cur, lat)
396
+ %i[green bold]
397
+ else
398
+ cur[2] == lat[2] ? [:yellow] : [:green]
399
+ end]
405
400
  else
406
401
  puts line
407
402
  end
@@ -433,7 +428,7 @@ module Squared
433
428
  line = sub_style(line, pat: /^(.+)(?<!\dm)(#{a}|#{c})(.*)$/, styles: theme[:header], index: 2)
434
429
  end
435
430
  puts line
436
- puts '-' * n
431
+ puts sub_style(ARG[:BORDER][1] * n, styles: borderstyle)
437
432
  else
438
433
  styles = item.last
439
434
  a = a.ljust(d)
@@ -467,25 +462,23 @@ module Squared
467
462
  when :build, :push
468
463
  if !out.empty?
469
464
  if flag == :build && out.size == 1
470
- cmd << basepath(out.first)
465
+ cmd << shell_quote(basepath(out.first))
471
466
  else
472
- raise_error('gem', flag, out.join(', '), hint: 'unrecognized option')
467
+ raise_error("unknown args: #{out.join(', ')}", hint: flag)
473
468
  end
474
469
  elsif flag == :build
475
470
  cmd << "#{project}.gemspec"
476
471
  end
477
472
  when :exec
478
- raise_error('gem', flag, hint: 'no command given') if out.empty?
479
- cmd << project << out.join(' ')
473
+ raise_error('no command given', hint: flag) if out.empty?
474
+ cmd << out.join(' ')
480
475
  else
481
- if out.empty? && cmd.none? { |val| val =~ /^--system(?:=|$)/ }
482
- raise_error('gem', flag, hint: 'no gemname given')
483
- end
476
+ raise_error('no gemname given', hint: flag) if out.empty? && !session_arg?('system')
484
477
  if flag == :pristine
485
478
  if session_arg?('all')
486
479
  append_repeat 'skip', out
487
480
  out.clear
488
- elsif (n = out.first =~ /@/)
481
+ elsif (n = out.first.index('@'))
489
482
  name = out.first
490
483
  if n == 0
491
484
  cmd << project
@@ -508,16 +501,16 @@ module Squared
508
501
  cmd = bundle_session flag
509
502
  case flag
510
503
  when 'exec', 'check'
511
- args = option_sanitize(args, OPT_BUNDLE[flag.to_sym] + OPT_BUNDLE[:common], args: flag == :exec).first
504
+ args = option_sanitize(args, OPT_BUNDLE[flag.to_sym] + OPT_BUNDLE[:common]).first
512
505
  end
513
- raise_error('bundle', flag, hint: 'no command given') unless !args.empty? || flag == 'check'
506
+ raise_error('no command given', hint: flag) unless !args.empty? || flag == 'check'
514
507
  cmd.merge(args)
515
508
  run(from: :"bundle:#{flag}")
516
509
  end
517
510
 
518
511
  def rake(*cmd)
519
512
  if cmd.empty?
520
- run_s(rake_output(rakeapp), from: :rake, chdir: workspace.pwd, banner: false)
513
+ run_s(rake_output(rakeapp), from: :rake, chdir: workspace.pwd)
521
514
  else
522
515
  cmd = cmd.flatten.map { |val| rake_output(rakeapp, val) }
523
516
  run_s(cmd, from: :rake, chdir: workspace.pwd, banner: false)
@@ -574,7 +567,7 @@ module Squared
574
567
  end
575
568
  pwd_set { parse.(`#{bundle_output('show', project)}`) } unless @gemdir
576
569
  end
577
- raise_error('failed to parse', hint: @version || 'path') unless @gemdir
570
+ raise_error('parse failed', hint: @version || 'path') unless @gemdir
578
571
  rescue StandardError => e
579
572
  log.error e
580
573
  @version = nil
@@ -594,13 +587,9 @@ module Squared
594
587
  run(banner: !@session.include?('--quiet'), **kwargs)
595
588
  end
596
589
 
597
- def append_bundle(opts, list, target: @session, append: false)
590
+ def append_bundle(opts, list, target: @session)
598
591
  out = option_sanitize(opts, list, target: target).first
599
- if append
600
- append_value(out, target: target, escape: true)
601
- else
602
- option_clear(out, target: target)
603
- end
592
+ option_clear(out, target: target)
604
593
  end
605
594
 
606
595
  def gem_session(*cmd, **kwargs)
@@ -611,7 +600,7 @@ module Squared
611
600
 
612
601
  def bundle_session(*cmd, **kwargs)
613
602
  ret = session('bundle', *cmd, **kwargs)
614
- append_nocolor(target: ret)
603
+ append_nocolor
615
604
  ret
616
605
  end
617
606
 
@@ -657,23 +646,23 @@ module Squared
657
646
  def rakefile
658
647
  return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
659
648
 
660
- basepath(file)
649
+ basepath file
661
650
  end
662
651
 
663
652
  def rakeapp
664
- quote_option 'f', rakefile
653
+ quote_option 'rakefile', Rake.application.rakefile
665
654
  end
666
655
 
667
656
  def rakepwd
668
657
  return unless Rake::VERSION >= '13.0.4'
669
658
 
670
- quote_option('C', path)
659
+ quote_option 'C', path
671
660
  end
672
661
 
673
662
  def gempwd
674
663
  return unless Gem::VERSION >= '3.4.2'
675
664
 
676
- quote_option('C', path)
665
+ quote_option 'C', path
677
666
  end
678
667
 
679
668
  def gempath(val = @version)
@@ -7,7 +7,13 @@ module Squared
7
7
  attr_accessor :line_width
8
8
 
9
9
  def max_width(lines)
10
- [lines.max_by(&:size).size, line_width].max
10
+ win = 0
11
+ if $stdout.tty?
12
+ require 'io/console'
13
+ win = $stdout.winsize[1] rescue nil
14
+ end
15
+ n = [lines.max_by(&:size).size, line_width].max
16
+ [n, win > 0 ? win : ::Float::INFINITY].min
11
17
  end
12
18
  end
13
19
 
@@ -3,6 +3,8 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Repo
6
+ include Common::Format
7
+
6
8
  class << self
7
9
  def read_manifest(path)
8
10
  require 'rexml/document'
@@ -29,14 +31,14 @@ module Squared
29
31
  @root = nil unless repo_confirm
30
32
  end
31
33
  end
32
- raise_error('REPO_HOME', val, hint: 'invalid') unless @root
34
+ raise_error("path invalid: #{val}", hint: 'REPO_HOME') unless @root
33
35
  path.realdirpath
34
36
  elsif (val = env('REPO_ROOT'))
35
37
  @root = Pathname.new(val).realdirpath
36
38
  if !@root.exist?
37
39
  @root.mkpath
38
40
  elsif !repo_install?(parent: true)
39
- raise_error('REPO_ROOT', val, hint: 'exist') unless repo_confirm
41
+ raise_error("path does not exist: #{val}", hint: 'REPO_ROOT') unless repo_confirm
40
42
  end
41
43
  @root.join(main).realdirpath
42
44
  elsif repo_install?(parent: true) && (!@home.exist? || @root.join(main) == @home)
@@ -152,11 +154,13 @@ module Squared
152
154
  parse_opts.(args)
153
155
  stage ||= 'all'
154
156
  repo['sync'].invoke
157
+ next if env('REPO_DRYRUN', equals: '2')
158
+
155
159
  @project.select do |_, proj|
156
160
  next unless proj.enabled?(proj.workspace.baseref)
157
161
 
158
162
  proj.depend(sync: true) if proj.depend?
159
- proj.build?
163
+ proj.build? unless env('REPO_DRYRUN', ignore: '0')
160
164
  end
161
165
  .each_value do |proj|
162
166
  proj.build(sync: true)
@@ -182,7 +186,7 @@ module Squared
182
186
  desc.('sync[{0}]')
183
187
  task 'sync', [:opts] do |_, args|
184
188
  unless branch || stage == 'init'
185
- raise_error('repo is not initialized', "rake #{task_name('repo:init')}", kind: LoadError)
189
+ raise_error('repo not initialized', hint: task_name('repo:init'), kind: LoadError)
186
190
  end
187
191
  parse_opts.(args)
188
192
  cmd << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}"
@@ -190,6 +194,9 @@ module Squared
190
194
  puts if newline && stage != 'init'
191
195
  begin
192
196
  Common::System.shell("repo sync #{cmd.join(' ')}", chdir: root, exception: failfast)
197
+ rescue Errno::ENOENT => e
198
+ emphasize(e, title: root)
199
+ raise
193
200
  rescue StandardError => e
194
201
  emphasize(e, title: "rake stash #{task_name(task_join('repo', stage || 'sync'))}")
195
202
  raise
@@ -119,7 +119,7 @@ module Squared
119
119
  val = format_desc(key, out: true)
120
120
  if items.size > 1
121
121
  @multiple << key
122
- if parallel.include?(t) || pattern.any? { |pat| t =~ pat } || subcheck.(t)
122
+ if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.(t)
123
123
  task_desc("#{val} (thread)", name: key)
124
124
  multitask key => items
125
125
  @parallel << key
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-28 00:00:00.000000000 Z
10
+ date: 2025-03-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -92,6 +92,7 @@ files:
92
92
  - lib/squared/workspace/application.rb
93
93
  - lib/squared/workspace/project.rb
94
94
  - lib/squared/workspace/project/base.rb
95
+ - lib/squared/workspace/project/docker.rb
95
96
  - lib/squared/workspace/project/git.rb
96
97
  - lib/squared/workspace/project/node.rb
97
98
  - lib/squared/workspace/project/python.rb