squared 0.4.6 → 0.4.8

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.
@@ -5,7 +5,7 @@ module Squared
5
5
  module Project
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
- common: %w[dry-run include-workspace-root workspaces=b? w|workspace=b].freeze,
8
+ common: %w[dry-run include-workspace-root workspaces=b? w|workspace=v].freeze,
9
9
  install: %w[prefer-dedupe package-lock-only cpu=b libc=b os=b].freeze,
10
10
  install_base: %w[ignore-scripts install-links strict-peer-deps include=b omit=b install-strategy=b].freeze,
11
11
  install_no: %w[audit bin-links fund package-lock].freeze,
@@ -112,7 +112,7 @@ module Squared
112
112
  return unless outdated? && ref?(Node.ref)
113
113
 
114
114
  namespace name do
115
- @@tasks[Node.ref].each do |action, flags|
115
+ Node.subtasks do |action, flags|
116
116
  next if @pass.include?(action)
117
117
 
118
118
  if flags.nil?
@@ -201,11 +201,11 @@ module Squared
201
201
  tag, otp, dryrun = args
202
202
  end
203
203
  check = ->(val) { val == 'dry-run' || val == 'true' }
204
- if check.(otp)
204
+ if check.call(otp)
205
205
  dryrun = true
206
206
  otp = nil
207
207
  elsif dryrun
208
- dryrun = check.(dryrun)
208
+ dryrun = check.call(dryrun)
209
209
  end
210
210
  publish(flag, otp: otp, tag: tag, dryrun: dryrun)
211
211
  end
@@ -242,7 +242,7 @@ module Squared
242
242
  items << @workspace.home
243
243
  @workspace.rev_clear(@workspace.find(@workspace.home).name)
244
244
  end
245
- items += as_a(also) if also
245
+ items.concat(as_a(also)) if also
246
246
  return if items.empty?
247
247
 
248
248
  on :first, :copy
@@ -280,7 +280,7 @@ module Squared
280
280
  dest = dir.path
281
281
  @workspace.rev_clear(dir.name)
282
282
  else
283
- raise_error "copy given: #{dir}"
283
+ raise_error "copy: given #{dir}"
284
284
  end
285
285
  next unless from && dest&.directory?
286
286
 
@@ -445,14 +445,13 @@ module Squared
445
445
  if upgrade && !w[5]
446
446
  next if file == want
447
447
 
448
- index = if a != c
449
- 1
450
- elsif b != d
451
- 3
452
- else
453
- 5
454
- end
455
- found << [key, file, want, index, major, f, w]
448
+ found << [key, file, want, if a != c
449
+ 1
450
+ elsif b != d
451
+ 3
452
+ else
453
+ 5
454
+ end, major, f, w]
456
455
  elsif !major
457
456
  avail << [key, file, latest, latest != current]
458
457
  end
@@ -478,11 +477,12 @@ module Squared
478
477
  end
479
478
  print_item banner unless sync
480
479
  if !found.empty?
481
- col1 = size_col.(found, 0) + 4
482
- col2 = size_col.(found, 1) + 4
480
+ col1 = size_col.call(found, 0) + 4
481
+ col2 = size_col.call(found, 1) + 4
483
482
  found.each_with_index do |item, i|
484
483
  a, b, c, d, e = item
485
- if inter && (rev != :major || e || semmajor?(item[5], item[6])) && !confirm_outdated(a, c, d, e)
484
+ inter &&= rev != :major || e || semmajor?(item[5], item[6])
485
+ if inter && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
486
486
  cur = -1
487
487
  else
488
488
  cur = modified
@@ -510,22 +510,22 @@ module Squared
510
510
  else
511
511
  sub_style(c, pat: SEM_VER, styles: color(:green), index: d)
512
512
  end
513
- puts "#{pad_ord.(i, found)}. #{a + b + c}"
513
+ puts "#{pad_ord.call(i, found)}. #{a + b + c}"
514
514
  end
