squared 0.4.7 → 0.4.9

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.
@@ -98,9 +98,8 @@ module Squared
98
98
  initialize_build(Node.ref, prod: prod?, **kwargs)
99
99
  initialize_env(**kwargs)
100
100
  end
101
- @buildtype = :run if script?
102
101
  @pm = {}
103
- @dependfile = basepath('package.json')
102
+ @dependfile = @path + 'package.json'
104
103
  end
105
104
 
106
105
  def ref
@@ -112,7 +111,7 @@ module Squared
112
111
  return unless outdated? && ref?(Node.ref)
113
112
 
114
113
  namespace name do
115
- @@tasks[Node.ref].each do |action, flags|
114
+ Node.subtasks do |action, flags|
116
115
  next if @pass.include?(action)
117
116
 
118
117
  if flags.nil?
@@ -201,11 +200,11 @@ module Squared
201
200
  tag, otp, dryrun = args
202
201
  end
203
202
  check = ->(val) { val == 'dry-run' || val == 'true' }
204
- if check.(otp)
203
+ if check.call(otp)
205
204
  dryrun = true
206
205
  otp = nil
207
- elsif dryrun
208
- dryrun = check.(dryrun)
206
+ else
207
+ dryrun &&= check.call(dryrun)
209
208
  end
210
209
  publish(flag, otp: otp, tag: tag, dryrun: dryrun)
211
210
  end
@@ -253,7 +252,7 @@ module Squared
253
252
  dest = dir
254
253
  @workspace.rev_clear(dest)
255
254
  when String
256
- dest = @workspace.rootpath(dir)
255
+ dest = @workspace.root + dir
257
256
  @workspace.rev_clear(dest)
258
257
  when Symbol
259
258
  if (proj = @workspace.find(name: dir))
@@ -284,16 +283,16 @@ module Squared
284
283
  end
285
284
  next unless from && dest&.directory?
286
285
 
287
- from = basepath(from)
286
+ from = path + from
288
287
  glob = as_a(glob || '**/*')
289
288
  target = []
290
289
  if workspace
291
- Dir.glob(from.join('*')).each do |path|
290
+ Dir.glob(from + '*').each do |path|
292
291
  next unless (path = Pathname.new(path)).directory?
293
292
 
294
293
  sub = if (proj = @workspace.find(path))
295
294
  proj.packagename
296
- elsif (file = path.join('package.json')).exist?
295
+ elsif (file = path + 'package.json').exist?
297
296
  begin
298
297
  doc = JSON.parse(file.read)
299
298
  rescue StandardError => e
@@ -313,7 +312,7 @@ module Squared
313
312
  target << [from, dest.join(into, scope || project)]
314
313
  end
315
314
  target.each do |src, to|
316
- glob.each { |val| log.info "cp #{from.join(val)} #{to}" }
315
+ glob.each { |val| log.info "cp #{from + val} #{to}" }
317
316
  begin
318
317
  copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
319
318
  rescue StandardError => e
@@ -428,8 +427,8 @@ module Squared
428
427
  want = rev == :major && !latest[SEM_VER, 6] ? latest : val['wanted']
429
428
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
430
429
 
431
- f = semscan(file)
432
- w = semscan(want)
430
+ f = semscan file
431
+ w = semscan want
433
432
  a = f[0]
434
433
  b = f[2]
435
434
  c = w[0]
@@ -445,14 +444,13 @@ module Squared
445
444
  if upgrade && !w[5]
446
445
  next if file == want
447
446
 
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]
447
+ found << [key, file, want, if a != c
448
+ 1
449
+ elsif b != d
450
+ 3
451
+ else
452
+ 5
453
+ end, major, f, w]
456
454
  elsif !major
457
455
  avail << [key, file, latest, latest != current]
458
456
  end
@@ -478,11 +476,12 @@ module Squared
478
476
  end
479
477
  print_item banner unless sync
480
478
  if !found.empty?
481
- col1 = size_col.(found, 0) + 4
482
- col2 = size_col.(found, 1) + 4
479
+ col1 = size_col.call(found, 0) + 4
480
+ col2 = size_col.call(found, 1) + 4
483
481
  found.each_with_index do |item, i|
