squared 0.0.12 → 0.1.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.
@@ -6,7 +6,7 @@ module Squared
6
6
  class Python < Git
7
7
  REQUIREMENTS = %w[requirements.txt pyproject.toml setup.py].freeze
8
8
  OPT_USER = %w[pre dry-run].freeze
9
- OPT_FORCE = [*OPT_USER, 'user'].freeze
9
+ OPT_FORCE = (OPT_USER + ['user']).freeze
10
10
  OPT_GENERAL = %w{venv isolated no-cache-dir [v]erbose}.freeze
11
11
  private_constant :REQUIREMENTS, :OPT_USER, :OPT_FORCE, :OPT_GENERAL
12
12
 
@@ -116,6 +116,8 @@ module Squared
116
116
  when :force
117
117
  cmd << '--force-reinstall'
118
118
  append_pip opts, OPT_FORCE
119
+ else
120
+ append_pip
119
121
  end
120
122
  cmd << (type == 1 ? '-r requirements.txt' : '.')
121
123
  run(sync: sync)
@@ -127,6 +129,7 @@ module Squared
127
129
 
128
130
  def outdated(*)
129
131
  pip_session 'list', '--outdated'
132
+ append_pip
130
133
  run
131
134
  end
132
135
 
@@ -159,7 +162,7 @@ module Squared
159
162
  session('pip', *cmd)
160
163
  end
161
164
 
162
- def append_pip(opts, list = [])
165
+ def append_pip(opts = [], list = [])
163
166
  opts.each do |opt|
164
167
  next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (v = opt.match(/^v+$/))
165
168
 
@@ -170,14 +173,13 @@ module Squared
170
173
  (v ? "-#{v[0]}" : "--#{opt}")
171
174
  end
172
175
  end
173
- @session << '--user' if option('user')
174
- @session << '--no-input' if option('no-input')
175
176
  if (val = option('proxy', ignore: false))
176
177
  @session << "--proxy=#{shell_escape(val, quote: true)}"
177
178
  end
178
- if (val = option('log', ignore: false))
179
- @session << "--log=#{shell_escape(basepath(val), quote: true)}"
180
- end
179
+ @session << "--python=#{shell_escape(basepath(val), quote: true)}" if (val = option('python', ignore: false))
180
+ @session << "--log=#{shell_escape(basepath(val), quote: true)}" if (val = option('log', ignore: false))
181
+ @session << '--user' if option('user')
182
+ @session << '--no-input' if option('no-input')
181
183
  append_nocolor option('no-color')
182
184
  end
183
185
 
@@ -6,7 +6,7 @@ module Squared
6
6
  class Ruby < Git
7
7
  VAR_SET = %i[version autodetect].freeze
8
8
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
9
- RUBY_DIR = [*GEMFILE, *::Rake::Application::DEFAULT_RAKEFILES, 'README.rdoc'].freeze
9
+ RUBY_DIR = (GEMFILE + Rake::Application::DEFAULT_RAKEFILES + ['README.rdoc']).freeze
10
10
  OPT_INSTALL = %w[no-cache force].freeze
11
11
  OPT_UPDATE = %w[redownload local strict conservative group=s].freeze
12
12
  OPT_OUTDATED = %w[local strict pre only-explicit group=s].freeze
@@ -95,7 +95,7 @@ module Squared
95
95
  if args.command == '#'
96
96
  format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
97
97
  each: ->(val) { val[0] + val[1].to_s })
98
- elsif (data = indexdata(args.command))
98
+ elsif (data = indexitem(args.command))
99
99
  n, opts = data
100
100
  list = read_rakefile
101
101
  if (item = list[n - 1])
@@ -206,25 +206,26 @@ module Squared
206
206
  end
207
207
  end
208
208
 
209
- def copy(from: 'lib', glob: nil, into: @gemdir, override: false)
209
+ def copy(from: 'lib', include: nil, exclude: nil, into: @gemdir, override: false)
210
210
  if @copy && !override
211
211
  return super if runnable?(@copy)
212
212
 
213
213
  from = @copy[:from] if @copy.key?(:from)
214
- glob = @copy[:glob] if @copy.key?(:glob)
214
+ glob = @copy[:include] if @copy.key?(:include)
215
+ pass = @copy[:exclude] if @copy.key?(:exclude)
215
216
  into = @copy[:into] if @copy.key?(:into)
216
217
  end
217
218
  return unless into
218
219
 
219
220
  dest = Pathname.new(into).realpath
220
- print_item unless @output[0]
221
+ print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
221
222
  glob = as_a(glob || '**/*')
222
223
  as_a(from).each_with_index do |val, i|
223
224
  a = basepath(val)
224
225
  b = dest.join(val)
225
226
  c = glob[i] || glob[0]
226
227
  log.info "cp #{a.join(c)} #{b}"
227
- copy_d(a, b, glob: c, verbose: verbose)
228
+ copy_d(a, b, glob: c, pass: pass, verbose: verbose)
228
229
  end
229
230
  end
230
231
 
@@ -375,7 +376,7 @@ module Squared
375
376
  end
376
377
 
377
378
  def copy?
