Skip to content

Commit

Permalink
fix(pip): filter with install_args instead of breaking change pre_rel…
Browse files Browse the repository at this point in the history
…ease
  • Loading branch information
teluq-pbrideau committed Jun 17, 2024
1 parent b726520 commit 9d3e063
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# @param log_dir Log directory
# @param egg The egg name to use
# @param umask
# @param pre_release if ye allow to install with --pre
#
# @example Install Flask to /var/www/project1 using a proxy
# python::pip { 'flask':
Expand Down Expand Up @@ -71,7 +70,6 @@
String[1] $log_dir = '/tmp',
Array[String] $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
String[1] $exec_provider = 'shell',
Boolean $pre_release = false,
) {
$python_provider = getparam(Class['python'], 'provider')
$python_version = getparam(Class['python'], 'version')
Expand Down Expand Up @@ -135,11 +133,6 @@
$install_editable = ''
}

$prerelease_flag = $pre_release ? {
false => '',
default => '--pre'
}

# TODO: Do more robust argument checking, but below is a start
if ($ensure == absent) and $install_args {
fail('python::pip cannot provide install_args with ensure => absent')
Expand Down Expand Up @@ -222,22 +215,21 @@
}

# Unfortunately this is the smartest way of getting the latest available package version with pip as of now
# Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns
# more than one line with paretheses.
# Public version identifiers: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
$latest_version = $pre_release ? {
false => join([
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
" ${install_args} ${install_editable} ${real_pkgname}==0.0 2>&1",
" | sed -nE 's/.*\\(from versions: ([^\\)]*)\\)/\\1/p'",
' | awk \'BEGIN {RS=", "} {if ($0 !~ /(a|b|rc|dev)/) {gsub(/\n/,"");stable[arraylen++]=$0}} END {print stable[arraylen-1] }\'',
]),
default => join([
if $install_args and $install_args =~ /--pre/ {
$latest_version = join([
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
" ${install_args} ${install_editable} ${real_pkgname}==0.0 2>&1",
" | sed -nE 's/.*\\(from versions: (.*, )*(.*)\\)/\\2/p'",
' | tr -d "[:space:]"',
])
} else {
$latest_version = join([
"${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
" ${install_args} ${install_editable} ${real_pkgname}==0.0 2>&1",
" | sed -nE 's/.*\\(from versions: ([^\\)]*)\\)/\\1/p'",
' | awk \'BEGIN {RS=", "} {if ($0 !~ /(a|b|rc|dev)/) {gsub(/\n/,"");stable[arraylen++]=$0}} END {print stable[arraylen-1] }\'',
])
}

# Packages with underscores in their names are listed with dashes in their place in `pip freeze` output
Expand Down

0 comments on commit 9d3e063

Please sign in to comment.