Skip to content

Commit 87e2c76

Browse files
fix(pip): add pre_release parameter and filter latest_version
1 parent 66bfce4 commit 87e2c76

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

manifests/pip.pp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
String[1] $log_dir = '/tmp',
7171
Array[String] $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
7272
String[1] $exec_provider = 'shell',
73+
Boolean $pre_release = false,
7374
) {
7475
$python_provider = getparam(Class['python'], 'provider')
7576
$python_version = getparam(Class['python'], 'version')
@@ -133,6 +134,11 @@
133134
$install_editable = ''
134135
}
135136

137+
$prerelease_flag = $pre_release ? {
138+
false => '',
139+
default => '--pre'
140+
}
141+
136142
# TODO: Do more robust argument checking, but below is a start
137143
if ($ensure == absent) and $install_args {
138144
fail('python::pip cannot provide install_args with ensure => absent')
@@ -179,7 +185,7 @@
179185
default => "'${url}#egg=${egg_name}'",
180186
}
181187

182-
$pip_install = "${pip_env} --log ${log}/pip.log install"
188+
$pip_install = "${pip_env} --log ${log}/pip.log install ${prerelease_flag}"
183189
$pip_common_args = "${pypi_index} ${pypi_extra_index} ${proxy_flag} ${install_editable} ${source}"
184190

185191
# Explicit version out of VCS when PIP supported URL is provided
@@ -217,12 +223,21 @@
217223
# Unfortunately this is the smartest way of getting the latest available package version with pip as of now
218224
# Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns
219225
# more than one line with paretheses.
220-
$latest_version = join([
221-
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
222-
" ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1",
223-
" | sed -nE 's/.*\\(from versions: (.*, )*(.*)\\)/\\2/p'",
224-
' | tr -d "[:space:]"',
225-
])
226+
# Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
227+
$latest_version = $pre_release ? {
228+
false => join([
229+
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
230+
" ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1",
231+
" | sed -nE 's/.*\\(from versions: ([^\\)]*)\\)/\\1/p'",
232+
' | awk \'BEGIN {RS=", "} {if ($0 !~ /(a|b|rc|dev)/) {gsub(/\n/,"");stable[arraylen++]=$0}} END {print stable[arraylen-1] }\'',
233+
]),
234+
default => join([
235+
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
236+
" ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1",
237+
" | sed -nE 's/.*\\(from versions: (.*, )*(.*)\\)/\\2/p'",
238+
' | tr -d "[:space:]"',
239+
])
240+
}
226241

227242
# Packages with underscores in their names are listed with dashes in their place in `pip freeze` output
228243
$pkgname_with_dashes = regsubst($real_pkgname, '_', '-', 'G')

0 commit comments

Comments
 (0)