squared 0.0.9 → 0.0.11

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.
@@ -12,22 +12,21 @@ module Squared
12
12
 
13
13
  class << self
14
14
  def populate(*); end
15
+ def batchargs(*); end
16
+ def aliasargs(*); end
15
17
 
16
18
  def tasks
17
- nil
19
+ %i[outdated].freeze
18
20
  end
19
21
 
20
22
  def venv?
21
- val = ENV['VIRTUAL_ENV']
22
- !val.nil? && Dir.exist?(val)
23
+ Dir.exist?(ENV.fetch('VIRTUAL_ENV', ''))
23
24
  end
24
25
 
25
- def is_a?(val)
26
- if (val = as_path(val))
27
- REQUIREMENTS.any? { |file| val.join(file).exist? }
28
- else
29
- super
30
- end
26
+ def config?(val)
27
+ return false unless (val = as_path(val))
28
+
29
+ REQUIREMENTS.any? { |file| val.join(file).exist? }
31
30
  end
32
31
  end
33
32
 
@@ -35,13 +34,19 @@ module Squared
35
34
 
36
35
  def initialize(*, **kwargs)
37
36
  super
37
+ if @pass.include?(Python.ref)
38
+ initialize_ref(Python.ref)
39
+ initialize_logger(**kwargs)
40
+ else
41
+ initialize_build(Python.ref, **kwargs)
42
+ initialize_env(**kwargs)
43
+ end
38
44
  @reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
39
45
  @requirements = base_path(REQUIREMENTS[@reqindex])
40
- initialize_build(Python.ref, **kwargs)
41
46
  end
42
47
 
43
48
  @@tasks[ref] = {
44
- install: %i[user target upgrade force]
49
+ install: %i[user target upgrade force].freeze
45
50
  }.freeze
46
51
 
47
52
  def ref
@@ -69,7 +74,8 @@ module Squared
69
74
  else
70
75
  OPT_USER
71
76
  end
72
- desc format_desc(action, flag, list + OPT_GENERAL, req: req)
77
+ list += OPT_GENERAL
78
+ desc format_desc(action, flag, list, req: req)
73
79
  if flag == :target
74
80
  task flag, [:dir, :opts] do |_, args|
75
81
  guard_params(action, flag, args: args, key: :dir)
@@ -87,11 +93,10 @@ module Squared
87
93
  end
88
94
  end
89
95
 
90
- def depend(flag = nil, dir: nil, opts: [])
96
+ def depend(flag = nil, dir: nil, opts: [], sync: invoked_sync?('depend', flag))
91
97
  if @depend && !flag
92
98
  super
93
99
  elsif outdated?
94
- sync = invoked_sync?('depend', flag)
95
100
  case (type = install_type)
96
101
  when 1, 2
97
102
  cmd = pip_session 'install'
@@ -128,6 +133,25 @@ module Squared
128
133
  requirements.exist? ? @reqindex + 1 : 0
129
134
  end
130
135
 
136
+ def variable_set(key, *val, **)
137
+ case key
138
+ when :requirements
139
+ req = base_path(val.first)
140
+ if (index = REQUIREMENTS.index(req.basename.to_s))
141
+ @reqindex = index
142
+ @requirements = req
143
+ else
144
+ log.warn "variable_set: @#{key}=#{req} (not supported)"
145
+ end
146
+ else
147
+ super
148
+ end
149
+ end
150
+
151
+ def depend?
152
+ @depend != false && (!@depend.nil? || outdated?)
153
+ end
154
+
131
155
  def outdated?
132
156
  install_type > 0
133
157
  end
@@ -149,21 +173,23 @@ module Squared
149
173
  (v ? "-#{v[0]}" : "--#{opt}")
150
174
  end
151
175
  end
152
- @session << '--user' if env('PIP_USER')
153
- @session << '--no-input' if env('PIP_NO_INPUT')
154
- if (val = env('PIP_PROXY'))
176
+ @session << '--user' if option('user')
177
+ @session << '--no-input' if option('no-input')
178
+ if (val = option('proxy', ignore: false))
155
179
  @session << "--proxy=#{shell_escape(val, quote: true)}"
156
180
  end
157
- if (val = env('PIP_LOG'))
181
+ if (val = option('log', ignore: false))
158
182
  @session << "--log=#{shell_escape(base_path(val).to_s, quote: true)}"
159
183
  end
160
- append_nocolor
184
+ append_nocolor option('no-color')
161
185
  end
