Skip to content

Commit

Permalink
operations.apt: dist-upgrade also supports --autoremove
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 authored and Fizzadar committed Feb 5, 2025
1 parent 70ce784 commit 260a659
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyinfra/operations/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ def upgrade(auto_remove: bool = False):


@operation()
def dist_upgrade():
def dist_upgrade(auto_remove: bool = False):
"""
Updates all apt packages, employing dist-upgrade.
+ auto_remove: removes transitive dependencies that are no longer needed.
**Example:**
.. code:: python
Expand All @@ -376,7 +378,12 @@ def dist_upgrade():
)
"""

yield from _simulate_then_perform("dist-upgrade")
command = ["dist-upgrade"]

if auto_remove:
command.append("--autoremove")

yield from _simulate_then_perform(" ".join(command))


@operation()
Expand Down
16 changes: 16 additions & 0 deletions tests/operations/apt.dist_upgrade/dist_upgrade_autoremove.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"kwargs": {"auto_remove": true},
"facts": {
"apt.SimulateOperationWillChange": {
"command=dist-upgrade --autoremove": {
"upgraded": 10,
"newly_installed": 3,
"removed": 2,
"not_upgraded": 3
}
}
},
"commands": [
"DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade --autoremove"
]
}

0 comments on commit 260a659

Please sign in to comment.