From 722adb30e49fd5fbafd862db249491d5d416d637 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 09:38:52 +0200 Subject: [PATCH 1/6] Fix pre-releases causing corrective changes 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'. --- manifests/pip.pp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 1ac36773..1cbe2cf8 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -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}) ]" From c4eaff212a2fc30e948ef960afe9033c783842fc Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 13:01:54 +0200 Subject: [PATCH 2/6] Dev --- manifests/pip.pp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 1cbe2cf8..94639202 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -246,17 +246,17 @@ } # Unfortunately this is the smartest way of getting the latest available package version with pip as of now - $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" + $latest_version = join(["${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 = "${pip_env} freeze --all \ - | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3 \ - | tr -d '[:space:]'" + $installed_version = join(["${pip_env} freeze --all", + " | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3", + " | tr -d '[:space:]'"]) $unless_command = "[ \$(${latest_version}) = \$(${installed_version}) ]" From 45d874c464ac34b816cad76956121d2500aee1f5 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 13:12:28 +0200 Subject: [PATCH 3/6] Dev --- manifests/pip.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifests/pip.pp b/manifests/pip.pp index 94639202..5c391f60 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -242,6 +242,8 @@ $exclude_pre_releases_command = $include_pre_releases ? { true => '', + # The below regexp is based on this code, assuming that it is semi-authoritative on the PEP440 versioning: + # https://github.com/pypa/packaging/blob/21.3/packaging/version.py#L230-L235 default => ' | grep -vP "(a|b|c|rc|alpha|beta|pre|preview)[-_\.]?(\d+)?"', } From 67117b94fccb7d3c34bd0f12e22400ac47134419 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 13:18:18 +0200 Subject: [PATCH 4/6] Try to fix --- manifests/pip.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 5c391f60..fc82616e 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -249,9 +249,9 @@ # Unfortunately this is the smartest way of getting the latest available package version with pip as of now $latest_version = join(["${pip_env} install ${pypi_index} ${proxy_flag} ${pkgname}==notreallyaversion 2>&1", - " | grep -oP '\(from versions: \K(.*)(?=\))' | tr ',' '\n'", + ' | grep -oP "\(from versions: \K(.*)(?=\))" | tr "," "\n"', $exclude_pre_releases_command, - " | tail -n1"]) + ' | 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') From f37bbe54a5bd33606e702abb2be7fac394a8d05e Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 13:40:12 +0200 Subject: [PATCH 5/6] Fix extra space --- manifests/pip.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index fc82616e..93d89fd0 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -249,7 +249,7 @@ # Unfortunately this is the smartest way of getting the latest available package version with pip as of now $latest_version = join(["${pip_env} install ${pypi_index} ${proxy_flag} ${pkgname}==notreallyaversion 2>&1", - ' | grep -oP "\(from versions: \K(.*)(?=\))" | tr "," "\n"', + ' | grep -oP "\(from versions: \K(.*)(?=\))" | tr "," "\n" | tr -d "[:space:]"', $exclude_pre_releases_command, ' | tail -n1']) From d29bfe96e7870ceef0ce5ee62f3381646826a5b4 Mon Sep 17 00:00:00 2001 From: Greg Dubicki Date: Thu, 12 May 2022 13:58:58 +0200 Subject: [PATCH 6/6] Fix order --- manifests/pip.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 93d89fd0..5c818e40 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -249,7 +249,7 @@ # Unfortunately this is the smartest way of getting the latest available package version with pip as of now $latest_version = join(["${pip_env} install ${pypi_index} ${proxy_flag} ${pkgname}==notreallyaversion 2>&1", - ' | grep -oP "\(from versions: \K(.*)(?=\))" | tr "," "\n" | tr -d "[:space:]"', + ' | grep -oP "\(from versions: \K(.*)(?=\))" | tr -d "[:space:]" | tr "," "\n"', $exclude_pre_releases_command, ' | tail -n1'])