484
482
  a, b, c, d, e = item
485
- if inter && (rev != :major || e || semmajor?(item[5], item[6])) && !confirm_outdated(a, c, d, e)
483
+ inter &&= rev != :major || e || semmajor?(item[5], item[6])
484
+ if inter && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
486
485
  cur = -1
487
486
  else
488
487
  cur = modified
@@ -510,22 +509,22 @@ module Squared
510
509
  else
511
510
  sub_style(c, pat: SEM_VER, styles: color(:green), index: d)
512
511
  end
513
- puts "#{pad_ord.(i, found)}. #{a + b + c}"
512
+ puts "#{pad_ord.call(i, found)}. #{a + b + c}"
514
513
  end
515
514
  pending = avail.reduce(pending) { |a, b| a + (b[3] ? 0 : 1) }
516
515
  if dryrun || (modified == 0 && pending > 0)
517
- footer.(modified, found.size)
516
+ footer.call(modified, found.size)
518
517
  elsif modified > 0
519
518
  modified = -1
520
- footer.(0, found.size)
519
+ footer.call(0, found.size)
521
520
  File.write(dependfile, doc)
522
521
  commit(:add, refs: ['package.json'], pass: true)
523
522
  install if opts.include?('prune')
524
523
  end
525
524
  elsif !avail.empty?
526
- col1 = size_col.(avail, 0) + 4
527
- col2 = size_col.(avail, 1)
528
- col3 = size_col.(avail, 2) + 4
525
+ col1 = size_col.call(avail, 0) + 4
526
+ col2 = size_col.call(avail, 1)
527
+ col3 = size_col.call(avail, 2) + 4
529
528
  avail.each_with_index do |item, i|
530
529
  a, b, c, d = item
531
530
  a = a.ljust(col1)
@@ -536,9 +535,9 @@ module Squared
536
535
  c = sub_style(c, styles: color(:green))
537
536
  pending += 1
538
537
  end
539
- puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
538
+ puts "#{pad_ord.call(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
540
539
  end
541
- footer.(0, avail.size)
540
+ footer.call(0, avail.size)
542
541
  else
543
542
  puts 'No updates were found'
544
543
  end
@@ -623,7 +622,7 @@ module Squared
623
622
  if opt =~ op.values
624
623
  case $1
625
624
  when 'w', 'workspace'
626
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
625
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
627
626
  end
628
627
  elsif opt.include?('=')
629
628
  op.errors << opt
@@ -704,7 +703,7 @@ module Squared
704
703
  cmd = session dependbin, 'pack'
705
704
  if dependtype(:yarn) > 1
706
705
  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')
706
+ op << quote_option('out', Pathname.pwd + "#{project}-#{version}.tgz") unless op.arg?('out')
708
707
  else
709
708
  op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
710
709
  project: self)
@@ -714,7 +713,7 @@ module Squared
714
713
 
715
714
  case $1
716
715
  when 'w', 'workspace'
717
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
716
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
718
717
  op.found << opt
719
718
  end
720
719
  end
@@ -725,7 +724,7 @@ module Squared
725
724
  run(from: :pack)
726
725
  end
727
726
 
728
- def compose(target, opts = nil, script: false, args: nil, from: :run, **)
727
+ def compose(target, opts = nil, script: false, args: nil, from: nil, **)
729
728
  return unless target
730
729
 
731
730
  if script
@@ -902,21 +901,6 @@ module Squared
902
901
  end
903
902
  end
904
903
 
905
- def confirm_outdated(pkg, ver, rev, lock)
906
- a = sub_style(case rev
907
- when 1
908
- 'MAJOR'
909
- when 3
910
- 'MINOR'
911
- else
912
- 'PATCH'
913
- end, styles: theme[:header])
914
- b = sub_style("#{pkg} #{ver}", styles: theme[:inline])
915
- c, d = rev == 1 || lock ? ['y/N', 'N'] : ['Y/n', 'Y']
916
- e = lock ? " #{sub_style('(locked)', styles: color(:red))}" : ''
917
- confirm("Upgrade to #{a}? #{b + e} [#{c}] ", d, timeout: 60)
918
- end
919
-
920
904
  def dryrun?(prefix = dependbin, **)
