← Back to issue list

fix(deb): avoid python-apt for installed package checks

View original Github issue

Metadata

Project
craft-parts
Number
#1485
Type
pull request
State
merged
Author
gcomneno
Labels
—
Created
Updated
Closed

Current evaluation

PR #1485 merged as commit a98be83a: host install_packages() now uses dpkg-query (plus apt-get --simulate) instead of python-apt for installed-package checks, fixing PermissionError when /etc/apt/sources.list is absent. Closes #976.

Resolution: closed resolved

Reason: The PR was merged to main as commit a98be83a after extended review (37 comments addressed over several iterations, including a make format fix). It implements the stated fix — replacing python-apt with dpkg-query for host installed-state checks — and closes craft-parts#976, which is now marked closed.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Fixes #976 ## Background On Ubuntu Plucky, `/etc/apt/sources.list` may be absent because the system uses deb822-based configuration exclusively. When `python-apt` initializes its cache (`apt.cache.Cache(rootdir="/")`), it attempts to ensure certain files exist, including `/etc/apt/sources.list`. If the file is missing, it attempts to create it. When running as an unprivileged user (e.g. during integration tests), this results in: PermissionError: [Errno 13] Permission denied: '//etc/apt/sources.list' This failure happens in the installed-package check path, before any actual installation occurs. ## What this change does For the host `install_packages()` path only: - Replace the use of `python-apt` for: - checking whether packages are already installed - constructing the returned `package=version` list - Use `dpkg-query` instead for installed-state detection. Actual installation still uses: apt-get install ... Stage package handling and other apt-cache–based functionality remain unchanged. ## Rationale For determining whether a package is installed, `dpkg-query` is: - sufficient - does not require root - independent of apt source configuration - unaffected by deb822 migration Using `python-apt` for this specific optimization is unnecessary and causes failures on systems without `/etc/apt/sources.list`. ## Trade-offs - `dpkg-query` does not resolve virtual packages in the same way as `python-apt`. - However: - `apt-get install` still performs dependency and virtual package resolution. - The returned `package=version` list is already documented as “best effort”. - Typical build-packages (cmake, gcc, pkg-config, etc.) are concrete packages. ## Scope This change only affects the installed-check optimization and version reporting for host installs. All apt-cache usage for stage packages remains intact.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved PR #1485 merged as commit a98be83a: host install_packages() now uses dpkg-query (plus apt-get --simulate) instead of python-apt for installed-package checks, fixing PermissionError when /etc/apt/sources.list is absent. Closes #976.
stealth/space-bunny-alpha — closed resolved Merged as a98be83a via #1485: host installed-package checks now use dpkg-query, avoiding python-apt permission errors on deb822 systems without /etc/apt/sources.list; fixes #976.
qwen3.6-35b-a3b-mtp-q6 — — Merged. Replaces python-apt with dpkg-query for host package checks to prevent PermissionError on deb822 systems missing /etc/apt/sources.list. Actual installation uses apt-get. Review cycle addressed formatting and CI failures prior to merge.
qwen/qwen3.8-27b
Impact: 50
Quick Win: 22
Staleness: 5
Complexity: 55
Confidence: 85
needs review Replaces python-apt with dpkg-query/apt-get --simulate for host installed-package checks to avoid PermissionError when /etc/apt/sources.list is absent (fixes #976). Approved by 2 reviewers; active review cycle with unresolved ruff formatting request and merge conflicts.
qwen/qwen3.6-35b-a3b
Staleness: 5
Complexity: 30
Confidence: 90
needs review Replaces python-apt with dpkg-query for host installed package checks to avoid permission errors on deb822-only systems. Approved, CI passing, merge conflicts resolved, awaiting final maintainer review.
qwen/qwen3.6-35b-a3b
Staleness: 10
Complexity: 30
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to fix permission errors on deb822-only systems. CI passing, awaiting maintainer review after merge conflict resolution.
qwen/qwen3.6-35b-a3b
Staleness: 10
Complexity: 35
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. Currently under review with unresolved comments and pending merge conflict resolution.
qwen/qwen3.6-35b-a3b
Staleness: 15
Complexity: 50
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. Currently under review, awaiting merge conflict resolution.
qwen/qwen3.6-35b-a3b
Staleness: 15
Complexity: 50
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. Currently awaiting maintainer review after addressing merge conflicts and requested changes.
qwen/qwen3.6-35b-a3b
Staleness: 10
Complexity: 45
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. CI passes, author addressed reviewer feedback, awaiting maintainer approval.
qwen/qwen3.6-35b-a3b
Staleness: 20
Complexity: 40
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to avoid permission errors on deb822-only systems. CI passes, review requested with 8 unresolved comments, awaiting maintainer feedback.
qwen/qwen3.6-35b-a3b
Staleness: 10
Complexity: 45
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to fix permission errors on deb822-only systems. CI passes. Awaiting maintainer re-review after recent updates addressing requested changes.
qwen/qwen3.6-35b-a3b
Staleness: 20
Complexity: 30
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to avoid permission errors on deb822-only systems. CI passes, but review status remains changes_requested with unresolved comments despite recent contributor updates.
qwen/qwen3.6-35b-a3b
Staleness: 45
Complexity: 40
Confidence: 85
needs review Replaces python-apt with dpkg-query for host installed-package checks to prevent permission errors on deb822-only systems. Currently awaiting maintainer review after addressing requested changes; CI is mostly passing.
qwen/qwen3.6-35b-a3b
Staleness: 15
Complexity: 50
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. Currently under review with changes requested, author has addressed feedback and CI is green.
qwen3.6-35b-a3b-mtp-q6
Staleness: 20
Complexity: 40
Confidence: 90
needs review Replaces python-apt with dpkg-query for installed package checks to avoid permission errors on deb822-only systems. Awaiting maintainer review of latest changes addressing requested feedback.
qwen/qwen3.6-35b-a3b
Staleness: 45
Complexity: 45
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to prevent permission errors on deb822-only systems. Currently awaiting maintainer review after addressing requested changes; CI is green.
qwen3.6-35b-a3b-mtp-q6
Staleness: 20
Complexity: 40
Confidence: 85
needs review Replaces python-apt with dpkg-query for installed package checks to fix PermissionError on deb822-only systems. PR is green, review comments addressed, awaiting maintainer review.

Update history

Date Change
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated
updated

Related work

  • Duplicate Of: craft-parts#976 (confidence 100%)

    Issue #976 ("Package installer fails if /etc/apt/sources.list is absent") is closed by this PR; its summary cites a98be83a.

  • Related To: craft-parts#1468 (confidence 70%)

    c2836c97 'fix(deb): refresh apt cache before marking packages' is an adjacent change to the same install_packages() path in deb.py.

Related issues

Issue Project State Summary Similarity
#976 Package installer fails if `/etc/apt/sources.list` is absent craft-parts closed Fixed by merged PR #1485 (commit a98be83a), replacing python-apt installed-package checks with dpkg-query so a missing /etc/apt/sources.list no longer breaks package installation.
76%