python: Add support for installing packages with pip

This commit is contained in:
Ossi Salmi 2016-02-24 15:21:40 +02:00
parent 4a30785106
commit bed8b2e777

View file

@ -129,3 +129,67 @@ define python::compile() {
}
}
# Install pip.
#
class python::pip {
case $::operatingsystem {
'openbsd': {
$package = 'py-pip'
}
default: {
$package = 'python-pip'
}
}
package { $package:
ensure => installed,
}
}
# Install python package using pip.
#
# === Parameters
#
# $name:
# Package name.
#
# $source:
# Optional source path to package archive.
#
define python::pip::install($source=undef) {
require python::pip
if $source {
$filename = basename($name)
file { "/usr/local/src/${filename}":
ensure => present,
mode => '0644',
owner => 'root',
group => $::operatingsystem ? {
'openbsd' => 'wheel',
default => 'root',
},
source => $source,
}
exec { "pip-install-${filename}":
refreshonly => true,
path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin',
command => "pip install --no-deps --no-index --upgrade /usr/local/src/${filename}",
subscribe => File["/usr/local/src/${filename}"],
}
} else {
package { $name:
ensure => installed,
provider => 'pip',
}
}
}