Skip to content

Commit abec84c

Browse files
committed
Add support for uninstalling a requirements file in pip.packages.
This also fixes the unexpected behaviour before where it would install the requirements file if provided, even if `present=False`!
1 parent 78973a9 commit abec84c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pyinfra/operations/pip.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def virtualenv(
7878
def packages(
7979
packages=None, present=True, latest=False,
8080
requirements=None, pip='pip', virtualenv=None, virtualenv_kwargs=None,
81+
extra_install_args=None,
8182
state=None, host=None,
8283
):
8384
'''
@@ -86,7 +87,7 @@ def packages(
8687
+ packages: list of packages to ensure
8788
+ present: whether the packages should be installed
8889
+ latest: whether to upgrade packages without a specified version
89-
+ requirements: location of requirements file to install
90+
+ requirements: location of requirements file to install/uninstall
9091
+ pip: name or path of the pip directory to use
9192
+ virtualenv: root directory of virtualenv to work in
9293
+ virtualenv_kwargs: dictionary of arguments to pass to ``pip.virtualenv``
@@ -130,7 +131,10 @@ def packages(
130131

131132
# (un)Install requirements
132133
if requirements is not None:
133-
yield '{0} install -r {1}'.format(pip, requirements)
134+
if present:
135+
yield '{0} -r {1}'.format(install_command, requirements)
136+
else:
137+
yield '{0} -r {1}'.format(uninstall_command, requirements)
134138

135139
# Handle passed in packages
136140
if packages:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"kwargs": {
3+
"requirements": "requirements.pip",
4+
"present": false
5+
},
6+
"facts": {},
7+
"commands": [
8+
"pip uninstall --yes -r requirements.pip"
9+
]
10+
}

0 commit comments

Comments
 (0)