squared 0.2.2 → 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.
@@ -4,19 +4,22 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Python < Git
7
- REQUIREMENTS = %w[requirements.txt pyproject.toml setup.py].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
7
+ REQUIREMENTS = %w[requirements.txt pyproject.toml].freeze
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.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'
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,56 +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
- case (type = dependtype)
108
- when 1, 2
109
- cmd = pip_session 'install'
110
- case flag
111
- when :user
112
- cmd << '--user'
113
- when :upgrade
114
- cmd << '--upgrade'
115
- case param
116
- when 'eager', 'only-if-needed'
117
- cmd << basic_option('upgrade-strategy', param)
118
- else
119
- opts << param
120
- end
121
- when :force
122
- cmd << '--force-reinstall'
123
- when :target
124
- cmd << quote_option('target', basepath(param))
125
- else
126
- append_global
127
- end
128
- append_pip opts if flag
129
- if type == 2
130
- cmd << '.'
131
- elsif !cmd.find { |val| val =~ /^(?:-r|--requirement)/ }
132
- cmd << '-r requirements.txt'
133
- end
134
- when 3
135
- cmd = python_session 'setup.py', 'install'
136
- case flag
137
- when :user
138
- cmd << '--user'
139
- when :target
140
- cmd << quote_option('build-base', basepath(dir))
141
- end
142
- if option('user')
143
- cmd << '--user'
144
- else
145
- append_first(%w[home prefix], equals: true, escape: false, quote: true, ignore: false)
146
- end
147
- cmd.delete('--user') if workspace.windows?
125
+ cmd = pip_session 'install'
126
+ case flag
127
+ when :user
128
+ cmd << "--#{flag}"
129
+ when :target
130
+ cmd << quote_option('target', basepath(target))
131
+ when :force
132
+ cmd << '--force-reinstall'
133
+ else
134
+ append_global
135
+ 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 << '.'
148
141
  end
149
142
  run(from: :depend, sync: sync)
150
143
  end
151
144
  end
152
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
+
153
161
  def outdated(*, sync: invoked_sync?('outdated'))
154
162
  cmd = pip_session 'list', '--outdated'
155
163
  append_global
@@ -256,36 +264,42 @@ module Squared
256
264
  session('python', *cmd)
257
265
  end
258
266
 
259
- def append_pip(opts, list = nil, target: @session)
267
+ def append_pip(flag, opts, target: @session, from: nil)
260
268
  append_nocolor(target: target)
261
- return if opts.empty?
269
+ return [] unless from && !opts.empty?
262
270
 
271
+ opts, pat = option_sanitize(opts, OPT_PIP[from] + OPT_PIP[:common], target: target)
263
272
  out = []
264
- opts, pat = option_partition(opts, list || (OPT_INSTALL + OPT_GENERAL), target: target)
273
+ edit = nil
265
274
  opts.each do |opt|
266
275
  if opt =~ /^(v+|q+)$/
267
276
  cmd << "-#{$1}"
268
277
  elsif opt =~ pat
269
278
  case $1
270
- when 'root', 'prefix', 'src', 'cert', 'client-cert', 'cache-dir', 'log', 'report',
271
- 'r', 'requirement', 'c', 'constraint', 't', 'target'
272
- target << quote_option($1, basepath($2))
273
279
  when 'e', 'editable'
274
- val = $2
275
- target << quote_option($1, val =~ %r{^[a-z]+\+[a-z]+://} ? val : basepath(val))
276
- when 'proxy', 'config-settings', 'global-option', 'extra-index-url',
277
- 'f', 'find-links', 'i', 'index-url'
278
- target << quote_option($1, $2)
279
- when 'retries', 'timeout'
280
- target << basic_option($1, $2) if $2.to_i > 0
281
- else
282
- target << shell_option($1, $2)
280
+ edit = $2
283
281
  end
282
+ elsif flag == :editable && !edit
283
+ edit = opt
284
284
  else
285
285
  out << opt
286
286
  end
287
287
  end
288
- option_clear(out, target: target)
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
299
+ else
300
+ option_clear(out, target: target)
301
+ []
302
+ end
289
303
  end
290
304
 
291
305
  def append_global
@@ -297,7 +311,7 @@ module Squared
297
311
  quote_option('cache-dir', basepath(val))
298
312
  end
299
313
  end
300
- cmd << quote_option('proxy', val) if (val = option('proxy'))
314
+ cmd << shell_option('proxy', val) if (val = option('proxy'))
301
315
  cmd << quote_option('python', basepath(val)) if (val = option('python'))
302
316
  append_nocolor
303
317
  end