515
515
  pending = avail.reduce(pending) { |a, b| a + (b[3] ? 0 : 1) }
516
516
  if dryrun || (modified == 0 && pending > 0)
517
- footer.(modified, found.size)
517
+ footer.call(modified, found.size)
518
518
  elsif modified > 0
519
519
  modified = -1
520
- footer.(0, found.size)
520
+ footer.call(0, found.size)
521
521
  File.write(dependfile, doc)
522
522
  commit(:add, refs: ['package.json'], pass: true)
523
523
  install if opts.include?('prune')
524
524
  end
525
525
  elsif !avail.empty?
526
- col1 = size_col.(avail, 0) + 4
527
- col2 = size_col.(avail, 1)
528
- col3 = size_col.(avail, 2) + 4
526
+ col1 = size_col.call(avail, 0) + 4
527
+ col2 = size_col.call(avail, 1)
528
+ col3 = size_col.call(avail, 2) + 4
529
529
  avail.each_with_index do |item, i|
530
530
  a, b, c, d = item
531
531
  a = a.ljust(col1)
@@ -536,9 +536,9 @@ module Squared
536
536
  c = sub_style(c, styles: color(:green))
537
537
  pending += 1
538
538
  end
539
- puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
539
+ puts "#{pad_ord.call(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
540
540
  end
541
- footer.(0, avail.size)
541
+ footer.call(0, avail.size)
542
542
  else
543
543
  puts 'No updates were found'
544
544
  end
@@ -598,48 +598,48 @@ module Squared
598
598
  else
599
599
  flag
600
600
  end
601
- out = option_sanitize(opts, if yarn == 1
602
- OPT_PNPM[:install_base] + OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
603
- else
604
- OPT_BERRY[flag]
605
- end).first
601
+ op = OptionPartition.new(opts, if yarn == 1
602
+ OPT_PNPM[:install_base] + OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
603
+ else
604
+ OPT_BERRY[flag]
605
+ end, cmd, project: self)
606
+ op.clear
606
607
  append_loglevel
607
- option_clear out
608
608
  run(from: :"package:#{flag}")
609
609
  return
610
610
  elsif pnpm?
611
611
  cmd = session 'pnpm', flag
612
612
  list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
613
- list += OPT_PNPM[:install_as] unless flag == :dedupe
614
- opts = option_sanitize(opts, list, no: OPT_PNPM[:"#{flag}_no"]).first
613
+ list.concat(OPT_PNPM[:install_as]) unless flag == :dedupe
614
+ no = OPT_PNPM[:"#{flag}_no"]
615
615
  else
616
616
  cmd = session 'npm', flag
617
617
  list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
618
- list += OPT_NPM[:install_as] unless flag == :dedupe
619
- opts, pat = option_sanitize(opts, list, no: OPT_NPM[:install_no])
618
+ list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
619
+ no = OPT_NPM[:install_no]
620
620
  end
621
- out = []
622
- err = []
623
- opts.each do |opt|
624
- if pat && opt =~ pat
621
+ op = OptionPartition.new(opts, list, cmd, no: no, project: self)
622
+ op.each do |opt|
623
+ if opt =~ op.values
625
624
  case $1
626
625
  when 'w', 'workspace'
627
- cmd << (%r{[\\/]}.match?($2) ? quote_option($1, basepath($2)) : shell_option($1, $2))
626
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
628
627
  end
629
628
  elsif opt.include?('=')
630
- err << opt
629
+ op.errors << opt
631
630
  else
632
- out << opt
631
+ op.found << opt
633
632
  end
634
633
  end
634
+ op.swap
635
635
  append_nocolor
636
636
  append_loglevel
637
637
  if flag == :dedupe
638
- option_clear out
638
+ op.clear
639
639
  else
640
- append_value(out, escape: true)
640
+ op.append(escape: true)
641
641
  end
642
- option_clear err
642
+ op.clear(errors: true)
643
643
  run(from: :"package:#{flag}")
644
644
  end
645
645
 
