Class: Autoproj::PackageManagers::PipManager
- Inherits:
-
Manager
- Object
- Manager
- Autoproj::PackageManagers::PipManager
show all
- Defined in:
- lib/autoproj/package_managers/pip_manager.rb
Overview
Using pip to install python packages
Instance Attribute Summary collapse
Attributes inherited from Manager
#enabled, #silent, #ws
Instance Method Summary
collapse
Methods inherited from Manager
#call_while_empty?, #configure_manager, #enabled?, #silent?, #strict?
Constructor Details
Returns a new instance of PipManager.
20
21
22
23
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 20
def initialize(ws)
super(ws)
@installed_pips = Set.new
end
|
Instance Attribute Details
#installed_pips ⇒ Object
Returns the value of attribute installed_pips.
7
8
9
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 7
def installed_pips
@installed_pips
end
|
Instance Method Details
#activate_python ⇒ Object
#guess_pip_program ⇒ Object
29
30
31
32
33
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 29
def guess_pip_program
activate_python
Autobuild.programs["pip"] = "pip" unless Autobuild.programs["pip"]
Autobuild.programs["pip"]
end
|
#initialize_environment ⇒ Object
9
10
11
12
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 9
def initialize_environment
ws.env.set "PYTHONUSERBASE", pip_home
ws.env.add_path "PATH", File.join(pip_home, "bin")
end
|
#install(pips, filter_uptodate_packages: false, install_only: false) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 40
def install(pips, filter_uptodate_packages: false, install_only: false)
guess_pip_program
pips = [pips] if pips.is_a?(String)
base_cmdline = [Autobuild.tool("pip"), "install", "--user"]
cmdlines = [base_cmdline + pips]
if pips_interaction(cmdlines)
Autoproj.message " installing/updating Python dependencies:" \
" #{pips.sort.join(', ')}"
cmdlines.each do |c|
Autobuild::Subprocess.run "autoproj", "osdeps", *c,
env: ws.env.resolved_env
end
pips.each do |p|
@installed_pips << p
end
end
end
|
#os_dependencies ⇒ Object
25
26
27
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 25
def os_dependencies
super + ["pip"]
end
|
#pip_home ⇒ Object
Return the directory where python packages are installed to. The actual path is pip_home/lib/pythonx.y/site-packages.
16
17
18
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 16
def pip_home
ws.env["AUTOPROJ_PYTHONUSERBASE"] || File.join(ws.prefix_dir, "pip")
end
|
#pips_interaction(cmdlines) ⇒ Object
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
|
# File 'lib/autoproj/package_managers/pip_manager.rb', line 63
def pips_interaction(cmdlines)
if OSPackageInstaller.force_osdeps
return true
elsif enabled?
return true
elsif silent?
return false
end
puts <<-EOMSG
#{Autoproj.color('The build process and/or the packages require some Python packages to be installed', :bold)}
#{Autoproj.color('and you required autoproj to not do it itself', :bold)}
The following command line can be used to install them manually
#{' '}
#{cmdlines.map { |c| c.join(' ') }.join("\n ")}
#{' '}
Autoproj expects these Python packages to be installed in #{pip_home} This can
be overridden by setting the AUTOPROJ_PYTHONUSERBASE environment variable manually
EOMSG
print " #{Autoproj.color('Press ENTER to continue ', :bold)}"
$stdout.flush
$stdin.readline
puts
false
end
|