Class: Squared::Repo::Project::Python

Inherits:
Git
  • Object
show all
Defined in:
lib/squared/repo/project/python.rb

Instance Attribute Summary

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?, #doc, #doc?, #enabled?, #has?, #initialize_build, #initialize_script, #inspect, #refresh, #refresh?, #test, #test?, to_s, #to_s, to_sym, #to_sym

Methods included from Common::Task

#collect_args, #invoke, #invoked?

Methods included from Common

#__get__, #__set__, #as_a, #finalize!, #message

Constructor Details

#initialize(name, path, workspace, **kwargs) ⇒ Python

Returns a new instance of Python.



32
33
34
35
# File 'lib/squared/repo/project/python.rb', line 32

def initialize(name, path, workspace, *, **kwargs)
  super
  initialize_build(REF, **kwargs)
end

Class Method Details

.is_a?(val) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/squared/repo/project/python.rb', line 23

def is_a?(val)
  if (val = as_path(val))
    REQUIREMENTS.any? { |file| val.join(file).exist? }
  else
    super
  end
end

.populateObject



12
# File 'lib/squared/repo/project/python.rb', line 12

def populate(*); end

.tasksObject



14
15
16
# File 'lib/squared/repo/project/python.rb', line 14

def tasks
  nil
end

.venv?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/squared/repo/project/python.rb', line 18

def venv?
  val = ENV['VIRTUAL_ENV']
  !val.nil? && Dir.exist?(val)
end

Instance Method Details

#depend(flag = nil, opts: [], override: false) ⇒ Object



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
96
# File 'lib/squared/repo/project/python.rb', line 71

def depend(flag = nil, opts: [], override: false)
  if @depend && !override
    super
  elsif outdated?
    case install_type
    when 1, 2
      cmd = pip_session 'install'
      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
      cmd << (install_type == 1 ? '-r requirements.txt' : '.')
      run(exception: workspace.exception)
    when 3
      run_s "#{@bin} setup.py install"
    end
  end
end

#depend?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/squared/repo/project/python.rb', line 107

def depend?
  !!@depend || outdated?
end

#install_typeObject



100
101
102
103
104
105
# File 'lib/squared/repo/project/python.rb', line 100

def install_type(*)
  return @requirements if @requirements

  ret = REQUIREMENTS.index { |file| base_path(file).exist? }
  @requirements = ret ? ret + 1 : 0
end

#outdatedObject



98
# File 'lib/squared/repo/project/python.rb', line 98

def outdated(*); end

#outdated?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/squared/repo/project/python.rb', line 111

def outdated?
  install_type > 0
end

#populateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/squared/repo/project/python.rb', line 41

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
            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|
              depend(flag, opts: collect_args(args, :opts), override: true)
            end
          end
        end
      end
    end
  end
end