Skip to content

Commit 7464d01

Browse files
author
Joshua Spence
committed
Allow setting a custom index for python::pip
1 parent cd7dacc commit 7464d01

3 files changed

Lines changed: 55 additions & 32 deletions

File tree

manifests/pip.pp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
# [*group*]
2626
# The group of the virtualenv being manipulated. Default: root
2727
#
28+
# [*index*]
29+
# Base URL of Python package index. Default: none (http://pypi.python.org/simple/)
30+
#
2831
# [*proxy*]
2932
# Proxy server to use for outbound connections. Default: none
3033
#
@@ -53,6 +56,7 @@
5356
# python::pip { 'flask':
5457
# virtualenv => '/var/www/project1',
5558
# proxy => 'http://proxy.domain.com:3128',
59+
# index => 'http://www.example.com/simple/',
5660
# }
5761
#
5862
# === Authors
@@ -67,6 +71,7 @@
6771
$url = false,
6872
$owner = 'root',
6973
$group = 'root',
74+
$index = false,
7075
$proxy = false,
7176
$egg = false,
7277
$editable = false,
@@ -103,6 +108,11 @@
103108
default => "${virtualenv}/bin/pip",
104109
}
105110

111+
$pypi_index = $index ? {
112+
false => '',
113+
default => "--index-url=${index}",
114+
}
115+
106116
$proxy_flag = $proxy ? {
107117
false => '',
108118
default => "--proxy=${proxy}",
@@ -162,38 +172,36 @@
162172

163173
# Explicit version out of VCS when PIP supported URL is provided
164174
if $source =~ /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp)(:\/\/).+$/ {
165-
if $ensure != present and $ensure != latest {
166-
exec { "pip_install_${name}":
167-
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure}#egg=${egg_name} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure}#egg=${egg_name} ;}",
168-
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
169-
user => $owner,
170-
group => $group,
171-
cwd => $cwd,
172-
environment => $environment,
173-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
174-
timeout => $timeout,
175-
}
176-
}
177-
else {
178-
exec { "pip_install_${name}":
179-
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
180-
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
181-
user => $owner,
182-
group => $group,
183-
cwd => $cwd,
184-
environment => $environment,
185-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
186-
timeout => $timeout,
187-
}
175+
if $ensure != present and $ensure != latest {
176+
exec { "pip_install_${name}":
177+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure}#egg=${egg_name} || ${pip_env} --log ${log}/pip.log install ${install_args} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure}#egg=${egg_name} ;}",
178+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
179+
user => $owner,
180+
group => $group,
181+
cwd => $cwd,
182+
environment => $environment,
183+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
184+
timeout => $timeout,
185+
}
186+
} else {
187+
exec { "pip_install_${name}":
188+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${install_args} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
189+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
190+
user => $owner,
191+
group => $group,
192+
cwd => $cwd,
193+
environment => $environment,
194+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
195+
timeout => $timeout,
196+
}
188197
}
189-
}
190-
else {
198+
} else {
191199
case $ensure {
192200
/^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/: {
193201
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
194202
# Explicit version.
195203
exec { "pip_install_${name}":
196-
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
204+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install ${install_args} \$wheel_support_flag ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
197205
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
198206
user => $owner,
199207
group => $group,
@@ -207,7 +215,7 @@
207215
present: {
208216
# Whatever version is available.
209217
exec { "pip_install_${name}":
210-
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
218+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install \$wheel_support_flag ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
211219
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
212220
user => $owner,
213221
group => $group,
@@ -221,7 +229,7 @@
221229
latest: {
222230
# Latest version.
223231
exec { "pip_install_${name}":
224-
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
232+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install --upgrade \$wheel_support_flag ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
225233
unless => "${pip_env} search ${proxy_flag} ${source} | grep -i INSTALLED | grep -i latest",
226234
user => $owner,
227235
group => $group,

manifests/virtualenv.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# requirements => '/var/www/project1/requirements.txt',
6161
# proxy => 'http://proxy.domain.com:3128',
6262
# systempkgs => true,
63-
# index => 'http://www.example.com/simple/'
63+
# index => 'http://www.example.com/simple/',
6464
# }
6565
#
6666
# === Authors

spec/defines/pip_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,29 @@
4343
end
4444
context "adds proxy to install command if proxy set" do
4545
let (:params) {{ :proxy => "http://my.proxy:3128" }}
46-
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc ;}") }
46+
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc ;}") }
4747
end
4848
context "adds proxy to search command if set to latest" do
4949
let (:params) {{ :proxy => "http://my.proxy:3128", :ensure => 'latest' }}
50-
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --upgrade --proxy=http://my.proxy:3128 rpyc ;}") }
50+
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --upgrade --proxy=http://my.proxy:3128 rpyc ;}") }
5151
it { is_expected.to contain_exec("pip_install_rpyc").with_unless('pip search --proxy=http://my.proxy:3128 rpyc | grep -i INSTALLED | grep -i latest') }
5252
end
5353
end
5454

55+
describe 'index as' do
56+
context 'defaults to empty' do
57+
let (:params) {{ }}
58+
it { is_expected.to contain_exec('pip_install_rpyc').without_command(/--index-url/) }
59+
end
60+
context 'adds index to install command if index set' do
61+
let (:params) {{ :index => 'http://www.example.com/simple/' }}
62+
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --index-url=http://www.example.com/simple/ rpyc ;}") }
63+
end
64+
context 'adds index to search command if set to latest' do
65+
let (:params) {{ :index => 'http://www.example.com/simple/', :ensure => 'latest' }}
66+
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --upgrade --index-url=http://www.example.com/simple/ rpyc ;}") }
67+
end
68+
end
69+
5570
end
56-
end
71+
end

0 commit comments

Comments
 (0)