squared 0.6.3 → 0.6.5

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.
@@ -330,7 +330,8 @@ module Squared
330
330
  end
331
331
  end
332
332
  when 'outdated'
333
- format_desc action, flag, 'eager?,user?,s/elect'
333
+ format_desc(action, flag, "eager?,no-deps?,#{shortname('h', 'i', 's', 'u', 'd')}",
334
+ before: ('user?' unless venv))
334
335
  task flag do |_, args|
335
336
  outdated flag, args.to_a
336
337
  end
@@ -406,21 +407,44 @@ module Squared
406
407
 
407
408
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
408
409
  cmd = pip_session 'list --outdated'
409
- cmd << '--not-required' unless flag || option('not-required', equals: '0')
410
+ cmd << if flag
411
+ se = has_value! opts, 's', 'select'
412
+ ia = has_value!(opts, 'i', 'interactive') && !se
413
+ up = has_value! opts, 'u', 'update'
414
+ hide = has_value! opts, 'h', 'hide'
415
+ dryrun = has_value! opts, 'd', 'dry-run'
416
+ if !sync || stdin?
417
+ se = false
418
+ ia = false
419
+ elsif se || ia
420
+ up = true
421
+ items = []
422
+ end
423
+ '--not-required' if opts.include?('no-deps')
424
+ else
425
+ if (up = option('u', 'update'))
426
+ flag = case up
427
+ when 'major', 'minor'
428
+ up.to_sym
429
+ else
430
+ :patch
431
+ end
432
+ end
433
+ '--not-required' unless option('not-required', equals: '0')
434
+ end
410
435
  cmd << '--local' if option('l', 'local')
411
436
  append_global
437
+ dryrun ||= dryrun?
412
438
  cmd = session_done cmd
413
439
  log.info cmd
414
440
  on :first, :outdated
415
441
  banner = format_banner cmd
416
- items = if sync
417
- print_item banner
418
- [] if flag && has_value?(opts, 's', 'select') && !stdin?
419
- end
442
+ print_item banner if sync
420
443
  pwd_set(from: :outdated) do
421
444
  tc = theme[:current]
422
445
  start = 0
423
446
  found = 0
447
+ col = 0
424
448
  major = []
425
449
  minor = []
426
450
  patch = []
@@ -431,53 +455,58 @@ module Squared
431
455
  else
432
456
  IO.popen(runenv || {}, cmd)
433
457
  end.each do |line|
458
+ line.chomp!
434
459
  next if line.match?(/^[ -]+$/)
435
460
 
436
461
  if start > 0
462
+ n = line.size
437
463
  unless stdin?
438
464
  cur, lat = line.scan(SEM_VER)
439
465
  next unless cur && lat
440
466
 
441
- latest = lat.join
442
- current = cur.join
467
+ name = line.split(' ', 2).first
468
+ c = cur.join
469
+ l = lat.join
443
470
  semver cur
444
471
  semver lat
445
- name = line.split(' ', 2).first
446
- type = if semmajor?(cur, lat)
447
- major << name
448
- 2
449
- elsif cur[2] == lat[2]
450
- patch << name
451
- 0
452
- else
453
- minor << name
454
- 1
455
- end
456
- if type == 0
472
+ case (type = semtype(cur, lat))
473
+ when 1
474
+ major << name
475
+ when 2
476
+ minor << name
477
+ else
478
+ patch << name
479
+ end
480
+ next if hide && ((flag == :patch && type < 3) || (flag == :minor && type < 2))
481
+
482
+ if type == 3
457
483
  styles = color(:yellow)
458
484
  else
459
485
  styles = color(:green)
