Skip to content

Commit 4f2c04b

Browse files
author
Antonis Christofides
committed
Added src parameter for pip in python::requirements
A requirements file can have --editable resources; in such a case the pip default is to install them in ~/src/, which can be unsuitable; for example, if run by root, /root/src/ is usually unreadable by other users. pip provides an --src parameter to specify an alternative directory. This is useful for installing requirements systemwide, outside a virtualenv.
1 parent a017bd3 commit 4f2c04b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Installs and manages Python packages from requirements file.
7777

7878
**owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root
7979

80+
**src** - The ``--src`` parameter to ``pip``, used to specify where to install ``--editable`` resources; by default no ``--src`` parameter is passed to ``pip``.
81+
8082
**group** - The group that was used to create the virtualenv. This is used to create the requirements file with correct permissions if it's not present already.
8183

8284
python::requirements { '/var/www/project1/requirements.txt':

manifests/requirements.pp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
# [*proxy*]
2020
# Proxy server to use for outbound connections. Default: none
2121
#
22+
# [*src*]
23+
# Pip --src parameter; if the requirements file contains --editable resources,
24+
# this parameter specifies where they will be installed. See the pip
25+
# documentation for more. Default: none (i.e. use the pip default).
26+
#
2227
# [*environment*]
2328
# Additional environment variables required to install the packages. Default: none
2429
#
@@ -41,6 +46,7 @@
4146
$owner = 'root',
4247
$group = 'root',
4348
$proxy = false,
49+
$src = false,
4450
$environment = []
4551
) {
4652

@@ -63,6 +69,11 @@
6369
default => "--proxy=${proxy}",
6470
}
6571

72+
$src_flag = $src ? {
73+
false => '',
74+
default => "--src=${src}",
75+
}
76+
6677
# This will ensure multiple python::virtualenv definitions can share the
6778
# the same requirements file.
6879
if !defined(File[$requirements]) {
@@ -79,7 +90,7 @@
7990

8091
exec { "python_requirements${name}":
8192
provider => shell,
82-
command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} -r ${requirements}",
93+
command => "${pip_env} --log-file ${cwd}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
8394
refreshonly => true,
8495
timeout => 1800,
8596
user => $owner,

0 commit comments

Comments
 (0)