squared 0.3.14 → 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"
@@ -121,11 +121,11 @@ module Squared
121
121
  when 'rake'
122
122
  next unless rakefile
123
123
 
124
- format_desc action, nil, "command*|#{indexchar}index,args*|#,pattern*"
124
+ format_desc action, nil, 'command*|^index,args*|#,pattern*'
125
125
  task action, [:command] do |_, args|
126
126
  if args.command == '#'
127
- format_list(read_rakefile, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile.to_s,
128
- each: ->(val) { val[0] + val[1].to_s })
127
+ format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
128
+ each: ->(val) { val[0] + val[1].to_s })
129
129
  elsif (data = indexitem(args.command))
130
130
  n, opts = data
131
131
  list = read_rakefile
@@ -155,10 +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: case flag
159
- when :exec then 'command+'
160
- when :push then 'file'
161
- end)
158
+ format_desc action, flag, 'opts*'
162
159
  task flag do |_, args|
163
160
  gemx flag, args.to_a
164
161
  end
@@ -181,6 +178,7 @@ module Squared
181
178
  if @depend
182
179
  super
183
180
  elsif outdated?
181
+ workspace.rev_clear name
184
182
  cmd = bundle_session 'install'
185
183
  if (n = option('jobs')).to_i > 0
186
184
  cmd << "-j#{n}"
@@ -189,15 +187,13 @@ module Squared
189
187
  end
190
188
  end
191
189
 
192
- def copy(from: 'lib', into: @gemdir, override: false, **kwargs)
193
- glob = kwargs[:include]
194
- pass = kwargs[:exclude]
190
+ def copy(from: 'lib', include: nil, exclude: nil, into: @gemdir, override: false)
195
191
  if @copy && !override
196
- return super if runnable?(@copy)
192
+ return super unless @copy.is_a?(Hash)
197
193
 
198
194
  from = @copy[:from] if @copy.key?(:from)
199
195
  glob = @copy[:include] if @copy.key?(:include)
200
- pass = @copy[:exclude] if @copy.key?(:exclude)
196
+ exclude = @copy[:exclude] if @copy.key?(:exclude)
201
197
  into = @copy[:into] if @copy.key?(:into)
202
198
  end
203
199
  return unless into
@@ -209,10 +205,10 @@ module Squared
209
205
  as_a(from).each_with_index do |val, i|
210
206
  a = basepath(val)
211
207
  b = dest.join(val)
212
- c = glob[i] || glob.first
208
+ c = glob[i] || glob[0]
213
209
  log.info "cp #{a.join(c)} #{b}"
214
210
  begin
215
- copy_dir(a, b, c, pass: pass, verbose: verbose)
211
+ copy_dir(a, b, c, pass: exclude, verbose: verbose)
216
212
  rescue StandardError => e
217
213
  log.error e
218
214
  ret = on(:error, :copy, e)
@@ -306,7 +302,7 @@ module Squared
306
302
  end
307
303
  end
308
304
  out.("#{start.to_s.rjust(2)}. #{line}")
309
- elsif line =~ /^Gem /
305
+ elsif line.start_with?('Gem')
310
306
  unless stdin?
311
307
  sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
312
308
  out.(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
@@ -347,8 +343,7 @@ module Squared
347
343
 
348
344
  def update(flag, opts = [])
349
345
  bundle_session 'update', "--#{flag}"
350
- append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
351
- append: flag != :all)
346
+ append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common]
352
347
  run_rb(from: :update)
353
348
  end
354
349
 
@@ -361,8 +356,7 @@ module Squared
361
356
  end
362
357
  cmd << flag
363
358
  when :push
364
- raise_error('gem not found', hint: flag) if opts.empty? || !(file = path + opts.shift).exist?
365
- cmd << flag << shell_quote(file)
359
+ cmd << flag << project
366
360
  when :'user-install'
367
361
  cmd << 'install' << '--user-install'
368
362
  else
@@ -373,17 +367,14 @@ module Squared
373
367
  when :install, :'user-install', :update
374
368
  list += OPT_GEM[:shared]
375
369
  no = OPT_GEM[:shared_no]
376
- first = true
377
- when :pristine
378
- first = true
379
370
  end
380
- opts, pat = option_sanitize(opts, list, no: no, first: first)
371
+ opts, pat = option_sanitize(opts, list, no: no, first: true)
381
372
  out = []
382
373
  opts.each do |opt|
383
374
  if opt =~ pat
384
375
  case $1
385
376
  when 'g', 'gem'
386
- cmd << (flag == :exec ? basic_option($1, $2) : quote_option($1, basepath($2)))
377
+ cmd << (flag == :exec ? shell_option($1, $2) : quote_option($1, basepath($2)))
387
378
  end