@@ -693,7 +693,8 @@ module Squared
693
693
  end
694
694
  rescue StandardError => e
695
695
  log.debug e
696
- raise if exception
696
+ ret = on(:error, :bump, e)
697
+ raise if exception && ret != true
697
698
  end
698
699
  end
699
700
 
@@ -702,13 +703,25 @@ module Squared
702
703
 
703
704
  cmd = session dependbin, 'pack'
704
705
  if dependtype(:yarn) > 1
705
- out = option_sanitize(opts, OPT_BERRY[:pack]).first
706
- cmd << quote_option('out', Pathname.pwd.join("#{project}-#{version}.tgz")) unless session_arg?('out')
706
+ op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
707
+ op << quote_option('out', Pathname.pwd.join("#{project}-#{version}.tgz")) unless op.arg?('out')
707
708
  else
708
- out = option_sanitize(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common]).first
709
- cmd << quote_option('pack-destination', Dir.pwd) unless session_arg?('pack-destination')
709
+ op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
710
+ project: self)
711
+ unless pnpm?
712
+ op.each do |opt|
713
+ next unless opt =~ op.values
714
+
715
+ case $1
716
+ when 'w', 'workspace'
717
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
718
+ op.found << opt
719
+ end
720
+ end
721
+ end
722
+ op << quote_option('pack-destination', Dir.pwd) unless op.arg?('pack-destination')
710
723
  end
711
- option_clear out
724
+ op.clear
712
725
  run(from: :pack)
713
726
  end
714
727
 
@@ -731,7 +744,7 @@ module Squared
731
744
  when Enumerable
732
745
  target.to_a.join(' ')
733
746
  else
734
- raise_error("compose given: #{target}", hint: from)
747
+ raise_error("compose: given #{target}", hint: from)
735
748
  end
736
749
  end
737
750
  end
@@ -889,21 +902,6 @@ module Squared
889
902
  end
890
903
  end
891
904
 
892
- def confirm_outdated(pkg, ver, rev, lock)
893
- a = sub_style(case rev
894
- when 1
895
- 'MAJOR'
896
- when 3
897
- 'MINOR'
898
- else
899
- 'PATCH'
900
- end, styles: theme[:header])
901
- b = sub_style("#{pkg} #{ver}", styles: theme[:inline])
902
- c, d = rev == 1 || lock ? ['y/N', 'N'] : ['Y/n', 'Y']
903
- e = lock ? " #{sub_style('(locked)', styles: color(:red))}" : ''
904
- confirm("Upgrade to #{a}? #{b + e} [#{c}] ", d, timeout: 60)
905
- end
906
-
907
905
  def dryrun?(prefix = dependbin, **)
908
906
  super || !option('dry-run', prefix: prefix).nil?
909
907
  end
@@ -20,7 +20,7 @@ module Squared
20
20
  install: %w[break-system-packages check-build-dependencies compile dry-run force-reinstall I|ignore-installed
21
21
  ignore-requires-python no-build-isolation no-clean no-compile no-deps no-index no-warn-conflicts
22
22
  no-warn-script-location pre prefer-binary require-hashes U|upgrade use-pep517 user abi=b
23
- config-settings=q c|constraint=p extra-index-url=q f|find-links=q global-option=q
23
+ config-settings=q c|constraint=p e|editable=v extra-index-url=q f|find-links=q global-option=q
24
24
  implementation=b i|index-url=q no-binary=q only-binary=q platform=q prefix=p progress-bar=b
25
25
  python-version=q report=p r|requirement=p root=p root-user-action=b src=p t|target=p
26
26
  upgrade-strategy=b].freeze,
@@ -55,7 +55,7 @@ module Squared
55
55
  end
56
56
 
57
57
  def bannerargs
58
- [:dependfile].freeze
58
+ %i[dependfile venv].freeze
59
59
  end
60
60
 
61
61
  def venv?
@@ -109,7 +109,7 @@ module Squared
109
109
  return unless outdated? && ref?(Python.ref)