162
186
 
163
187
  def append_eager(opts)
164
188
  @session << '--upgrade-strategy=eager' if opts.include?('eager')
165
189
  end
166
190
  end
191
+
192
+ Application.implement Python
167
193
  end
168
194
  end
169
195
  end
@@ -4,33 +4,35 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Ruby < Git
7
+ VAR_SET = %i[version autodetect].freeze
7
8
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
9
+ RUBY_DIR = [*GEMFILE, *::Rake::Application::DEFAULT_RAKEFILES, 'README.rdoc'].freeze
8
10
  OPT_INSTALL = %w[no-cache force].freeze
9
11
  OPT_UPDATE = %w[redownload local strict conservative group=s].freeze
10
12
  OPT_OUTDATED = %w[local strict pre only-explicit group=s].freeze
11
- private_constant :GEMFILE, :OPT_INSTALL, :OPT_UPDATE, :OPT_OUTDATED
13
+ private_constant :VAR_SET, :GEMFILE, :RUBY_DIR, :OPT_INSTALL, :OPT_UPDATE, :OPT_OUTDATED
12
14
 
13
15
  class << self
14
16
  def populate(*); end
17
+ def batchargs(*); end
18
+ def aliasargs(*); end
15
19
 
16
20
  def tasks
17
- nil
21
+ %i[outdated].freeze
18
22
  end
19
23
 
20
- def is_a?(val)
21
- if (val = as_path(val))
22
- [*GEMFILE, *::Rake::Application::DEFAULT_RAKEFILES, 'README.rdoc'].any? { |file| val.join(file).exist? }
23
- else
24
- super
25
- end
24
+ def config?(val)
25
+ return false unless (val = as_path(val))
26
+
27
+ RUBY_DIR.any? { |file| val.join(file).exist? }
26
28
  end
27
29
  end
28
30
 
