Skip to content

Commit 5477c34

Browse files
author
Marc Fournier
committed
python::virtualenv - '--system-site-packages' option
New 'systempkgs' parameter will call virtualenv with the '--system-site-packages' option, which can greatly speed up creation in some cases.
1 parent 452451e commit 5477c34

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ Creates Python virtualenv.
6464

6565
**proxy** — Proxy server to use for outbound connections. Default: none
6666

67+
**systempkgs** — Copy system site-packages into virtualenv. Default: don't
68+
6769
python::virtualenv { '/var/www/project1':
6870
ensure => present,
6971
version => 'system',
7072
requirements => '/var/www/project1/requirements.txt',
7173
proxy => 'http://proxy.domain.com:3128',
74+
systempkgs => true,
7275
}
7376

7477
### python::gunicorn

manifests/virtualenv.pp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
# [*proxy*]
1717
# Proxy server to use for outbound connections. Default: none
1818
#
19+
# [*systempkgs*]
20+
# Copy system site-packages into virtualenv. Default: don't
21+
#
1922
# === Examples
2023
#
2124
# python::virtualenv { '/var/www/project1':
2225
# ensure => present,
2326
# version => 'system',
2427
# requirements => '/var/www/project1/requirements.txt',
2528
# proxy => 'http://proxy.domain.com:3128',
29+
# systempkgs => true,
2630
# }
2731
#
2832
# === Authors
@@ -33,7 +37,8 @@
3337
$ensure = present,
3438
$version = 'system',
3539
$requirements = false,
36-
$proxy = false
40+
$proxy = false,
41+
$systempkgs = false,
3742
) {
3843

3944
$venv_dir = $name
@@ -55,10 +60,15 @@
5560
default => "&& export http_proxy=${proxy}",
5661
}
5762

63+
$system_pkgs_flag = $systempkgs ? {
64+
false => '',
65+
default => '--system-site-packages',
66+
}
67+
5868
exec { "python_virtualenv_${venv_dir}":
5969
command => "mkdir -p ${venv_dir} \
6070
${proxy_command} \
61-
&& virtualenv -p `which ${python}` ${venv_dir} \
71+
&& virtualenv -p `which ${python}` ${system_pkgs_flag} ${venv_dir} \
6272
&& ${venv_dir}/bin/pip install ${proxy_flag} --upgrade distribute pip",
6373
creates => $venv_dir,
6474
}

tests/virtualenv.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
version => 'system',
1010
requirements => '/var/www/project1/requirements.txt',
1111
proxy => 'http://proxy.domain.com:3128',
12+
systempkgs => true,
1213
}

0 commit comments

Comments
 (0)