Class: Squared::Repo::Project::Python
- Inherits:
-
Git
- Object
- Base
- Git
- Squared::Repo::Project::Python
show all
- Defined in:
- lib/squared/repo/project/python.rb
Instance Attribute Summary
Attributes inherited from Base
#group, #name, #path, #project, #workspace
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Git
#checkout, #commit, #diff, #fetch, #files, #pull, #rebase, #refs, #reset, #rev, #stash, #status
#check_style, #emphasize, #log_message, #log_title, #sub_style
Methods inherited from Base
#base_path, #build, #build?, #clean, #clean?, #copy, #copy?, #doc, #doc?, #enabled?, #has?, #initialize, #refresh, #refresh?, #styles, to_s, #to_s, #to_sym, #verbose?
Methods included from Common
#as_a, #get, #message, #set
Class Method Details
.is_a?(path) ⇒ Boolean
21
22
23
24
25
26
27
28
|
# File 'lib/squared/repo/project/python.rb', line 21
def is_a?(path)
if path.is_a?(::String) || path.is_a?(::Pathname)
base = Pathname.new(path)
['setup.py', 'requirements.txt'].any? { |file| base.join(file).exist? }
else
super
end
end
|
.tasks ⇒ Object
8
9
10
|
# File 'lib/squared/repo/project/python.rb', line 8
def tasks
nil
end
|
.to_sym ⇒ Object
12
13
14
|
# File 'lib/squared/repo/project/python.rb', line 12
def to_sym
:python
end
|
.venv? ⇒ Boolean
16
17
18
19
|
# File 'lib/squared/repo/project/python.rb', line 16
def venv?
path = ENV['VIRTUAL_ENV']
!path.nil? && Dir.exist?(path)
end
|
Instance Method Details
#depend(flag = nil, opts: []) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/squared/repo/project/python.rb', line 65
def depend(flag = nil, opts: [])
if @depend
super
else
cmd = pip_session 'install -r requirements.txt'
case flag
when :upgrade
cmd << '--upgrade'
cmd << '--upgrade-strategy=eager' if opts.include?('eager')
when :force
cmd << '--force-reinstall'
end
cmd << '--pre' if opts.include?('pre')
cmd << '--require-virtualenv' if opts.include?('venv')
cmd << '--no-cache-dir' if opts.include?('no-cache')
cmd << '--dry-run' if opts.include?('dry-run')
append_nocolor
run(exception: @workspace.exception)
end
end
|
#depend? ⇒ Boolean
88
89
90
|
# File 'lib/squared/repo/project/python.rb', line 88
def depend?
!@depend.nil? || outdated?
end
|
#outdated ⇒ Object
86
|
# File 'lib/squared/repo/project/python.rb', line 86
def outdated(*); end
|
#outdated? ⇒ Boolean
92
93
94
|
# File 'lib/squared/repo/project/python.rb', line 92
def outdated?
base_path('requirements.txt').exist?
end
|
#populate ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/squared/repo/project/python.rb', line 35
def populate(*)
super
return unless outdated?
namespace @name do
@@tasks[:python].each do |action, flags|
namespace action do
flags.each do |flag|
case action
when :install
options = lambda do |*opts|
opts += %w[pre venv no-cache dry-run]
format_desc(action, flag, opts)
end
case flag
when :upgrade
desc options.('eager')
when :force
desc options.()
end
task flag do |_, args|
install(flag, opts: collect_args(args, :opts))
end
end
end
end
end
end
end
|