460
- sub_style!(line, if type == 2
486
+ sub_style!(line, if type == 1
461
487
  styles += [:bold]
462
488
  theme[:major]
463
489
  else
464
490
  theme[:active]
465
491
  end, pat: /^(\S+)(.+)$/)
466
492
  end
467
- sub_style!(line, **opt_style(tc, /^(.+)(#{Regexp.escape(current)})(.+)$/, 2)) if tc
468
- sub_style!(line, **opt_style(styles, /^(.+)(#{Regexp.escape(latest)})(.+)$/, 2))
493
+ sub_style!(line, **opt_style(tc, /^(.+)(#{Regexp.escape(c)})(.+)$/, 2)) if tc
494
+ sub_style!(line, **opt_style(styles, /^(.+)(#{Regexp.escape(l)})(.+)$/, 2))
469
495
  found += 1
470
496
  end
471
- if items
472
- items << [line, name]
473
- else
474
- out.call("#{start.to_s.rjust(2)}. #{line}")
475
- end
497
+ s = '%2d. %s' % [start, line]
476
498
  start += 1
499
+ if ia
500
+ next unless confirm_semver(s.ljust(col + line.size - n), type)
501
+ elsif !se
502
+ out.call(s)
503
+ end
504
+ items&.push([line, name])
477
505
  elsif line.start_with?('Package')
478
506
  unless stdin?
507
+ col = line.size + 5
479
508
  sub = [opt_style(theme[:header], /^(.*)(?<!\dm)(Package|Latest)(.+)$/, 2)] * 2
480
- out.call(print_footer(" # #{line.chomp}", reverse: true, sub: sub))
509
+ out.call(print_footer(" # #{line}", reverse: true, sub: sub))
481
510
  end
482
511
  start += 1
483
512
  end
@@ -487,9 +516,11 @@ module Squared
487
516
  puts buffer
488
517
  end
489
518
  if found > 0
490
- if items
519
+ if se
491
520
  choice('Select a package', items.map(&:first),
492
521
  multiple: true, force: false, index: true, border: true).map! { |n| items[n.pred].last }
522
+ elsif ia
523
+ items.map(&:last)
493
524
  else
494
525
  case flag
495
526
  when :major
@@ -500,12 +531,20 @@ module Squared
500
531
  patch
501
532
  end
502
533
  end.tap do |packages|
503
- unless packages.empty?
504
- install(:upgrade, opts.grep(/^(?:eager|user)$/), packages: packages, banner: false)
534
+ if up && !packages.empty?
535
+ base = %w[eager no-deps]
536
+ base << 'user' unless venv
537
+ opts = (base & opts).map! { |val| val == 'eager' ? "upgrade-strategy=#{val}" : val }
538
+ if dryrun
539
+ opts.map! { |val| fill_option(val) }
540
+ print_run pip_output('install --upgrade', *opts, *packages.quote!), false
541
+ else
542
+ install(:upgrade, opts, packages: packages, banner: false)
543
+ end
505
544
  end
506
545
  print_status(major.size, minor.size, patch.size, from: :outdated)
507
546
  end
508
- elsif start == 0
547
+ elsif start == 0 || hide
509
548
  puts 'No updates were found'
510
549
  end
511
550
  end
@@ -595,7 +634,7 @@ module Squared
595
634
  op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
596
635
  dist = lambda do
597
636
  dir = basepath 'dist'
598
- return dir if dir.directory? && !dir.empty?
637
+ next dir if dir.directory? && !dir.empty?
599
638
 
600
639
  if dir.exist?
601
640
  raise_error 'no source to publish', hint: dir
@@ -700,26 +739,26 @@ module Squared
700
739
  run(sync: sync, banner: banner, from: :"pip:#{flag}").yield_self { |val| ret || val }
701
740
  end
702
741
 
703
- def variable_set(key, *val, **, &blk)
742
+ def variable_set(key, *args, **, &blk)
704
743
  if block_given?
705
744
  case key
706
745
  when :dependfile, :venv, :editable
707
- val = block_args val, &blk
746
+ args = block_args args, &blk
708
747
  end
709
748
  end
710
749
  case key
711
750
  when :dependfile
712
- req = basepath(*val)
713
- if (index = DEP_PYTHON.index(req.basename.to_s))
751
+ val = basepath(*args)
752
+ if (index = DEP_PYTHON.index(val.basename.to_s))
714
753
  @dependindex = index
715
- @dependfile = req
754
+ @dependfile = val
716
755
  else
717
- log.warn "variable_set: @#{key}=#{req} (not supported)"
756
+ log.warn "variable_set: @#{key}=#{val} (not supported)"
718
757
  end
719
758
  when :editable
720
- editable_set val.first
759
+ editable_set args.first
721
760
  when :venv
722
- instance_variable_set(:"@#{key}", (basepath(*val) unless val.empty?))
761
+ instance_variable_set(:"@#{key}", (basepath(*args) unless args.empty?))
723
762
  else
724
763
  super
725
764
  end
@@ -730,7 +769,7 @@ module Squared
730
769
  end
731
770
 
732
771
  def outdated?
733
- dependtype > 0
772
+ dependtype > 0 && !task_pass?('outdated')
734
773
  end
735
774
 
736
775
  private
@@ -739,6 +778,10 @@ module Squared
739
778
  session('pip', *cmd, *preopts, path: venv.nil?)
740
779
  end
741
780
 
781
+ def pip_output(*cmd)
782
+ session_output('pip', *cmd, *preopts, path: venv.nil?)
783
+ end
784
+
742
785
  def python_session(*cmd, opts: nil)
743
786
  return session('python', *preopts(quiet: false), *cmd, path: venv.nil?) unless opts
744
787
 
@@ -769,11 +812,11 @@ module Squared
769
812
 
770
813
  def append_pip(flag, opts, target: @session, from: nil)
771
814
  list = OPT_PIP.fetch(from, []) + OPT_PIP[:common]
772
- if pip_install?(flag)
815
+ if pip_install?(flag) || from == :install
773
816
  list.concat(OPT_PIP[:install_a])
774
817
  list.concat(OPT_PIP[:install_b]) unless flag == :index
775
818
  case flag
776
- when :install
819
+ when :install, :editable, :upgrade
777
820
  list.concat(OPT_PIP[:install_c] + OPT_PIP[:debug])
778
821
  when :lock, :wheel
779
822
  list.concat(OPT_PIP[:install_c])
@@ -785,7 +828,7 @@ module Squared
785
828
  op = OptionPartition.new(opts, list, target, project: self, single: singleopt)
786
829
  append_global(target: target)
787
830
  case flag
788
- when :install, :lock, :wheel
831
+ when :install, :lock, :wheel, :editable, :upgrade
789
832
  edit = nil
790
833
  op.each do |opt|
791
834
  if opt =~ op.values
@@ -994,10 +1037,10 @@ module Squared
994
1037
  def venv_init
995
1038
  return if !venv || (venvbin.directory? && !venvbin.empty?)
996
1039
 
997
- puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'init')
1040
+ puts log_message(venv, subject: 'venv', hint: 'init')
998
1041
  opts = @venvopts&.map { |val| OptionPartition.strip(val) }&.flatten
999
1042
  venv_create(venv, opts || ["prompt=#{name}", 'upgrade-deps'], env: false, banner: false)
1000
- puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'created')
1043
+ puts log_message(venv, subject: 'venv', hint: 'created')
1001
1044
  end
1002
1045
 
1003
1046
  def venv_create(dir, opts = [], env: nil, banner: true)