squared 0.2.3 → 0.3.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.
@@ -5,18 +5,21 @@ module Squared
5
5
  module Project
6
6
  class Python < Git
7
7
  REQUIREMENTS = %w[requirements.txt pyproject.toml].freeze
8
- OPT_INSTALL = %w[I U break-system-packages check-build-dependencies compile dry-run force-reinstall
9
- ignore-installed ignore-requires-python no-build-isolation no-clean no-compile no-deps
10
- no-index no-warn-conflicts no-warn-script-location pre prefer-binary require-hashes upgrade
11
- use-pep517 user abi=s config-settings=s c=s constraint=s e=s? editable=s? extra-index-url=s
12
- f=s find-links=s global-option=s implementation=s i=s index-url=s no-binary=s only-binary=s
13
- platform=s prefix=s progress-bar=s python-version=s report=s r=s requirement=s
14
- root-user-action=s root=s src=s t=s target=s upgrade-strategy=s].freeze
15
- OPT_GENERAL = %w[debug disable-pip-version-check isolated q quiet require-virtualenv v verbose
16
- no-cache-dir no-color no-input no-python-version-warning
17
- cache-dir=s cert=s client-cert=s exists-action=s log=s proxy=s python=s retries=i timeout=i
18
- trusted-host=s use-deprecated=s use-feature=s].freeze
19
- private_constant :REQUIREMENTS, :OPT_INSTALL, :OPT_GENERAL
8
+ SETUPTOOLS = %w[setup.py pyproject.toml].freeze
9
+ DIR_PYTHON = (REQUIREMENTS + SETUPTOOLS).freeze
10
+ OPT_PIP = {
11
+ common: %w[debug disable-pip-version-check isolated no-cache-dir no-color no-input no-python-version-warning
12
+ q|quiet require-virtualenv v|verbose cache-dir=p cert=p client-cert=p exists-action=b log=p
13
+ proxy=q python=e retries=i timeout=i trusted-host=e use-deprecated=e use-feature=e].freeze,
14
+ install: %w[break-system-packages check-build-dependencies compile dry-run force-reinstall I|ignore-installed
15
+ ignore-requires-python no-build-isolation no-clean no-compile no-deps no-index no-warn-conflicts
16
+ no-warn-script-location pre prefer-binary require-hashes U|upgrade use-pep517 user abi=e
17
+ config-settings=q c|constraint=p e|editable=s? extra-index-url=q f|find-links=q global-option=q
18
+ implementation=b i|index-url=q no-binary=q only-binary=q platform=q prefix=p progress-bar=b
19
+ python-version=q report=p r|requirement=p root=p root-user-action=e src=p t|target=p
20
+ upgrade-strategy=b].freeze
21
+ }.freeze
22
+ private_constant :REQUIREMENTS, :SETUPTOOLS, :DIR_PYTHON, :OPT_PIP
20
23
 
21
24
  class << self
22
25
  def populate(*); end
@@ -37,7 +40,7 @@ module Squared
37
40
  def config?(val)
38
41
  return false unless (val = as_path(val))
39
42
 
40
- (REQUIREMENTS + ['setup.py']).any? { |file| val.join(file).exist? }
43
+ DIR_PYTHON.any? { |file| val.join(file).exist? }
41
44
  end
42
45
  end
43
46
 
@@ -55,7 +58,7 @@ module Squared
55
58
  end
56
59
 
57
60
  @@tasks[ref] = {
58
- 'install' => %i[user upgrade force target].freeze
61
+ 'install' => %i[user force upgrade target editable].freeze
59
62
  }.freeze
60
63
 
61
64
  def ref
@@ -74,23 +77,38 @@ module Squared
74
77
  flags.each do |flag|
75
78
  case action
76
79
  when 'install'
77
- if @@task_desc
78
- format_desc(action, flag, OPT_INSTALL + OPT_GENERAL, before: case flag
79
- when :target
80
- 'dir'
81
- when :upgrade
82
- 'strategy?,packages+'
83
- end)
84
- end
80
+ format_desc(action, flag, 'opts*', before: case flag
81
+ when :target
82
+ 'dir'
83
+ when :editable
84
+ 'path/url?'
85
+ when :upgrade
86
+ 'eager?,package+'
87
+ end)
85
88
  case flag
86
- when :target, :upgrade
87
- task flag, [:param] do |_, args|
88
- param = param_guard(action, flag, args: args, key: :param)
89
- depend(flag, param: param, opts: args.extras)
89
+ when :editable
90
+ task flag do |_, args|
91
+ install flag, args.to_a
92
+ end
93
+ when :upgrade
94
+ task flag, [:strategy] do |_, args|
95
+ case (strategy = args.strategy)
96
+ when 'eager', 'only-if-needed'
97
+ opts = args.extras
98
+ else
99
+ opts = args.to_a
100
+ strategy = nil
101
+ end
102
+ install(flag, opts, strategy: strategy)
103
+ end
104
+ when :target
105
+ task flag, [:dir] do |_, args|
106
+ dir = param_guard(action, flag, args: args, key: :dir)
107
+ depend(flag, args.extras, target: dir)
90
108
  end
91
109
  else
92
110
  task flag do |_, args|
93
- depend(flag, opts: args.to_a)
111
+ depend flag, args.to_a
94
112
  end
95
113
  end
