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 inherited
from Base
Base::SEM_VER
Constants included
from Common
Common::ARG
Instance Attribute Summary collapse
Attributes inherited from Base
#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, #stash, #status
Methods inherited from Base
#add, #allref, as_path, #base_path, #build, #build?, #clean, #clean?, #color, #copy, #copy?, #dev?, #doc, #doc?, #enabled?, #has?, #initialize_build, #initialize_env, #initialize_logger, #initialize_ref, #inspect, #log, #prod?, ref, #ref?, #script?, #test, #test?, to_s, #to_s, #to_sym, #variables, #version, #with
Constructor Details
#initialize(**kwargs) ⇒ Python
Returns a new instance of Python.
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/squared/workspace/project/python.rb', line 35
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
@reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
@requirements = base_path(REQUIREMENTS[@reqindex])
end
|
Instance Attribute Details
#requirements ⇒ Object
Returns the value of attribute requirements.
33
34
35
|
# File 'lib/squared/workspace/project/python.rb', line 33
def requirements
@requirements
end
|
Class Method Details
.aliasargs ⇒ Object
16
|
# File 'lib/squared/workspace/project/python.rb', line 16
def aliasargs(*); end
|
.batchargs ⇒ Object
15
|
# File 'lib/squared/workspace/project/python.rb', line 15
def batchargs(*); end
|
.config?(val) ⇒ Boolean
26
27
28
29
30
|
# File 'lib/squared/workspace/project/python.rb', line 26
def config?(val)
return false unless (val = as_path(val))
REQUIREMENTS.any? { |file| val.join(file).exist? }
end
|
.populate ⇒ Object
14
|
# File 'lib/squared/workspace/project/python.rb', line 14
def populate(*); end
|
.tasks ⇒ Object
18
19
20
|
# File 'lib/squared/workspace/project/python.rb', line 18
def tasks
%i[outdated].freeze
end
|
.venv? ⇒ Boolean
22
23
24
|
# File 'lib/squared/workspace/project/python.rb', line 22
def venv?
Dir.exist?(ENV.fetch('VIRTUAL_ENV', ''))
end
|
Instance Method Details
#depend(flag = nil, dir: nil, opts: [], sync: invoked_sync?('depend', flag)) ⇒ Object
96
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
|
# File 'lib/squared/workspace/project/python.rb', line 96
def depend(flag = nil, dir: nil, opts: [], sync: invoked_sync?('depend', flag))
if @depend && !flag
super
elsif outdated?
case (type = install_type)
when 1, 2
cmd = pip_session 'install'
case flag
when :user
cmd << '--user'
append_pip opts, OPT_USER
when :target
cmd << "--target=#{shell_escape(base_path(dir).to_s, quote: true)}"
append_pip opts, OPT_USER + ['upgrade']
append_eager opts
when :upgrade
cmd << '--upgrade'
append_pip opts, OPT_FORCE
append_eager opts
when :force
cmd << '--force-reinstall'
append_pip opts, OPT_FORCE
end
cmd << (type == 1 ? '-r requirements.txt' : '.')
run(sync: sync)
when 3
run_s("#{@bin} setup.py install", sync: sync)
end
end
end
|
#depend? ⇒ Boolean
151
152
153
|
# File 'lib/squared/workspace/project/python.rb', line 151
def depend?
@depend != false && (!@depend.nil? || outdated?)
end
|
#install_type ⇒ Object
132
133
134
|
# File 'lib/squared/workspace/project/python.rb', line 132
def install_type(*)
requirements.exist? ? @reqindex + 1 : 0
end
|
#outdated ⇒ Object
127
128
129
130
|
# File 'lib/squared/workspace/project/python.rb', line 127
def outdated(*)
pip_session 'list', '--outdated'
run
end
|
#outdated? ⇒ Boolean
155
156
157
|
# File 'lib/squared/workspace/project/python.rb', line 155
def outdated?
install_type > 0
end
|
#populate ⇒ Object
56
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
|
# File 'lib/squared/workspace/project/python.rb', line 56
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, :opts] do |_, args|
guard_params(action, flag, args: args, key: :dir)
depend(flag, dir: args.dir, opts: args.to_a)
end
else
task flag do |_, args|
depend(flag, opts: args.to_a)
end
end
end
end
end
end
end
end
|
#ref ⇒ Object
52
53
54
|
# File 'lib/squared/workspace/project/python.rb', line 52
def ref
Python.ref
end
|
#variable_set(key, *val) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/squared/workspace/project/python.rb', line 136
def variable_set(key, *val, **)
case key
when :requirements
req = base_path(val.first)
if (index = REQUIREMENTS.index(req.basename.to_s))
@reqindex = index
@requirements = req
else
log.warn "variable_set: @#{key}=#{req} (not supported)"
end
else
super
end
end
|