Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make install latest ignore pre-releases (unless --pre is passed) #1

Draft
wants to merge 6 commits into
base: dont_use_pip_search_and_fixed_dotfile
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,20 @@
}

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

$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+)?"',
}

# 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 = join(["${pip_env} install ${pypi_index} ${proxy_flag} ${pkgname}==notreallyaversion 2>&1",
' | grep -oP "\(from versions: \K(.*)(?=\))" | tr -d "[:space:]" | 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')
Expand Down