|
28 | 28 | # Sergey Stankevich |
29 | 29 | # |
30 | 30 | define python::pip ( |
31 | | - $virtualenv, |
| 31 | + $virtualenv = 'system', |
32 | 32 | $ensure = present, |
33 | 33 | $url = false, |
34 | 34 | $owner = 'root', |
|
42 | 42 | fail('python::pip: virtualenv parameter must not be empty') |
43 | 43 | } |
44 | 44 |
|
| 45 | + if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') { |
| 46 | + fail('python::pip: root user must be used when virtualenv is system') |
| 47 | + } |
| 48 | + |
| 49 | + $cwd = $virtualenv ? { |
| 50 | + 'system' => '/', |
| 51 | + default => "${virtualenv}", |
| 52 | + } |
| 53 | + |
| 54 | + $pip_env = $virtualenv ? { |
| 55 | + 'system' => '`which pip`', |
| 56 | + default => "${virtualenv}/bin/pip", |
| 57 | + } |
| 58 | + |
45 | 59 | $proxy_flag = $proxy ? { |
46 | 60 | false => '', |
47 | 61 | default => "--proxy=${proxy}", |
|
60 | 74 | case $ensure { |
61 | 75 | present: { |
62 | 76 | exec { "pip_install_${name}": |
63 | | - command => "${virtualenv}/bin/pip install ${proxy_flag} ${source}", |
64 | | - unless => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}", |
| 77 | + command => "$pip_env --log-file ${cwd}/pip.log install ${proxy_flag} ${source}", |
| 78 | + unless => "$pip_env freeze | grep -i -e ${grep_regex}", |
65 | 79 | user => $owner, |
66 | 80 | environment => $environment, |
67 | 81 | } |
68 | 82 | } |
69 | 83 |
|
70 | 84 | default: { |
71 | 85 | exec { "pip_uninstall_${name}": |
72 | | - command => "echo y | ${virtualenv}/bin/pip uninstall ${proxy_flag} ${name}", |
73 | | - onlyif => "${virtualenv}/bin/pip freeze | grep -i -e ${grep_regex}", |
| 86 | + command => "echo y | $pip_env uninstall ${proxy_flag} ${name}", |
| 87 | + onlyif => "$pip_env freeze | grep -i -e ${grep_regex}", |
74 | 88 | user => $owner, |
75 | 89 | environment => $environment, |
76 | 90 | } |
|
0 commit comments