pyinfra-dev / pyinfra-dev/pyinfra

Apt: Only update package lists if packages need to be installed

Open
#1,102 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

operations
Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Description

Is your feature request related to a problem? Please describe

I'm using this to install packages:

      apt.packages(
          name="Install packages",
          packages=('vim', 'avahi-daemon'),
          update=True,
          cache_time=3600,
      )

This runs an apt update if needed, to ensure that the install actually works (it can fail if the lists are outdated).

However, currently this runs the apt update every hour, even if the specified packages are already installed and no further action is needed (and because upgrade=False and latest=False, which are the defaults, there is AFAICS also no way that running the update could cause a package to be installed/upgraded that would not be without running the update). In practice, this means every pyinfra run takes quite long, even when just making a small other change...

Describe the solution you'd like

When update is specified, but not upgrade or latest, only run the apt update when any packages are missing. If latest and/or upgrade are specified, then the behavior must remain as now, since the update needs to be run to decide whether any packages can be upgraded.

This is a change in behavior, but the documentation says "update: run apt update before installing packages", so the proposed behavior would (IMHO) better implement the documentation - run update only before/when actually installing packages.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Python implementation of the apt.packages operation and trace how update, upgrade, latest, and package presence affect command generation. Done means update runs only when packages are missing unless upgrade or latest is enabled, while existing behavior remains unchanged for those options.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.