29
31
  @@tasks[ref] = {
30
- install: %i[redownload local prefer-local gem with without],
31
- update: %i[all patch minor major],
32
- outdated: %i[patch minor major],
33
- pristine: %i[gem all version],
32
+ install: %i[redownload local prefer-local gem with without].freeze,
33
+ update: %i[all patch minor major].freeze,
34
+ outdated: %i[patch minor major].freeze,
35
+ pristine: %i[gem all version].freeze,
34
36
  exec: nil,
35
37
  config: nil,
36
38
  rake: nil
@@ -40,8 +42,14 @@ module Squared
40
42
 
41
43
  def initialize(*, version: nil, autodetect: false, **kwargs)
42
44
  super
43
- initialize_build(Ruby.ref, **kwargs)
44
- @version = env('BUILD', version, suffix: 'VERSION', strict: true)
45
+ if @pass.include?(Ruby.ref)
46
+ initialize_ref(Ruby.ref)
47
+ initialize_logger(**kwargs)
48
+ else
49
+ initialize_build(Ruby.ref, **kwargs)
50
+ initialize_env(**kwargs)
51
+ end
52
+ @version = env('BUILD', version, suffix: 'VERSION')
45
53
  @autodetect = autodetect
46
54
  index = GEMFILE.index { |file| base_path(file).exist? } || 0
47
55
  @gemfile = base_path(GEMFILE[index])
@@ -83,7 +91,7 @@ module Squared
83
91
 
84
92
  desc format_desc(action, nil, 'command*')
85
93
  task action, [:command] do |_, args|
86
- rake args.to_a
94
+ rake(*args.to_a)
87
95
  end
88
96
  end
89
97
  else
@@ -146,7 +154,7 @@ module Squared
146
154
  end
147
155
  end
148
156
 
149
- def depend(flag = nil, opts: [])
157
+ def depend(flag = nil, opts: [], sync: invoked_sync?('depend', flag))
150
158
  if @depend && !flag
151
159
  super
152
160
  elsif outdated?
@@ -159,7 +167,7 @@ module Squared
159
167
  append_repeat flag, opts
160
168
  when :redownload, :local, :'prefer-local'
161
169
  cmd = bundle_session 'install', "--#{flag}"
162
- if (val = env('BUNDLE_TRUST_POLICY'))
170
+ if (val = option('trust-policy', ignore: false))
163
171
  cmd << "--trust-policy=#{case val
164
172
  when '0'
165
173
  'NoSecurity'
@@ -180,88 +188,95 @@ module Squared
180
188
  bundle_session 'install'
181
189
  append_bundle
182
190
  end
183
- run_rb(sync: invoked_sync?('depend', flag))
191
+ run_rb(sync: sync)
184
192
  end
185
193
  end
186
194
 
187
- def copy(from: 'lib', glob: '**/*', gemdir: @gemdir, override: false)
195
+ def copy(from: 'lib', glob: '**/*', into: @gemdir, override: false)
188
196
  if @copy && !override
189
- return super if @copy.is_a?(::String)
197
+ return super if runnable?(@copy)
190
198
 
191
199
  from = @copy[:from] if @copy.key?(:from)
192
200
  glob = @copy[:glob] if @copy.key?(:glob)
193
- gemdir = @copy[:gemdir] if @copy.key?(:gemdir)
201
+ into = @copy[:into] if @copy.key?(:into)
194
202
  end
195
- return unless gemdir
203
+ return unless into
196
204
 
197
- dest = Pathname.new(gemdir).realpath
205
+ dest = Pathname.new(into).realpath
198
206
  print_item unless @output[0]
199
207
  glob = as_a(glob)
200
208
  as_a(from).each_with_index do |val, i|
201
209
  a = base_path(val)
202
210
  b = dest.join(val)
203
211
  c = glob[i] || '**/*'
204
- log.warn "cp #{a.join(c)} #{b}"
205
- copy_d(a, b, glob: c, verbose: verbose?)
212
+ log.info "cp #{a.join(c)} #{b}"
213
+ copy_d(a, b, glob: c, verbose: verbose)
206
214
  end
207
215
  end
208
216
 
209
217
  def outdated(rev = nil, opts: [])
210
218
  cmd = bundle_session 'outdated', rev && "--#{rev}"
211
219
  append_bundle opts, OPT_OUTDATED
212
- cmd = cmd.done
220
+ cmd = session_done(cmd)
213
221
  log.info cmd
214
- print_item format_banner(cmd) if store_pwd || invoked_sync?("outdated#{rev && ":#{rev}"}")
222
+ banner = format_banner(cmd)
223
+ if invoked_sync?('outdated', rev)
224
+ print_item banner
225
+ banner = nil
226
+ end
215
227
  start = 0
216
228
  found = 0
217
229
  major = 0
218
- IO.popen("#{cmd} --no-color").each do |line|
219
- if start > 0
220
- unless pipe?
221
- data = line.scan(SEM_VER)
222
- cur = data.shift
223
- lat = data.shift
224
- if cur && lat
230
+ pwd_set do
231
+ IO.popen("#{cmd} --no-color").each do |line|
232
+ if start > 0
233
+ unless stdin?
234
+ data = line.scan(SEM_VER)
235
+ next unless (cur = data.shift) && (lat = data.shift)
236
+
225
237
  semver(cur)
226
238
  semver(lat)
227
239
  c = cur.join
228
240
  l = lat.join
229
241
  styles = []
230
- data.each do |val|
231
- break unless (req = /(>=?|=|~>|!=|<=?) (#{Regexp.escape(val.join)})/.match(line))
232
-
233
- v = semver(val).join
234
- case req[1]
235
- when '>', '>='
236
- if semmajor(cur, lat)
237
- styles = %i[green bold]
238
- major += 1
239
- else
240
- styles[0] = cur[2] == lat[2] ? :yellow : :green
241
- end
242
- when '<', '<='
243
- if c <= v
244
- if semmajor(cur, lat)
245
- styles = %i[green bold]
246
- major += 1
242
+ major_set = lambda do
243
+ styles = %i[green bold]
244
+ major += 1
245
+ end
246
+ minor_set = -> { styles[0] = cur[2] == lat[2] ? :yellow : :green }
247
+ if data.empty?
248
+ semmajor(cur, lat) ? major_set.() : minor_set.()
249
+ else
250
+ data.each do |val|
251
+ break unless (req = /(>=?|=|~>|!=|<=?) (#{Regexp.escape(val.join)})/.match(line))
252
+
253
+ v = semver(val).join
254
+ case req[1]
255
+ when '>', '>='
256
+ semmajor(cur, lat) ? major_set.() : minor_set.()
257
+ when '<', '<='
258
+ if c <= v
259
+ if semmajor(cur, lat)
260
+ major_set.()
261
+ else
262
+ styles[0] = :yellow
263
+ end
264
+ end
265
+ when '!='
266
+ if c == l
267
+ styles.clear
247
268
  else
269
+ styles[1] = :bold
270
+ end
271
+ when '~>'
272
+ if c < v && cur[0] == val[0] && !semmajor(cur, val)
248
273
  styles[0] = :yellow
274
+ elsif semmajor(val, lat)
275
+ styles[1] = :underline
276
+ else
277
+ styles[1] = :bold
249
278
  end
250
279
  end
251
- when '!='
252
- if c == l
253
- styles.clear
254
- else
255
- styles[1] = :bold
256
- end
257
- when '~>'
258
- if c < v && cur[0] == val[0] && !semmajor(cur, val)
259
- styles[0] = :yellow
260
- elsif semmajor(lat, val)
261
- styles[1] = :underline
262
- else
263
- styles[1] = :bold
264
- end
265
280
  end
266
281
  end
267
282
  unless styles.empty?
@@ -272,29 +287,40 @@ module Squared
272
287
  when :yellow
273
288
  found += 1
274
289
  end
275
- line = sub_style(line, pat: /^((?:\S+\s+){2})(#{Regexp.escape(l)})(.+)$/,
276
- styles: styles.compact, index: 2)
290
+ styles = styles.compact
291
+ .map { |s| s == :green || s == :yellow ? color(s) : s }
292
+ .flatten
293
+ line = sub_style(line, pat: /^((?:\S+\s+){2})(#{Regexp.escape(l)})(.*)$/, styles: styles,
294
+ index: 2)
277
295
  end
278
296
  end
297
+ puts "#{start.to_s.rjust(2)}. #{line}"
298
+ start += 1
299
+ elsif line =~ /^Gem /
300
+ print_item banner if banner
301
+ unless stdin?
302
+ sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
303
+ puts print_footer(" # #{line.chomp}", reverse: true, sub: [sub, sub])
304
+ end
305
+ start += 1
279
306
  end
280
- puts "#{start.to_s.rjust(2)}. #{line}"
281
- start += 1
282
- elsif line =~ /^Gem /
283
- unless pipe?
284
- puts print_footer(" # #{line.chomp}", reverse: true, sub: [
285
- { pat: /^(.+)(Gem)(.+)$/, styles: theme[:header], index: 2 },
286
- { pat: /^(.+)(Latest)(.+)$/, styles: theme[:header], index: 2 }
287
- ])
307
+ end
308
+ if found > 0
309
+ begin
310
+ if major == 0 && (data = /\b(?:source\s+(["'])(.+?)\1|remote:\s+(\S+))/.match(@gemfile.read))
311
+ status = (data[2] || data[3]).chomp('/')
312
+ right = true
313
+ end
314
+ rescue StandardError => e
315
+ log.debug e
316
+ ensure
317
+ status ||= 'Updates are available'
288
318
  end
289
- start += 1
319
+ puts print_footer(empty_status(status, 'major', major, always: !right), right: right)
320
+ elsif start == 0
321
+ puts 'No updates were found'
290
322
  end
291
323
  end
292
- if found > 0
293
- puts print_footer(empty_status('Updates are available', 'major', major, always: true))
294
- elsif start == 0
295
- puts 'No updates were found'
296
- end
297
- store_pwd true
298
324
  end
299
325
 
300
326
  def update(flag, opts: [])
@@ -322,12 +348,8 @@ module Squared
322
348
  run_s "bundle #{flag} #{cmd.join(' ')}"
323
349
  end
324
350
 
325
- def rake(cmd)
326
- if cmd.empty?
327
- run_s 'rake'
328
- else
329
- cmd.each { |val| run_s "rake #{val}" }
330
- end
351
+ def rake(*cmd)
352
+ run_s(cmd.empty? ? 'rake' : cmd.map { |val| "rake #{val}" })
331
353
  end
332
354
 
333
355
  def rakefile
@@ -335,8 +357,26 @@ module Squared
335
357
  base_path(file) if file
336
358
  end
337
359
 
360
+ def variable_set(key, *val, **)
361
+ case key
362
+ when :gemfile
363
+ @gemfile = base_path(val.first)
364
+ else
365
+ super
366
+ end
367
+ end
368
+
369
+ def variables
370
+ ret = super + VAR_SET
371
+ ret.freeze
372
+ end
373
+
374
+ def depend?
375
+ @depend != false && (!@depend.nil? || outdated?)
376
+ end
377
+
338
378
  def copy?
339
- return true if @copy.is_a?(::String) || @copy&.fetch(:gemdir, nil)
379
+ return true if super || (@copy.is_a?(::Hash) && copy.fetch(:into, nil))
340
380
  return gemdir? if @gemdir
341
381
 
342
382
  if @version && (val = ENV['GEM_HOME'])
@@ -346,33 +386,27 @@ module Squared
346
386
  return false unless @autodetect
347
387
 
348
388
  unsafe = ->(hint) { raise_error('failed to parse', hint: hint) }
349
- begin
350
- out = `gem -C #{shell_quote(path)} list --local -d #{project}`
351
- data = /#{Regexp.escape(project)} \(([^)]+)\)/.match(out)
352
- unsafe.('version') unless data
353
- ver = data[1].split(/\s*,\s*/)
354
- if @version
355
- ver.unshift(@version)
356
- ver.uniq!
357
- end
358
- ver.each do |v|
359
- data = /\(#{Regexp.escape(v)}(?:,[^)]+|\b)\):([^\n]+)/.match(out)
360
- next unless data
361
-
362
- log.warn "using version #{v} (given #{@version})" if @version && @version != v
363
- @version = v
364
- break
365
- end
366
- unsafe.('path') unless data
367
- @gemdir = Pathname.new(data[1].strip).join(gempath)
368
- rescue StandardError => e
369
- log.error e
370
- @version = nil
371
- @gemdir = nil
372
- @autodetect = false
373
- else
374
- gemdir?
389
+ out = `gem -C #{shell_quote(path)} list --local -d #{project}`
390
+ data = /#{Regexp.escape(project)} \(([^)]+)\)/.match(out)
391
+ unsafe.('version') unless data
392
+ ver = data[1].split(/\s*,\s*/)
393
+ ver.unshift(@version).uniq! if @version
394
+ ver.each do |v|
395
+ next unless (data = /\(#{Regexp.escape(v)}(?:,[^)]+|\b)\):([^\n]+)/.match(out))
396
+
397
+ log.warn "using version #{v} (given #{@version})" if @version && @version != v
398
+ @version = v
399
+ break
375
400
  end
401
+ unsafe.('path') unless data
402
+ @gemdir = Pathname.new(data[1].strip).join(gempath)
403
+ rescue StandardError => e
404
+ log.error e
405
+ @version = nil
406
+ @gemdir = nil
407
+ @autodetect = false
408
+ else
409
+ gemdir?
376
410
  end
377
411
 
378
412
  def outdated?
@@ -386,7 +420,7 @@ module Squared
386
420
  end
387
421
 
388
422
  def append_bundle(opts = nil, list = nil)
389
- if (val = env('BUNDLE_JOBS')).to_i > 0
423
+ if (val = option('jobs')).to_i > 0
390
424
  @session << "-j#{val}"
391
425
  end
392
426
  return unless opts && list
@@ -400,26 +434,19 @@ module Squared
400
434
  end
401
435
  end
402
436
 
403
- def append_repeat(flag, opts)
404
- opts.each { |val| @session << "--#{flag}=#{shell_escape(val, quote: true)}" }
405
- end
406
-
407
- def append_value(opts)
408
- opts.each { |val| @session << val }
409
- end
410
-
411
437
  def gem_session(*cmd)
412
438
  ret = session('gem', *cmd)
413
- if (val = env('GEM_CONFIG_FILE'))
439
+ if (val = option('config-file', ignore: false))
414
440
  ret << "--config-file=#{shell_escape(base_path(val).to_s, quote: true)}"
415
441
  end
416
- ret << '--norc' if env('GEM_NORC')
442
+ ret << '--norc' if option('norc')
417
443
  ret
418
444
  end
419
445
 
420
446
  def bundle_session(*cmd)
421
447
  session('bundle', *cmd)
422
- append_nocolor
448
+ append_nocolor option('no-color')
449
+ @session
423
450
  end
424
451
 
425
452
  def gempath
@@ -430,6 +457,8 @@ module Squared
430
457
  @gemdir.exist? && !@gemdir.empty?
431
458
  end
432
459
  end
460
+
461
+ Application.implement Ruby
433
462
  end
434
463
  end
435
464
  end
@@ -18,6 +18,3 @@ end
18
18
 
19
19
  require_relative 'project/base'
20
20
  require_relative 'project/git'
21
- require_relative 'project/node'
22
- require_relative 'project/python'
23
- require_relative 'project/ruby'