diff --git a/manifests/pip.pp b/manifests/pip.pp index eaada706..76b3af48 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -160,8 +160,8 @@ # If it wasn't or if there is any error, the package manager will trigger a failure. $grep_regex = $_ensure ? { /^(present|absent|latest)$/ => "^${real_pkgname}[[:space:]].*$", - /^[0-9].*$/ => "^${real_pkgname}[[:space:]]\\+(\\?${_ensure}\\()$\\|$\\|, \\|[[:space:]]\\)", - default => fail('ensure can be a version number or one of: present, absent, latest') + /^v?[0-9].*$/ => "^${real_pkgname}[[:space:]]\\+(\\?${_ensure}\\()$\\|$\\|, \\|[[:space:]]\\)", + default => fail('ensure can be a version number (e.g. 1.7.0 or v1.7.0) or one of: present, absent, latest') } $extras_string = empty($extras) ? { @@ -195,7 +195,7 @@ } } else { case $_ensure { - /^[0-9].*$/: { + /^v?[0-9].*$/: { # Specific version $command = "${pip_install} ${install_args} ${pip_common_args}==${_ensure}" $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index d7115427..40add6d6 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -147,6 +147,20 @@ end end + describe 'install specific version' do + context 'supports v-prefixed version string' do + let(:params) { { ensure: 'v1.7.0' } } + + it { is_expected.to contain_exec('pip_install_rpyc').with_command('pip --log /tmp/pip.log install rpyc==v1.7.0') } + end + + context 'supports version string without v-prefix' do + let(:params) { { ensure: '1.7.0' } } + + it { is_expected.to contain_exec('pip_install_rpyc').with_command('pip --log /tmp/pip.log install rpyc==1.7.0') } + end + end + describe 'uninstall' do context 'adds correct title' do let(:params) { { ensure: 'absent' } }