110
110
 
111
111
  namespace name do
112
- @@tasks[Python.ref].each do |action, flags|
112
+ Python.subtasks do |action, flags|
113
113
  next if @pass.include?(action)
114
114
 
115
115
  namespace action do
@@ -120,12 +120,13 @@ module Squared
120
120
  format_desc action, flag, 'dir,opts*'
121
121
  task flag, [:dir] do |_, args|
122
122
  dir = basepath(param_guard(action, flag, args: args, key: :dir))
123
- opts = python_session('-m venv', opts: args.extras).last
124
- opts = option_sanitize(opts, OPT_PYTHON[:venv]).first
125
- append_value(dir, delim: true)
126
- option_clear(opts, pass: false)
123
+ cmd, opts = python_session('-m venv', opts: args.extras)
124
+ op = OptionPartition.new(opts, OPT_PYTHON[:venv], cmd, project: self)
125
+ op.append(dir, delim: true)
126
+ .clear(pass: false)
127
+ v = op.arg?(/^-v+$/, 'verbose')
127
128
  run(exception: true)
128
- puts(dir.directory? ? "Success: #{dir}" : 'Failed')
129
+ puts(dir.directory? ? "Success: #{dir}" : 'Failed') unless v
129
130
  end
130
131
  elsif venv
131
132
  case flag
@@ -134,7 +135,7 @@ module Squared
134
135
 
135
136
  format_desc action, flag, 'c|reate?,d|epend?'
136
137
  task flag do |_, args|
137
- FileUtils.rm_rf(venv, verbose: true)
138
+ rm_rf(venv, verbose: true)
138
139
  venv_init if has_value?(%w[c create], args.to_a)
139
140
  depend if has_value?(%w[d depend], args.to_a)
140
141
  end
@@ -210,7 +211,7 @@ module Squared
210
211
  'location?'
211
212
  end)
212
213
  task flag do |_, args|
213
- buildx flag, args.to_a
214
+ build! flag, args.to_a
214
215
  end
215
216
  when 'publish'