388
379
  else
389
380
  out << opt
@@ -398,14 +389,14 @@ module Squared
398
389
  pwd_set(pass: !pwd.nil?, from: from) do
399
390
  items = [[%w[Gem Current Latest], nil]]
400
391
  IO.popen(cmd.done).each do |line|
401
- if (data = line.match(/^(\S+) \((\S+) < ([^)]+)\)$/))
402
- cur = semscan(data[2])
403
- lat = semscan(data[3])
404
- items << [data.to_a.drop(1), if semmajor?(cur, lat)
405
- %i[green bold]
406
- else
407
- cur[2] == lat[2] ? [:yellow] : [:green]
408
- 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]
409
400
  else
410
401
  puts line
411
402
  end
@@ -437,7 +428,7 @@ module Squared
437
428
  line = sub_style(line, pat: /^(.+)(?<!\dm)(#{a}|#{c})(.*)$/, styles: theme[:header], index: 2)
438
429
  end
439
430
  puts line
440
- puts '-' * n
431
+ puts sub_style(ARG[:BORDER][1] * n, styles: borderstyle)
441
432
  else
442
433
  styles = item.last
443
434
  a = a.ljust(d)
@@ -471,33 +462,30 @@ module Squared
471
462
  when :build, :push
472
463
  if !out.empty?
473
464
  if flag == :build && out.size == 1
474
- cmd << basepath(out.first)
465
+ cmd << shell_quote(basepath(out.first))
475
466
  else
476
- raise_error('gem', flag, out.join(', '), hint: 'unrecognized option')
467
+ raise_error("unknown args: #{out.join(', ')}", hint: flag)
477
468
  end
478
469
  elsif flag == :build
479
470
  cmd << "#{project}.gemspec"
480
471
  end
481
472
  when :exec
482
- raise_error('gem', flag, hint: 'no command given') if out.empty?
483
- cmd << basic_option('gem', project) unless session_arg?('g', 'gem')
473
+ raise_error('no command given', hint: flag) if out.empty?
484
474
  cmd << out.join(' ')
485
475
  else
486
- if out.empty? && cmd.none? { |val| val =~ /^--system(?:=|$)/ }
487
- raise_error('gem', flag, hint: 'no gemname given')
488
- end
476
+ raise_error('no gemname given', hint: flag) if out.empty? && !session_arg?('system')
489
477
  if flag == :pristine
490
478
  if session_arg?('all')
491
479
  append_repeat 'skip', out
492
480
  out.clear
493
- elsif (n = out.first =~ /@/)
481
+ elsif (n = out.first.index('@'))
494
482
  name = out.first
495
483
  if n == 0
496
484
  cmd << project
497
485
  version = name[1..-1]
498
486
  else
499
487
  cmd << shell_escape(name[0, n])
500
- version = name[(n + 1)..-1]
488
+ version = name[n + 1..-1]
501
489
  end
502
490
  cmd << shell_option('version', version)
503
491
  out.clear
@@ -513,16 +501,16 @@ module Squared
513
501
  cmd = bundle_session flag
514
502
  case flag
515
503
  when 'exec', 'check'
516
- 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
517
505
  end
518
- 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'
519
507
  cmd.merge(args)
520
508
  run(from: :"bundle:#{flag}")
521
509
  end
522
510
 
523
511
  def rake(*cmd)
524
512
  if cmd.empty?
525
- run_s(rake_output(rakeapp), from: :rake, chdir: workspace.pwd, banner: false)
513
+ run_s(rake_output(rakeapp), from: :rake, chdir: workspace.pwd)
526
514
  else
527
515
  cmd = cmd.flatten.map { |val| rake_output(rakeapp, val) }
528
516
  run_s(cmd, from: :rake, chdir: workspace.pwd, banner: false)
@@ -579,7 +567,7 @@ module Squared
579
567
  end
580
568
  pwd_set { parse.(`#{bundle_output('show', project)}`) } unless @gemdir
581
569
  end
582
- raise_error('failed to parse', hint: @version || 'path') unless @gemdir
570
+ raise_error('parse failed', hint: @version || 'path') unless @gemdir
583
571
  rescue StandardError => e
584
572
  log.error e
585
573
  @version = nil
@@ -599,13 +587,9 @@ module Squared
599
587
  run(banner: !@session.include?('--quiet'), **kwargs)
600
588
  end
601
589
 
602
- def append_bundle(opts, list, target: @session, append: false)
590
+ def append_bundle(opts, list, target: @session)
603
591
  out = option_sanitize(opts, list, target: target).first
604
- if append
605
- append_value(out, target: target, escape: true)
606
- else
607
- option_clear(out, target: target)
608
- end
592
+ option_clear(out, target: target)
609
593
  end
610
594
 
611
595
  def gem_session(*cmd, **kwargs)
@@ -616,7 +600,7 @@ module Squared
616
600
 
617
601
  def bundle_session(*cmd, **kwargs)
618
602
  ret = session('bundle', *cmd, **kwargs)
619
- append_nocolor(target: ret)
603
+ append_nocolor
620
604
  ret
621
605
  end
622
606
 
@@ -662,23 +646,23 @@ module Squared
662
646
  def rakefile
663
647
  return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
664
648
 
665
- basepath(file)
649
+ basepath file
666
650
  end
667
651
 
668
652
  def rakeapp
669
- quote_option 'f', rakefile
653
+ quote_option 'rakefile', Rake.application.rakefile
670
654
  end
671
655
 
672
656
  def rakepwd
673
657
  return unless Rake::VERSION >= '13.0.4'
674
658
 
675
- quote_option('C', path)
659
+ quote_option 'C', path
676
660
  end
677
661
 
678
662
  def gempwd
679
663
  return unless Gem::VERSION >= '3.4.2'
680
664
 
681
- quote_option('C', path)
665
+ quote_option 'C', path
682
666
  end
683
667
 
684
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)
@@ -175,14 +179,14 @@ module Squared
175
179
  parse_opts.(args)
176
180
  stage = 'init'
177
181
  puts if newline
178
- Common::System.shell("repo init -u #{manifest_url} -m #{args.manifest || target}.xml", chdir: root)
182
+ system("repo init -u #{manifest_url} -m #{args.manifest || target}.xml", chdir: root)
179
183
  repo['all'].invoke
180
184
  end
181
185
 
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
data/squared.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- version = File.read(File.join(__dir__, "lib/squared/version.rb"))[/\bVERSION = '(.+)'$/, 1]
3
+ require_relative "lib/squared/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "squared"
7
- spec.version = version
7
+ spec.version = Squared::VERSION
8
8
  spec.authors = ["An Pham"]
9
9
  spec.email = ["anpham6@gmail.com"]
10
10
 
11
11
  spec.summary = %q{Rake task generator for managing multi-language workspaces.}
12
12
  spec.description = %q{Rake task generator for managing multi-language workspaces.}
13
- spec.homepage = "https://github.com/anpham6/squared-ruby"
13
+ spec.homepage = "https://github.com/anpham6/squared"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
15
  spec.licenses = ["BSD-3-Clause"]
16
16
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["documentation_uri"] = "https://squared.readthedocs.io"
20
20
 
21
21
  spec.files = Dir["lib/**/*"] +
22
- %w[CHANGELOG.md LICENSE README.md squared.gemspec]
22
+ %w[CHANGELOG.md LICENSE README.md README.ruby.md squared.gemspec]
23
23
  spec.bindir = "exe"
24
24
  spec.executables = []
25
25
  spec.require_paths = ["lib"]
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.14
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: 1980-01-02 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
@@ -75,6 +75,7 @@ files:
75
75
  - CHANGELOG.md
76
76
  - LICENSE
77
77
  - README.md
78
+ - README.ruby.md
78
79
  - lib/squared.rb
79
80
  - lib/squared/app.rb
80
81
  - lib/squared/common.rb
@@ -91,6 +92,7 @@ files:
91
92
  - lib/squared/workspace/application.rb
92
93
  - lib/squared/workspace/project.rb
93
94
  - lib/squared/workspace/project/base.rb
95
+ - lib/squared/workspace/project/docker.rb
94
96
  - lib/squared/workspace/project/git.rb
95
97
  - lib/squared/workspace/project/node.rb
96
98
  - lib/squared/workspace/project/python.rb
@@ -98,12 +100,12 @@ files:
98
100
  - lib/squared/workspace/repo.rb
99
101
  - lib/squared/workspace/series.rb
100
102
  - squared.gemspec
101
- homepage: https://github.com/anpham6/squared-ruby
103
+ homepage: https://github.com/anpham6/squared
102
104
  licenses:
103
105
  - BSD-3-Clause
104
106
  metadata:
105
- homepage_uri: https://github.com/anpham6/squared-ruby
106
- source_code_uri: https://github.com/anpham6/squared-ruby
107
+ homepage_uri: https://github.com/anpham6/squared
108
+ source_code_uri: https://github.com/anpham6/squared
107
109
  documentation_uri: https://squared.readthedocs.io
108
110
  rdoc_options: []
109
111
  require_paths:
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.6.9
124
+ rubygems_version: 3.6.2
123
125
  specification_version: 4
124
126
  summary: Rake task generator for managing multi-language workspaces.
125
127
  test_files: []