378
- return true if super || (@copy.is_a?(::Hash) && copy.fetch(:into, nil))
379
+ return true if super || (@copy.is_a?(Hash) && copy.fetch(:into, nil))
379
380
  return gemdir? if @gemdir
380
381
 
381
382
  if @version && (val = ENV['GEM_HOME'])
@@ -414,11 +415,6 @@ module Squared
414
415
 
415
416
  private
416
417
 
417
- def variables
418
- ret = super + VAR_SET
419
- ret.freeze
420
- end
421
-
422
418
  def run_rb(sync: true)
423
419
  run(sync: sync, banner: !@session.include?('--quiet'))
424
420
  end
@@ -465,18 +461,23 @@ module Squared
465
461
  @rakelist = ret
466
462
  end
467
463
 
464
+ def gemdir?
465
+ @gemdir.exist? && !@gemdir.empty?
466
+ end
467
+
468
+ def variables
469
+ ret = super + VAR_SET
470
+ ret.freeze
471
+ end
472
+
468
473
  def rakefile
469
- file = ::Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
474
+ file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
470
475
  basepath(file) if file
471
476
  end
472
477
 
473
478
  def gempath
474
479
  File.join('gems', "#{project}-#{@version}")
475
480
  end
476
-
477
- def gemdir?
478
- @gemdir.exist? && !@gemdir.empty?
479
- end
480
481
  end
481
482
 
482
483
  Application.implement Ruby
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rexml/document'
4
-
5
3
  module Squared
6
4
  module Workspace
7
5
  module Repo
@@ -9,6 +7,7 @@ module Squared
9
7
 
10
8
  class << self
11
9
  def read_manifest(path)
10
+ require 'rexml/document'
12
11
  return unless (file = path.join('.repo/manifest.xml')).exist?
13
12
 
14
13
  doc = REXML::Document.new(file.read)
@@ -16,7 +15,17 @@ module Squared
16
15
  end
17
16
 
18
17
  def empty?(dir)
19
- dir.empty? || (dir.children.size == 1 && dir.join(dir.children.first).to_s == __FILE__)
18
+ return false unless dir.exist?
19
+
20
+ case dir.children.size
21
+ when 0
22
+ true
23
+ when 1
24
+ file = dir.children.first
25
+ file.to_s == __FILE__ || (file.directory? && file.basename.to_s == '.repo')
26
+ else
27
+ false
28
+ end
20
29
  end
21
30
  end
22
31
 
@@ -45,20 +54,24 @@ module Squared
45
54
  raise_error('REPO_ROOT', val, hint: 'exist') unless repo_confirm
46
55
  end
47
56
  @root.join(main).realdirpath
57
+ elsif repo_install?(@home)
58
+ @home.join(main)
59
+ elsif @home != pwd && repo_install?(pwd)
60
+ pwd.join(main)
48
61
  else
49
- repo_install?(@home) ? @home.join(main) : @home
62
+ @home
50
63
  end
51
64
  @root = @home.parent
52
65
  @manifest_url = url
53
66
  @manifest = manifest
54
- data = script_obj
67
+ data = scriptobj
55
68
  if repo?
56
69
  if script
57
70
  if (val = env('REPO_BUILD'))
58
71
  data[:script] = case val
59
72
  when 'verbose'
60
73
  @verbose = 1
61
- if script.is_a?(::Array)
74
+ if script.is_a?(Array)
62
75
  script[0] = task_join(script[0], 'verbose')
63
76
  script
64
77
  else
@@ -162,7 +175,7 @@ module Squared
162
175
  if (ws = proj.workspace).task_defined?(target = ws.task_name(task_join(proj.name, 'copy')))
163
176
  task_invoke(target, **ws.invokeargs)
164
177
  else
165
- proj.copy(sync: true)
178
+ proj.copy
166
179
  end
167
180
  end
168
181
  end
@@ -182,7 +195,7 @@ module Squared
182
195
  raise_error('repo is not initialized', "rake #{task_name('repo:init')}", kind: LoadError)
183
196
  end
184
197
  parse_opts.(args)
185
- cmd << "-j#{ENV.fetch('REPO_JOBS', ::Rake::CpuCounter.count)}"
198
+ cmd << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}"
186
199
  cmd << '--fail-fast' if failfast
187
200
  puts if newline && stage != 'init'
188
201
  begin
@@ -192,12 +205,13 @@ module Squared
192
205
  raise
193
206
  end
194
207
  end
208
+
209
+ series.sync.push(
210
+ task_join(name, 'all'),
211
+ task_join(name, 'init'),
212
+ task_join(name, 'sync')
213
+ )
195
214
  end
196
- series.sync.push(
197
- task_join(name, 'all'),
198
- task_join(name, 'init'),
199
- task_join(name, 'sync')
200
- )
201
215
  end
202
216
 
203
217
  def repo_confirm
@@ -218,7 +232,7 @@ module Squared
218
232
  def repo_install?(dir = root, parent: false)
219
233
  return true if Repo.empty?(dir) || dir.join('.repo').directory?
220
234
 
