Re: [Puppet Users] pip and virtualenv

Michael Cumings
Fri, 03 Feb 2012 14:31:23 -0000

These modules work fine for what I need...

define virtualenv($ensure = ''present'', $executable=false,
$relocatable=false,
  $extra_search_dir=false, $site_packages=false,
  $never_download=false, $prompt=false, $user=''root'') {

    $executable_opt = $executable ? { false => '''', default
=> $executable }
    $relocatable_opt = $relocatable ? { false => '''',
default =>
''--relocatable'' }
    $site_packages_opt = $site_packages ? { false =>
''--no-site-packages'',
default => '''' }
    $never_download_opt = $never_download ? { false => '''',
default =>
''-never-download'' }
    $prompt_opt = $prompt ? { false => '''', default =>
"--prompt=$prompt" }
    $extra_search_dir_opt = $extra_search_dir ? {
false => '''',
default => inline_template(''<%= extra_search_dir.collect { |dir|
"--extra-search-dir={dir}"}.join(" ") %>'')
    }

    if $ensure == ''present'' {
exec { "virtual_env-$nme":
    command => "virtualenv $executable_opt $relocatable_opt
$site_packages_opt \
$never_download_opt $extrasearch_dir_opt $prompt_opt $name",
    creates => "$name",
    user => $user,
    require => Pip::Install[''virtualenv''],
}
    }
    else {
file { $name :
    ensure => absent,
    recurse => true,
    force => true,
}
    }
}

define pip::install ($ensure = ''present'', $virtualenv = false,
     $package = false, $version = false) {

    $_package = $package ? { false => $name, default => $package }
    $env_opt = $virtualenv ? { false => '''', default =>
"--environment
$virtualenv" }
    $package_opt = $version ? { false => $_package, default =>
"$_package==$version" }

    if $ensure == ''present'' {
  exec { "pip_install_${_package}_${virtualenv}":
    unless => "pip freeze $env_opt | grep $package_opt",
    command => "pip install $env_opt $package_opt"
  }
    }
    else {
exec { "pip_uninstall_${package}_${virtualenv}":
    onlyif => "pip freeze $env_opt | grep $package_opt",
    command => "pip uninstall $env_opt $package_opt"
}
    }
}

I declare the virtualenv and then declare the modules I want installed in
them.  I have a very targeted use but I think they might be generic enough
to help.  Working on Puppet 2.5.7.

On Fri, Feb 3, 2012 at 6:18 AM, lfrodrigues <lfrodrigues@gmail.com> wrote:

> Hello,
>
> I would like to use pip to install some python modules. The problem is
> that I want to keep all my stuff isolated.
>
> I saw this https://projects.puppetlabs.com/issues/7286 about
> virtualenv support.
>
> Anyone knows at what stage that is? Any other solution for virtualenv
> and pip?
>
> Best regards,
>
> Luis
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.