Class: Squared::Workspace::Project::Python
- Inherits:
-
Git
- Object
- Base
- Git
- Squared::Workspace::Project::Python
show all
- Defined in:
- lib/squared/workspace/project/python.rb
Constant Summary
Constants included
from Common
Common::ARG
Instance Attribute Summary
Attributes inherited from Base
#dependfile, #exception, #group, #name, #parent, #path, #pipe, #project, #theme, #verbose, #workspace
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Git
#checkout, #commit, #diff, #fetch, #files, #pull, #rebase, #refs, #reset, #restore, #rev, #show, #stash, #status, #tag
Methods inherited from Base
#add, aliasargs, #allref, as_path, #basepath, #build, #build?, #clean, #clean?, #copy, #copy?, #dependtype, #dev?, #doc, #doc?, #enabled?, #graph, #graph?, #has?, #initialize_build, #initialize_env, #initialize_logger, #initialize_ref, #inspect, #log, #prod?, ref, #ref?, #script?, #test, #test?, to_s, #to_s, #to_sym, #version, #with
#enable_aixterm
Constructor Details
#initialize(**kwargs) ⇒ Python
Returns a new instance of Python.
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/squared/workspace/project/python.rb', line 36
def initialize(*, **kwargs)
super
if @pass.include?(Python.ref)
initialize_ref(Python.ref)
initialize_logger(**kwargs)
else
initialize_build(Python.ref, **kwargs)
initialize_env(**kwargs)
end
@dependindex = REQUIREMENTS.index { |file| basepath(file).exist? }
@dependfile = basepath(REQUIREMENTS[@dependindex || 0])
end
|
Class Method Details
.bannerargs ⇒ Object
21
22
23
|
# File 'lib/squared/workspace/project/python.rb', line 21
def bannerargs
%i[dependfile].freeze
end
|
.batchargs ⇒ Object
15
|
# File 'lib/squared/workspace/project/python.rb', line 15
def batchargs(*); end
|
.config?(val) ⇒ Boolean
29
30
31
32
33
|
# File 'lib/squared/workspace/project/python.rb', line 29
def config?(val)
return false unless (val = as_path(val))
(REQUIREMENTS + ['setup.py']).any? { |file| val.join(file).exist? }
end
|
.populate ⇒ Object
14
|
# File 'lib/squared/workspace/project/python.rb', line 14
def populate(*); end
|
.tasks ⇒ Object
17
18
19
|
# File 'lib/squared/workspace/project/python.rb', line 17
def tasks
%i[outdated].freeze
end
|
.venv? ⇒ Boolean
25
26
27
|
# File 'lib/squared/workspace/project/python.rb', line 25
def venv?
Dir.exist?(ENV.fetch('VIRTUAL_ENV', ''))
end
|
Instance Method Details
#depend(flag = nil, dir: nil, opts: [], sync: invoked_sync?('depend', flag)) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/squared/workspace/project/python.rb', line 97
def depend(flag = nil, dir: nil, opts: [], sync: invoked_sync?('depend', flag))
if @depend && !flag
super
elsif outdated?
cmd = pip_session 'install'
case flag
when :user
cmd << '--user'
append_pip opts, OPT_USER
when :target
cmd << shell_option('target', basepath(dir), quote: true)
append_pip opts, OPT_USER + ['upgrade']
append_eager opts
when :upgrade
cmd << '--upgrade'
= []
append_pip(opts, OPT_FORCE, extra: )
append_eager opts
.delete('eager')
append_value(, delim: true)
when :force
cmd << '--force-reinstall'
append_pip opts, OPT_FORCE
else
append_pip
end
cmd << (dependtype == 1 ? '-r requirements.txt' : '.') unless flag == :upgrade
run(sync: sync)
end
end
|
#depend? ⇒ Boolean
149
150
151
|
# File 'lib/squared/workspace/project/python.rb', line 149
def depend?
@depend != false && (!@depend.nil? || outdated?)
end
|
#outdated(sync: invoked_sync?('outdated')) ⇒ Object
128
129
130
131
132
|
# File 'lib/squared/workspace/project/python.rb', line 128
def outdated(*, sync: invoked_sync?('outdated'))
pip_session 'list', '--outdated'
append_pip
run(sync: sync)
end
|
#outdated? ⇒ Boolean
153
154
155
|
# File 'lib/squared/workspace/project/python.rb', line 153
def outdated?
dependtype > 0
end
|
#populate ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/squared/workspace/project/python.rb', line 57
def populate(*)
super
return unless outdated? && ref?(Python.ref)
namespace name do
@@tasks[Python.ref].each do |action, flags|
namespace action do
flags.each do |flag|
case action
when :install
list = case flag
when :target
req = 'dir'
OPT_USER + %w[upgrade eager]
when :upgrade
OPT_FORCE + ['eager']
when :force
OPT_FORCE
else
OPT_USER
end
list += OPT_GENERAL
desc format_desc(action, flag, list, req: req)
if flag == :target
task flag, [:dir] do |_, args|
dir = guard_params(action, flag, args: args, key: :dir)
depend(flag, dir: dir, opts: args.)
end
else
task flag do |_, args|
depend(flag, opts: args.to_a)
end
end
end
end
end
end
end
end
|
#ref ⇒ Object
53
54
55
|
# File 'lib/squared/workspace/project/python.rb', line 53
def ref
Python.ref
end
|
#variable_set(key, *val) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/squared/workspace/project/python.rb', line 134
def variable_set(key, *val, **)
case key
when :dependfile
req = basepath(*val)
if (index = REQUIREMENTS.index(req.basename.to_s))
@dependindex = index
@dependfile = req
else
log.warn "variable_set: @#{key}=#{req} (not supported)"
end
else
super
end
end
|