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

pyinfra/operations: Handle latest value in installing pip requirements file #1237

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions pyinfra/operations/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ def packages(
install_command_args.append(extra_install_args)
install_command = " ".join(install_command_args)

upgrade_command = "{0} --upgrade".format(install_command)
uninstall_command = " ".join([pip, "uninstall", "--yes"])

# (un)Install requirements
if requirements is not None:
if present:
yield "{0} -r {1}".format(install_command, requirements)
yield "{0} -r {1}".format(upgrade_command if latest else install_command, requirements)
else:
yield "{0} -r {1}".format(uninstall_command, requirements)

Expand All @@ -199,7 +200,7 @@ def packages(
present,
install_command=install_command,
uninstall_command=uninstall_command,
upgrade_command="{0} --upgrade".format(install_command),
upgrade_command=upgrade_command,
version_join="==",
latest=latest,
)
12 changes: 12 additions & 0 deletions tests/operations/pip.packages/install_latest_requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"kwargs": {
"latest": true,
"requirements": "requirements.txt"
},
"facts": {},
"commands": [
"pip install --upgrade -r requirements.txt"
],
"idempotent": false,
"disable_idempotent_warning_reason": "pip package requirements are always executed"
}
Loading