921
905
  super || !option('dry-run', prefix: prefix).nil?
922
906
  end
@@ -10,13 +10,13 @@ module Squared
10
10
  common: %w[b B d E h i I O OO P q s S u v x c=q m=b W=b X=q check-hash-based-pycs=b].freeze,
11
11
  build: %w[n|no-isolation s|sdist v|verbose w|wheel x|skip-dependency-check C|config-setting=q installer=b
12
12
  o|outdir=p].freeze,
13
- venv: %w[clear copies symlinks system-site-packages upgrade upgrade-deps without-scm-ignore-files
14
- without-pip prompt=q].freeze
13
+ venv: %w[clear copies symlinks system-site-packages upgrade upgrade-deps without-scm-ignore-files without-pip
14
+ prompt=q].freeze
15
15
  }.freeze
16
16
  OPT_PIP = {
17
17
  common: %w[debug disable-pip-version-check isolated no-cache-dir no-color no-input no-python-version-warning
18
- q|quiet require-virtualenv v|verbose cache-dir=p cert=p client-cert=p exists-action=b log=p
19
- proxy=q python=q retries=i timeout=i trusted-host=b use-deprecated=b use-feature=b].freeze,
18
+ q|quiet require-virtualenv v|verbose cache-dir=p cert=p client-cert=p exists-action=b log=p proxy=q
19
+ python=q retries=i timeout=i trusted-host=b use-deprecated=b use-feature=b].freeze,
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
@@ -34,7 +34,7 @@ module Squared
34
34
  u|username=b].freeze
35
35
  }.freeze
