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, #log, #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?, #doc, #doc?, #enabled?, #has?, #initialize_build, #initialize_script, #inspect, #refresh, #refresh?, #test, #test?, to_s, #to_s, to_sym, #to_sym
Constructor Details
#initialize(name, path, workspace, **kwargs) ⇒ Python
Returns a new instance of Python.
38
39
40
41
42
43
|
# File 'lib/squared/workspace/project/python.rb', line 38
def initialize(name, path, workspace, *, **kwargs)
super
@reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
@requirements = base_path(REQUIREMENTS[@reqindex])
initialize_build(REF, **kwargs)
end
|
Instance Attribute Details
#requirements ⇒ Object
Returns the value of attribute requirements.
36
37
38
|
# File 'lib/squared/workspace/project/python.rb', line 36
def requirements
@requirements
end
|
Class Method Details
.is_a?(val) ⇒ Boolean
27
28
29
30
31
32
33
|
# File 'lib/squared/workspace/project/python.rb', line 27
def is_a?(val)
if (val = as_path(val))
REQUIREMENTS.any? { |file| val.join(file).exist? }
else
super
end
end
|
.populate ⇒ Object
16
|
# File 'lib/squared/workspace/project/python.rb', line 16
def populate(*); end
|
.tasks ⇒ Object
18
19
20
|
# File 'lib/squared/workspace/project/python.rb', line 18
def tasks
nil
end
|
.venv? ⇒ Boolean
22
23
24
25
|
# File 'lib/squared/workspace/project/python.rb', line 22
def venv?
val = ENV['VIRTUAL_ENV']
!val.nil? && Dir.exist?(val)
end
|
Instance Method Details
#depend(flag = nil, opts: [], override: false) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/squared/workspace/project/python.rb', line 78
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(exception: workspace.exception, sync: invoked_sync?('depend'))
when 3
run_s("#{@bin} setup.py install", sync: invoked_sync?('depend'))
end
end
end
|
#depend? ⇒ Boolean
110
111
112
|
# File 'lib/squared/workspace/project/python.rb', line 110
def depend?
outdated? || !!@depend
end
|
#install_type ⇒ Object
106
107
108
|
# File 'lib/squared/workspace/project/python.rb', line 106
def install_type(*)
requirements.exist? ? @reqindex + 1 : 0
end
|
#outdated ⇒ Object
104
|
# File 'lib/squared/workspace/project/python.rb', line 104
def outdated(*); end
|
#outdated? ⇒ Boolean
114
115
116
|
# File 'lib/squared/workspace/project/python.rb', line 114
def outdated?
install_type > 0
end
|
#populate ⇒ Object
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
76
|
# File 'lib/squared/workspace/project/python.rb', line 49
def populate(*)
super
return unless outdated?
namespace name do
@@tasks[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: collect_args(args, :opts), override: true)
end
end
end
end
end
end
end
|