Skip to content

Commit

Permalink
Fix pre-releases causing corrective changes
Browse files Browse the repository at this point in the history
The way we get all the available versions returns also the pre-releases.
But unless a `--pre` flag is added to $install_args, we don't want to
update to them when $ensure set to 'latest'.
  • Loading branch information
Greg Dubicki committed May 12, 2022
1 parent 25e2644 commit 722adb3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,25 @@
}

'latest': {
$include_pre_releases = $install_args =~ /(^| )--pre($| )/

$exclude_pre_releases_command = $include_pre_releases ? {
true => '',
default => ' | grep -vP "(a|b|c|rc|alpha|beta|pre|preview)[-_\.]?(\d+)?"',
}

# 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.
$latest_version = join(["${pip_env} install ${proxy_flag} ${pkgname}==notreallyaversion 2>&1",
' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"',
' | tr -d "[:space:]"'])
$latest_version = "${pip_env} install ${pypi_index} ${proxy_flag} ${pkgname}==notreallyaversion 2>&1 \
| grep -oP '\(from versions: \K(.*)(?=\))' | tr ',' '\n' \
$exclude_pre_releases_command \
| tail -n1"

# Packages with underscores in their names are listed with dashes in their place in `pip freeze` output
$pkgname_with_dashes = regsubst($pkgname, '_', '-', 'G')
$grep_regex_pkgname_with_dashes = "^${pkgname_with_dashes}=="
$installed_version = join(["${pip_env} freeze --all",
" | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3",
" | tr -d '[:space:]'"])
$installed_version = "${pip_env} freeze --all \
| grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3 \
| tr -d '[:space:]'"

$unless_command = "[ \$(${latest_version}) = \$(${installed_version}) ]"

Expand Down

0 comments on commit 722adb3

Please sign in to comment.