Skip to content

Commit b85d62a

Browse files
allow setting an index URL when creating the venv
1 parent 175ac42 commit b85d62a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Diff for: REFERENCE.md

+9
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ The following parameters are available in the `python::pyvenv` defined type:
904904
* [`path`](#-python--pyvenv--path)
905905
* [`environment`](#-python--pyvenv--environment)
906906
* [`prompt`](#-python--pyvenv--prompt)
907+
* [`index`](#-python--pyvenv--index)
907908
* [`pip_version`](#-python--pyvenv--pip_version)
908909

909910
##### <a name="-python--pyvenv--ensure"></a>`ensure`
@@ -986,6 +987,14 @@ Optionally specify the virtualenv prompt (python >= 3.6)
986987

987988
Default value: `undef`
988989

990+
##### <a name="-python--pyvenv--index"></a>`index`
991+
992+
Data type: `Optional[String[1]]`
993+
994+
Optionally specify an index location from where pip and setuptools should be installed
995+
996+
Default value: `undef`
997+
989998
##### <a name="-python--pyvenv--pip_version"></a>`pip_version`
990999

9911000
Data type: `Python::Venv::PipVersion`

Diff for: manifests/pyvenv.pp

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# @param path Specifies the PATH variable.
1212
# @param environment Optionally specify environment variables for pyvenv
1313
# @param prompt Optionally specify the virtualenv prompt (python >= 3.6)
14+
# @param index Optionally specify an index location from where pip and setuptools should be installed
1415
#
1516
# @example
1617
# python::pyvenv { '/var/www/project1' :
@@ -34,6 +35,7 @@
3435
Array $environment = [],
3536
Optional[String[1]] $prompt = undef,
3637
Python::Venv::PipVersion $pip_version = 'latest',
38+
Optional[String[1]] $index = undef,
3739
) {
3840
include python
3941

@@ -80,13 +82,18 @@
8082

8183
$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"
8284

85+
$index_config = $index ? {
86+
undef => '',
87+
default => "-i ${index}"
88+
}
89+
8390
$pip_upgrade = ($pip_version != 'latest') ? {
8491
true => "--upgrade 'pip ${pip_version}'",
8592
false => '--upgrade pip',
8693
}
8794

8895
exec { "python_virtualenv_${venv_dir}":
89-
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${prompt_arg} ${venv_dir} && ${pip_cmd} --log ${venv_dir}/pip.log install ${pip_upgrade} && ${pip_cmd} --log ${venv_dir}/pip.log install --upgrade setuptools",
96+
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${prompt_arg} ${venv_dir} && ${pip_cmd} --log ${venv_dir}/pip.log install ${index_config} ${pip_upgrade} && ${pip_cmd} --log ${venv_dir}/pip.log install ${index_config} --upgrade setuptools",
9097
user => $owner,
9198
creates => "${venv_dir}/bin/activate",
9299
path => $_path,

Diff for: spec/classes/python_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
it {
156156
expect(subject).to contain_exec('python_virtualenv_/opt/env1').
157157
with(
158-
command: 'python3.8 -m venv --clear /opt/env1 && /opt/env1/bin/pip --log /opt/env1/pip.log install --upgrade pip && /opt/env1/bin/pip --log /opt/env1/pip.log install --upgrade setuptools',
158+
command: 'python3.8 -m venv --clear /opt/env1 && /opt/env1/bin/pip --log /opt/env1/pip.log install --upgrade pip && /opt/env1/bin/pip --log /opt/env1/pip.log install --upgrade setuptools',
159159
user: 'root',
160160
creates: '/opt/env1/bin/activate',
161161
path: [
@@ -175,7 +175,7 @@
175175
it {
176176
expect(subject).to contain_exec('python_virtualenv_/opt/env2').
177177
with(
178-
command: 'python3.8 -m venv --clear /opt/env2 && /opt/env2/bin/pip --log /opt/env2/pip.log install --upgrade \'pip <= 20.3.4\' && /opt/env2/bin/pip --log /opt/env2/pip.log install --upgrade setuptools',
178+
command: 'python3.8 -m venv --clear /opt/env2 && /opt/env2/bin/pip --log /opt/env2/pip.log install --upgrade \'pip <= 20.3.4\' && /opt/env2/bin/pip --log /opt/env2/pip.log install --upgrade setuptools',
179179
user: 'root',
180180
creates: '/opt/env2/bin/activate',
181181
path: [

0 commit comments

Comments
 (0)