class Autoproj::PackageManagers::PipManager

Using pip to install python packages

Attributes

installed_pips[R]

Public Class Methods

new(ws) click to toggle source
Calls superclass method Autoproj::PackageManagers::Manager::new
# File lib/autoproj/package_managers/pip_manager.rb, line 20
def initialize(ws)
    super(ws)
    @installed_pips = Set.new
end

Public Instance Methods

activate_python() click to toggle source
# File lib/autoproj/package_managers/pip_manager.rb, line 35
def activate_python
    Autoproj::Python.setup_python_configuration_options(ws: ws)
    Autoproj::Python.assert_python_activated(ws: ws)
end
guess_pip_program() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/autoproj/package_managers/pip_manager.rb, line 25
def os_dependencies
    super + ["pip"]
end
pip_home() click to toggle source

Return the directory where python packages are installed to. The actual path is pip_home/lib/pythonx.y/site-packages.

# 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) click to toggle source
# 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

                # We're not supposed to install rubygem packages but silent is not
                # set, so display information about them anyway
                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