96
114
  end
@@ -100,41 +118,46 @@ module Squared
100
118
  end
101
119
  end
102
120
 
103
- def depend(flag = nil, sync: invoked_sync?('depend', flag), param: nil, opts: [])
121
+ def depend(flag = nil, opts = [], sync: invoked_sync?('depend', flag), target: nil, **)
104
122
  if @depend && !flag
105
123
  super
106
124
  elsif outdated?
107
125
  cmd = pip_session 'install'
108
126
  case flag
109
127
  when :user
110
- cmd << '--user'
111
- when :upgrade
112
- cmd << '--upgrade'
113
- case param
114
- when 'eager', 'only-if-needed'
115
- cmd << basic_option('upgrade-strategy', param)
116
- else
117
- opts << param
118
- end
128
+ cmd << "--#{flag}"
129
+ when :target
130
+ cmd << quote_option('target', basepath(target))
119
131
  when :force
120
132
  cmd << '--force-reinstall'
121
- when :target
122
- cmd << quote_option('target', basepath(param))
123
133
  else
124
134
  append_global
125
135
  end
126
- append_pip flag, opts if flag
127
- unless flag == :upgrade
128
- if dependtype == 2 || cmd.find { |val| val =~ /^(?:-e|--editable)$/ }
129
- cmd << '.'
130
- elsif !cmd.find { |val| val =~ /^(?:-r|--requirement|-e|--editable)/ }
131
- cmd << '-r requirements.txt'
132
- end
136
+ append_pip(flag, opts, from: :install) if flag
137
+ if dependtype == 1 && !session_arg?('e', 'editable')
138
+ cmd << '-r requirements.txt' unless session_arg?('r', 'requirement')
139
+ elsif !session_arg?('e', 'editable', value: true)
140
+ cmd << '.'
133
141
  end
134
142
  run(from: :depend, sync: sync)
135
143
  end
136
144
  end
137
145
 
146
+ def install(flag, opts, strategy: nil)
147
+ cmd = pip_session 'install'
148
+ out = append_pip(flag, opts, from: :install)
149
+ case flag
150
+ when :editable
151
+ cmd << '--editable' << (out.pop || '.')
152
+ option_clear out
153
+ when :upgrade
154
+ cmd << '--upgrade'
155
+ cmd << basic_option('upgrade-strategy', strategy) if strategy
156
+ append_value out
157
+ end
158
+ run(from: :install)
159
+ end
160
+
138
161
  def outdated(*, sync: invoked_sync?('outdated'))
139
162
  cmd = pip_session 'list', '--outdated'
140
163
  append_global
@@ -241,39 +264,41 @@ module Squared
241
264
  session('python', *cmd)
242
265
  end
243
266
 
244
- def append_pip(flag, opts, target: @session)
267
+ def append_pip(flag, opts, target: @session, from: nil)
245
268
  append_nocolor(target: target)
246
- return if opts.empty?
269
+ return [] unless from && !opts.empty?
247
270
 
271
+ opts, pat = option_sanitize(opts, OPT_PIP[from] + OPT_PIP[:common], target: target)
248
272
  out = []
249
- opts, pat = option_partition(opts, OPT_INSTALL + OPT_GENERAL, target: target)
273
+ edit = nil
250
274
  opts.each do |opt|
251
275
  if opt =~ /^(v+|q+)$/
252
276
  cmd << "-#{$1}"
253
277
  elsif opt =~ pat
254
278
  case $1
255
- when 'root', 'prefix', 'src', 'cert', 'client-cert', 'cache-dir', 'log', 'report',
256
- 'r', 'requirement', 'c', 'constraint', 't', 'target'
257
- target << quote_option($1, basepath($2))
258
279
  when 'e', 'editable'
259
- val = $2
260
- target << quote_option($1, val =~ %r{^[a-z]+(?:\+[a-z]+)?://}i ? val : basepath(val))
261
- when 'proxy', 'config-settings', 'global-option', 'extra-index-url',
262
- 'f', 'find-links', 'i', 'index-url'
263
- target << quote_option($1, $2)
264
- when 'retries', 'timeout'
265
- target << basic_option($1, $2) if $2.to_i > 0
266
- else
267
- target << shell_option($1, $2)
280
+ edit = $2
268
281
  end
282
+ elsif flag == :editable && !edit
283
+ edit = opt
269
284
  else
270
285
  out << opt
271
286
  end
272
287
  end
273
- if flag == :upgrade
274
- append_value(out, delim: true)
288
+ if edit
289
+ edit = basepath(edit) unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
290
+ if flag == :editable
291
+ out << edit
292
+ else
293
+ target << quote_option('editable', edit)
294
+ end
295
+ end
296
+ case flag
297
+ when :editable, :upgrade
298
+ out
275
299
  else
276
300
  option_clear(out, target: target)
301
+ []
277
302
  end
278
303
  end
279
304
 
@@ -286,7 +311,7 @@ module Squared
286
311
  quote_option('cache-dir', basepath(val))
287
312
  end
288
313
  end
289
- cmd << quote_option('proxy', val) if (val = option('proxy'))
314
+ cmd << shell_option('proxy', val) if (val = option('proxy'))
290
315
  cmd << quote_option('python', basepath(val)) if (val = option('python'))
291
316
  append_nocolor
292
317
  end