216
217
  format_desc(action, flag, 'opts*', after: case flag
@@ -310,12 +311,12 @@ module Squared
310
311
  line = sub_style(line, pat: /^(.+)(#{Regexp.escape(latest)})(.+)$/, styles: styles, index: 2)
311
312
  found += 1
312
313
  end
313
- out.("#{start.to_s.rjust(2)}. #{line}")
314
+ out.call("#{start.to_s.rjust(2)}. #{line}")
314
315
  start += 1
315
316
  elsif line.start_with?('Package')
316
317
  unless stdin?
317
318
  sub = { pat: /^(.*)(?<!\dm)(Package|Latest)(.+)$/, styles: theme[:header], index: 2 }
318
- out.(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
319
+ out.call(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
319
320
  end
320
321
  start += 1
321
322
  end
@@ -341,6 +342,7 @@ module Squared
341
342
  cmd << quote_option('e', out.pop || editable || '.')
342
343
  option_clear out
343
344
  when :upgrade
345
+ raise_error('no packages listed', hint: flag) if out.empty?
344
346
  cmd << '--upgrade'
345
347
  cmd << basic_option('upgrade-strategy', strategy) if strategy
346
348
  append_value out
@@ -348,9 +350,7 @@ module Squared
348
350
  run(from: :install)
349
351
  end
350
352
 
351
- def buildx(flag, opts = [])
352
- out = []
353
- srcdir = nil
353
+ def build!(flag, opts = [])
354
354
  case flag
355
355
  when :python
356
356
  cmd, opts = python_session('-m build', opts: opts)
@@ -362,20 +362,23 @@ module Squared
362
362
  cmd, opts = hatch_session('build', opts: opts)
363
363
  list = OPT_HATCH[:build]
364
364
  end
365
- option_sanitize(opts, list, single: flag == :python ? /^(?:v+|q+|b+)$/ : /^(?:v+|q+)$/).first.each do |opt|
365
+ srcdir = nil
366
+ op = OptionPartition.new(opts, list, cmd, project: self, single: singleopt(flag))
367
+ op.each do |opt|
366
368
  if !srcdir && basepath(opt).exist? && projectpath?(opt)
367
369
  srcdir = opt
368
370
  else
369
- out << opt
371
+ op.found << opt
370
372
  end
371
373
  end
374
+ op.swap
372
375
  case flag
373
376
  when :poetry
374
377
  if srcdir
375
- if session_arg?('o', 'output')
376
- out << srcdir
378
+ if op.arg?('o', 'output')
379
+ op.extras << srcdir
377
380
  else
378
- cmd << quote_option('output', basepath(srcdir))
381
+ op << quote_option('output', basepath(srcdir))
379
382
  end
380
383
  srcdir = nil
381
384
  end
@@ -385,10 +388,10 @@ module Squared
385
388
  else
386
389
  srcdir ||= path
387
390
  end
388
- cmd << basic_option('p', project) unless ENV['HATCH_PROJECT'] || session_arg?('p', 'project')
391
+ op << basic_option('p', project) unless ENV['HATCH_PROJECT'] || op.arg?('p', 'project')
389
392
  end
390
- cmd << shell_quote(basepath(srcdir)) if srcdir
391
- option_clear out
393
+ op << shell_quote(basepath(srcdir)) if srcdir
394
+ op.clear
392
395
  run(from: :"#{flag}:build")
393
396
  end
394
397
 
@@ -404,13 +407,13 @@ module Squared
404
407
  opts = hatch_session('publish', opts: opts).last
405
408
  list = OPT_HATCH[:publish]
406
409
  end
407
- out = option_sanitize(opts, list, single: flag == :twine ? nil : /^(?:v+|q+)$/).first
408
- if out.empty?
410
+ op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
411
+ if op.empty?
409
412
  dist = basepath.join('dist')
410
413
  raise_error('no source files found', hint: dist) unless dist.directory? && !dist.empty?
411
- out << "#{dist}/*" unless flag == :poetry
414
+ op.extras << "#{dist}/*" unless flag == :poetry
412
415
  end
413
- append_value out
416
+ op.append
414
417
  run(from: :"#{flag}:publish")
415
418
  end
416
419
 
@@ -419,7 +422,7 @@ module Squared
419
422
  out = append_pip(nil, opts, from: flag)
420
423
  case flag
421
424
  when :uninstall
422
- raise_error('no packages listed', subject: name, hint: 'uninstall') if out.empty?
425
+ raise_error('no packages listed', hint: 'uninstall') if out.empty?
423
426
  cmd.merge(out)
424
427
  when :freeze
425
428
  venv_init
@@ -465,10 +468,9 @@ module Squared
465
468
  def python_session(*cmd, opts: nil)
466
469
  return session('python', *preopts(quiet: false), *cmd, path: venv.nil?) unless opts
467
470
 
468
- out = []
469
- opts = option_sanitize(opts, OPT_PYTHON[:common], target: out, single: /^v+$/).first
470
- ret = session('python', *out, *cmd, path: venv.nil?)
471
- [ret, opts]
471
+ op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /^v+$/)
472
+ ret = session('python', *op.to_a, *cmd, path: venv.nil?)
473
+ [ret, op.extras]
472
474
  end
473
475
 
474
476
  def poetry_session(*cmd)
@@ -482,48 +484,47 @@ module Squared
482
484
  def hatch_session(*cmd, opts: nil)
483
485
  return session('hatch', *preopts, *cmd, path: venv.nil?) unless opts
484
486
 
485
- out = []
486
- opts = option_sanitize(opts, OPT_HATCH[:common], target: out, single: /^(?:v+|q+)$/).first
487
- ret = session('hatch', *out, *cmd, path: venv.nil?)
488
- [ret, opts]
487
+ op = OptionPartition.new(opts, OPT_HATCH[:common], project: self, single: singleopt)
488
+ ret = session('hatch', *op.to_a, *cmd, path: venv.nil?)
489
+ [ret, op.extras]
489
490
  end
490
491
 
491
- def append_pip(flag, opts, from: nil)
492
+ def append_pip(flag, opts, target: @session, from: nil)
492
493
  if !from || opts.empty?
493
- append_global
494
+ append_global(target: target)
494
495
  return []
495
496
  end
496
- opts, pat = option_sanitize(opts, OPT_PIP[from] + OPT_PIP[:common], single: /^(?:v+|q+)$/)
497
- append_global
497
+ op = OptionPartition.new(opts, OPT_PIP[from] + OPT_PIP[:common], target, project: self, single: singleopt)
498
+ append_global(target: target)
498
499
  if from == :install
499
- out = []
500
500
  edit = nil
501
- opts.each do |opt|
502
- if opt =~ pat
501
+ op.each do |opt|
502
+ if opt =~ op.values
503
503
  case $1
504
504
  when 'e', 'editable'
505
- out << edit if edit && flag == :editable
505
+ op.found << edit if edit && flag == :editable
506
506
  edit = $2
507
507
  end
508
508
  elsif flag == :editable && !edit
509
509
  edit = opt
510
510
  else
511
- out << opt
511
+ op.found << opt
512
512
  end
513
513
  end
514
+ op.swap
514
515
  if edit
515
516
  edit = basepath(edit) unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
516
517
  if flag == :editable
517
- out << edit
518
+ op.extras << edit
518
519
  else
519
520
  target << quote_option('e', edit)
520
521
  end
521
522
  end
522
523
  case flag
523
524
  when :editable, :upgrade
524
- out
525
+ op.extras
525
526
  else
526
- option_clear out
527
+ op.clear
527
528
  []
528
529
  end
529
530
  else
@@ -531,25 +532,25 @@ module Squared
531
532
  end
532
533
  end
533
534
 
534
- def append_editable
535
+ def append_editable(target: @session)
535
536
  return if requirements?
536
537
 
537
- if (val = option('editable', 'e', ignore: false))
538
- session_delete('e', 'editable')
538
+ if (val = option('editable', 'e', target: target, ignore: false))
539
+ session_delete('e', 'editable', target: target)
539
540
  case val
540
541
  when '0', 'false'
541
542
  return
542
543
  else
543
544
  val = basepath(val)
544
545
  end
545
- elsif session_arg?('e', 'editable') || !(val = editable)
546
+ elsif session_arg?('e', 'editable', target: target) || !(val = editable)
546
547
  return
547
548
  end
548
- @session << quote_option('e', val)
549
+ target << quote_option('e', val)
549
550
  end
550
551
 
551
552
  def append_global(target: @session)
552
- if (val = option('cache-dir'))
553
+ if (val = option('cache-dir', target: target))
553
554
  target << case val
554
555
  when '0', 'false'
555
556
  '--no-cache-dir'
@@ -557,15 +558,26 @@ module Squared
557
558
  quote_option('cache-dir', basepath(val))
558
559
  end
559
560
  end
560
- target << shell_option('proxy', val) if (val = option('proxy'))
561
- target << quote_option('python', basepath(val)) if (val = option('python'))
561
+ target << shell_option('proxy', val) if (val = option('proxy', target: target))
562
+ target << quote_option('python', basepath(val)) if (val = option('python', target: target))
562
563
  append_nocolor(target: target)
563
564
  end
564
565
 
566
+ def singleopt(flag = nil)
567
+ case flag
568
+ when :python
569
+ /^(?:v+|q+|b+)$/
570
+ when :twine
571
+ nil
572
+ else
573
+ /^(?:v+|q+)$/
574
+ end
575
+ end
576
+
565
577
  def preopts(quiet: true)
566
578
  ret = []
567
579
  case verbose
568
- when false
580
+ when FalseClass
569
581
  ret << '--quiet' if quiet
570
582
  when Numeric
571
583
  ret << "-#{'v' * verbose}" if verbose > 0