36
36
  OPT_HATCH = {
37
- common: %w[color interactive no-color no-interactive cache-dir=p config=p data-dir=p e|env=b p|project=e
37
+ common: %w[color interactive no-color no-interactive cache-dir=p config=p data-dir=p e|env=b p|project=b
38
38
  q|quiet v|verbose].freeze,
39
39
  build: %w[clean-hooks-after ext hooks-only no-hooks c|clean t|target=b].freeze,
40
40
  publish: %w[initialize-auth n|no-prompt y|yes a|auth=q ca-cert=p client-cert=p client-key=p o|option=q
@@ -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?
@@ -81,8 +81,8 @@ module Squared
81
81
  initialize_env(**kwargs)
82
82
  end
83
83
  @dependindex = DEP_PYTHON.index { |file| basepath(file).exist? }
84
- @dependfile = basepath(DEP_PYTHON[@dependindex || 0])
85
- @verbose = $1.size if verbose.is_a?(String) && verbose =~ /^(v+)$/
84
+ @dependfile = @path + DEP_PYTHON[@dependindex || 0]
85
+ @verbose = verbose.size if verbose.is_a?(String) && verbose.match?(/\Av+\z/)
86
86
  @editable = case editable
87
87
  when '.', Pathname
88
88
  editable
@@ -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
@@ -119,12 +119,12 @@ module Squared
119
119
  if flag == :create
120
120
  format_desc action, flag, 'dir,opts*'
121
121
  task flag, [:dir] do |_, args|
122
- dir = basepath(param_guard(action, flag, args: args, key: :dir))
122
+ dir = path + param_guard(action, flag, args: args, key: :dir)
123
123
  cmd, opts = python_session('-m venv', opts: args.extras)
124
124
  op = OptionPartition.new(opts, OPT_PYTHON[:venv], cmd, project: self)
125
125
  op.append(dir, delim: true)
126
126
  .clear(pass: false)
127
- v = op.arg?(/^-v+$/, 'verbose')
127
+ v = op.arg?(/\A-v+\z/, 'verbose')
128
128
  run(exception: true)
129
129
  puts(dir.directory? ? "Success: #{dir}" : 'Failed') unless v
130
130
  end
@@ -142,7 +142,8 @@ module Squared
142
142
  when :run
143
143
  format_desc action, flag, 'args+'
144
144
  task flag do |_, args|
145
- args = param_guard(action, flag, args: args.to_a)
145
+ args = args.to_a
146
+ args = readline('Enter command', force: true).split(' ', 2) if args.empty?
146
147
  venv_init
147
148
  run session(*args, path: false)
148
149
  end
@@ -170,12 +171,9 @@ module Squared
170
171
  end
171
172
  when 'install'
172
173
  format_desc(action, flag, 'opts*', before: case flag
173
- when :target
174
- 'dir'
175
- when :editable
176
- 'path/url?'
177
- when :upgrade
178
- 'strategy?,package+'
174
+ when :target then 'dir'
175
+ when :editable then 'path/url?'
176
+ when :upgrade then 'strategy?,package+'
179
177
  end)
180
178
  case flag
181
179
  when :editable
@@ -205,20 +203,16 @@ module Squared
205
203
  end
206
204
  when 'build'
207
205
  format_desc(action, flag, 'opts*', after: case flag
208
- when :python
209
- 'srcdir?'
210
- when :hatch
211
- 'location?'
206
+ when :python then 'srcdir?'
207
+ when :hatch then 'location?'
212
208
  end)
213
209
  task flag do |_, args|
214
- buildx flag, args.to_a
210
+ build! flag, args.to_a
215
211
  end
216
212
  when 'publish'
217
213
  format_desc(action, flag, 'opts*', after: case flag
218
- when :hatch
219
- 'artifacts?'
220
- when :twine
221
- 'dist?'
214
+ when :hatch then 'artifacts?'
215
+ when :twine then 'dist?'
222
216
  end)
223
217
  task flag do |_, args|
224
218
  publish flag, args.to_a
@@ -246,7 +240,7 @@ module Squared
246
240
  when :user
247
241
  cmd << '--user'
248
242
  when :target
249
- cmd << quote_option('target', basepath(target))
243
+ cmd << quote_option('target', path + target)
250
244
  when :force
251
245
  cmd << '--force-reinstall'
252
246
  end
@@ -264,10 +258,10 @@ module Squared
264
258
  def outdated(*, sync: invoked_sync?('outdated'))
265
259
  cmd = pip_session 'list', '--outdated'
266
260
  append_global
267
- cmd = session_done(cmd)
261
+ cmd = session_done cmd
268
262
  log.info cmd
269
263
  on :first, :outdated
270
- banner = format_banner(cmd)
264
+ banner = format_banner cmd
271
265
  print_item banner if sync
272
266
  start = 0
273
267
  found = 0
@@ -285,8 +279,8 @@ module Squared
285
279
 
286
280
  latest = lat.join
287
281
  current = cur.join
288
- semver(cur)
289
- semver(lat)
282
+ semver cur
283
+ semver lat
290
284
  if semmajor?(cur, lat)
291
285
  type = 2
292
286
  major += 1
@@ -311,12 +305,12 @@ module Squared
311
305
  line = sub_style(line, pat: /^(.+)(#{Regexp.escape(latest)})(.+)$/, styles: styles, index: 2)
312
306
  found += 1
313
307
  end
314
- out.("#{start.to_s.rjust(2)}. #{line}")
308
+ out.call("#{start.to_s.rjust(2)}. #{line}")
315
309
  start += 1
316
310
  elsif line.start_with?('Package')
317
311
  unless stdin?
318
312
  sub = { pat: /^(.*)(?<!\dm)(Package|Latest)(.+)$/, styles: theme[:header], index: 2 }
319
- out.(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
313
+ out.call(print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub]))
320
314
  end
321
315
  start += 1
322
316
  end
@@ -350,7 +344,7 @@ module Squared
350
344
  run(from: :install)
351
345
  end
352
346
 
353
- def buildx(flag, opts = [])
347
+ def build!(flag, opts = [])
354
348
  case flag
355
349
  when :python
356
350
  cmd, opts = python_session('-m build', opts: opts)
@@ -378,7 +372,7 @@ module Squared
378
372
  if op.arg?('o', 'output')
379
373
  op.extras << srcdir
380
374
  else
381
- op << quote_option('output', basepath(srcdir))
375
+ op << quote_option('output', path + srcdir)
382
376
  end
383
377
  srcdir = nil
384
378
  end
@@ -390,7 +384,7 @@ module Squared
390
384
  end
391
385
  op << basic_option('p', project) unless ENV['HATCH_PROJECT'] || op.arg?('p', 'project')
392
386
  end
393
- op << shell_quote(basepath(srcdir)) if srcdir
387
+ op << shell_quote(path + srcdir) if srcdir
394
388
  op.clear
395
389
  run(from: :"#{flag}:build")
396
390
  end
@@ -409,7 +403,7 @@ module Squared
409
403
  end
410
404
  op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
411
405
  if op.empty?
412
- dist = basepath.join('dist')
406
+ dist = path + 'dist'
413
407
  raise_error('no source files found', hint: dist) unless dist.directory? && !dist.empty?
414
408
  op.extras << "#{dist}/*" unless flag == :poetry
415
409
  end
@@ -468,7 +462,7 @@ module Squared
468
462
  def python_session(*cmd, opts: nil)
469
463
  return session('python', *preopts(quiet: false), *cmd, path: venv.nil?) unless opts
470
464
 
471
- op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /^v+$/)
465
+ op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /\Av+\z/)
472
466
  ret = session('python', *op.to_a, *cmd, path: venv.nil?)
473
467
  [ret, op.extras]
474
468
  end
@@ -476,7 +470,7 @@ module Squared
476
470
  def poetry_session(*cmd)
477
471
  ret = session('poetry', *cmd, *preopts)
478
472
  if (val = option('project', ignore: false))
479
- ret << quote_option('project', basepath(val))
473
+ ret << quote_option('project', path + val)
480
474
  end
481
475
  ret
482
476
  end
@@ -513,7 +507,7 @@ module Squared
513
507
  end
514
508
  op.swap
515
509
  if edit
516
- edit = basepath(edit) unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
510
+ edit = path + edit unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
517
511
  if flag == :editable
518
512
  op.extras << edit
519
513
  else
@@ -541,7 +535,7 @@ module Squared
541
535
  when '0', 'false'
542
536
  return
543
537
  else
544
- val = basepath(val)
538
+ val = path + val
545
539
  end
546
540
  elsif session_arg?('e', 'editable', target: target) || !(val = editable)
547
541
  return
@@ -555,29 +549,29 @@ module Squared
555
549
  when '0', 'false'
556
550
  '--no-cache-dir'
557
551
  else
558
- quote_option('cache-dir', basepath(val))
552
+ quote_option('cache-dir', path + val)
559
553
  end
560
554
  end
561
555
  target << shell_option('proxy', val) if (val = option('proxy', target: target))
562
- target << quote_option('python', basepath(val)) if (val = option('python', target: target))
556
+ target << quote_option('python', path + val) if (val = option('python', target: target))
563
557
  append_nocolor(target: target)
564
558
  end
565
559
 
566
560
  def singleopt(flag = nil)
567
561
  case flag
568
562
  when :python
569
- /^(?:v+|q+|b+)$/
563
+ /\A(?:v+|q+|b+)\z/
570
564
  when :twine
571
565
  nil
572
566
  else
573
- /^(?:v+|q+)$/
567
+ /\A(?:v+|q+)\z/
574
568
  end
575
569
  end
576
570
 
577
571
  def preopts(quiet: true)
578
572
  ret = []
579
573
  case verbose
580
- when false
574
+ when FalseClass
581
575
  ret << '--quiet' if quiet
582
576
  when Numeric
583
577
  ret << "-#{'v' * verbose}" if verbose > 0
@@ -605,7 +599,7 @@ module Squared
605
599
 
606
600
  def venv_set(val)
607
601
  @venv = Pathname.new(val)
608
- @venv = basepath(@venv) unless @venv.absolute?
602
+ @venv = @path + @venv unless @venv.absolute?
609
603
  if projectpath?(@venv)
610
604
  if @venv.exist?
611
605
  log.debug "venv found: #{@venv}"