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
Instance Attribute Summary collapse
Attributes inherited from Base
#group, #name, #path, #project, #theme, #warning, #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
as_path, #base_path, #build, #build?, #clean, #clean?, #copy, #copy?, #depend?, #dev?, #doc, #doc?, #enabled?, #has?, #initialize_build, #initialize_logger, #initialize_script, #inspect, #log, ref, #refresh, #refresh?, #test, #test?, to_s, #to_s, #to_sym
Constructor Details
#initialize(**kwargs) ⇒ Python
Returns a new instance of Python.
37
38
39
40
41
42
|
# File 'lib/squared/workspace/project/python.rb', line 37
def initialize(*, **kwargs)
super
@reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
@requirements = base_path(REQUIREMENTS[@reqindex])
initialize_build(Python.ref, **kwargs)
end
|
Instance Attribute Details
#requirements ⇒ Object
Returns the value of attribute requirements.
35
36
37
|
# File 'lib/squared/workspace/project/python.rb', line 35
def requirements
@requirements
end
|
Class Method Details
.is_a?(val) ⇒ Boolean
26
27
28
29
30
31
32
|
# File 'lib/squared/workspace/project/python.rb', line 26
def is_a?(val)
if (val = as_path(val))
REQUIREMENTS.any? { |file| val.join(file).exist? }
else
super
end
end
|
.populate ⇒ Object
15
|
# File 'lib/squared/workspace/project/python.rb', line 15
def populate(*); end
|
.tasks ⇒ Object
17
18
19
|
# File 'lib/squared/workspace/project/python.rb', line 17
def tasks
nil
end
|
.venv? ⇒ Boolean
21
22
23
24
|
# File 'lib/squared/workspace/project/python.rb', line 21
def venv?
val = ENV['VIRTUAL_ENV']
!val.nil? && Dir.exist?(val)
end
|
Instance Method Details
#depend(flag = nil, opts: [], override: false) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/squared/workspace/project/python.rb', line 77
def depend(flag = nil, opts: [], override: false)
if @depend && !override
super
elsif outdated?
case (type = install_type)
when 1, 2
cmd = pip_session 'install'
case flag
when :user
cmd << '--user'
append_general opts, OPT_USER
when :upgrade
cmd << '--upgrade'
append_general opts, OPT_UPGRADE
when :force
cmd << '--force-reinstall'
append_general opts, OPT_FORCE
end
cmd << (type == 1 ? '-r requirements.txt' : '.')
run(sync: invoked_sync?('depend'))
when 3
run_s("#{@bin} setup.py install", sync: invoked_sync?('depend'))
end
end
end
|
#install_type ⇒ Object
105
106
107
|
# File 'lib/squared/workspace/project/python.rb', line 105
def install_type(*)
requirements.exist? ? @reqindex + 1 : 0
end
|
#outdated ⇒ Object
103
|
# File 'lib/squared/workspace/project/python.rb', line 103
def outdated(*); end
|
#outdated? ⇒ Boolean
109
110
111
|
# File 'lib/squared/workspace/project/python.rb', line 109
def outdated?
install_type > 0
end
|
#populate ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/squared/workspace/project/python.rb', line 48
def populate(*)
super
return unless outdated? && !@exclude.include?(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 :upgrade
OPT_UPGRADE
when :force
OPT_FORCE
else
OPT_USER
end
desc format_desc(action, flag, list + OPT_GENERAL)
task flag do |_, args|
depend(flag, opts: args.to_a, override: true)
end
end
end
end
end
end
end
|