221
- parent && root.children.none? { |ent| ent.directory? && ent.basename.to_s[0] != '.' && ent.to_s != home.to_s }
235
+ parent && root.children.none? { |ent| ent.directory? && ent.basename.to_s[0] != '.' && ent != home }
222
236
  end
223
237
  end
224
238
 
@@ -5,13 +5,13 @@ require 'forwardable'
5
5
  module Squared
6
6
  module Workspace
7
7
  class Series
8
- include ::Rake::DSL
8
+ include Rake::DSL
9
9
  extend Forwardable
10
10
 
11
11
  TASK_BASE = %i[build depend graph doc test copy clean]
12
12
  TASK_BATCH = {}
13
13
  TASK_EXTEND = {}
14
- TASK_KEYS = TASK_BASE.dup + TASK_BATCH.keys
14
+ TASK_KEYS = TASK_BASE + TASK_BATCH.keys
15
15
  TASK_ALIAS = {}
16
16
  TASK_NAME = {}
17
17
  private_constant :TASK_BASE, :TASK_BATCH, :TASK_KEYS, :TASK_NAME, :TASK_EXTEND
@@ -19,11 +19,11 @@ module Squared
19
19
  class << self
20
20
  def add(task, obj)
21
21
  key_set task
22
- (TASK_EXTEND[task] ||= []).push(obj)
22
+ (TASK_EXTEND[task] ||= []) << obj
23
23
  end
24
24
 
25
25
  def batch(*args, obj)
26
- if obj.is_a?(::Hash)
26
+ if obj.is_a?(Hash)
27
27
  obj.each do |key, val|
28
28
  key_set key
29
29
  data = TASK_BATCH[key] ||= {}
@@ -36,7 +36,7 @@ module Squared
36
36
  end
37
37
 
38
38
  def alias(ref, obj)
39
- if obj.is_a?(::Hash)
39
+ if obj.is_a?(Hash)
40
40
  obj.each { |key, val| (TASK_ALIAS[key] ||= {})[ref] = val }
41
41
  else
42
42
  TASK_ALIAS[obj]&.delete(ref)
@@ -98,7 +98,8 @@ module Squared
98
98
  end
99
99
  end
100
100
 
101
- def build(parallel: [], **)
101
+ def build(parallel: [], pattern: [], **)
102
+ subcheck = ->(val) { (ns = @workspace.task_namespace(val)) && parallel.include?(ns) }
102
103
  @data.merge!(@session[:parent]) if @session[:id].uniq.size > 1
103
104
  @data.merge!(@session[:group])
104
105
  @data.each do |key, items|
@@ -108,7 +109,7 @@ module Squared
108
109
  val = @workspace.task_name(t, desc: true)
109
110
  if items.size > 1
110
111
  @multiple << key
111
- if parallel.include?(t) || ((ns = @workspace.task_namespace(t)) && parallel.include?(ns))
112
+ if parallel.include?(t) || pattern.any? { |pat| pat.match?(t) } || subcheck.(t)
112
113
  desc "#{val} (thread)"
113
114
  multitask key => items
114
115
  @parallel << key
@@ -173,7 +174,7 @@ module Squared
173
174
  def already_invoked?(list, val)
174
175
  return false if val && !list.include?(val)
175
176
 
176
- ::Rake::Task.tasks.any? { |obj| obj.already_invoked && (val ? val == obj.name : list.include?(obj.name)) }
177
+ Rake::Task.tasks.any? { |obj| obj.already_invoked && (val ? val == obj.name : list.include?(obj.name)) }
177
178
  end
178
179
  end
179
180
 
@@ -7,10 +7,10 @@ module Squared
7
7
 
8
8
  def resolve(*args)
9
9
  ret = args.map do |id|
10
- if id.is_a?(::Symbol)
10
+ if id.is_a?(Symbol)
11
11
  project id
12
12
  else
13
- id = dirpath(id) if id.is_a?(::String)
13
+ id = dirpath(id) if id.is_a?(String)
14
14
  __get__(:project).find { |_, val| val.path.to_s == id.to_s }
15
15
  end
16
16
  end
@@ -24,12 +24,6 @@ module Squared
24
24
  raise NoMethodError, "project is not initialized (#{name})"
25
25
  end
26
26
 
27
- def dirpath(val, absolute: true)
28
- Pathname.new(val).realdirpath
29
- rescue StandardError
30
- absolute ? Pathname.pwd.join(val) : Pathname.new(val)
31
- end
32
-
33
27
  def project?(name)
34
28
  !!project(name)&.enabled?
35
29
  end
@@ -39,6 +33,12 @@ module Squared
39
33
  def project(name)
40
34
  __get__(:project)[name.to_s]
41
35
  end
36
+
37
+ def dirpath(val, absolute: true)
38
+ Pathname.new(val).realdirpath
39
+ rescue StandardError
40
+ absolute ? Pathname.pwd.join(val) : Pathname.new(val)
41
+ end
42
42
  end
43
43
  end
44
44
  end
data/squared.gemspec CHANGED
@@ -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[LICENSE README.md README.ruby.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-01 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - CHANGELOG.md
62
63
  - LICENSE
63
64
  - README.md
64
65
  - README.ruby.md