Skip to content

feat(operations.pkg): migrate FreeBSD pkg to PackageInfo (phase 2 of #1725)#1823

Open
wowi42 wants to merge 3 commits into
pyinfra-dev:3.xfrom
KalvadTech:feat/pkg-unified-packages
Open

feat(operations.pkg): migrate FreeBSD pkg to PackageInfo (phase 2 of #1725)#1823
wowi42 wants to merge 3 commits into
pyinfra-dev:3.xfrom
KalvadTech:feat/pkg-unified-packages

Conversation

@wowi42

@wowi42 wowi42 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Phase 2 of the staged rollout tracked in #1725.

Summary

Migrates the pkg (FreeBSD) manager to the unified package model. Per the rollout direction, the manager exposes a single fact: PkgPackages now returns list[PackageInfo] directly. There are no PkgUpgradeablePackages / PkgLockedPackages sub-facts.

  • PkgPackages returns list[PackageInfo] sorted by name, gathered by one compound command: (pkg query '%n %v %k' && echo __pyinfra_pkg_remote__ && (pkg version -vRL= || true)) || pkg_info || true. On FreeBSD, pkg query provides name/version/locked in one pass and pkg version -vRL= (after the marker line) provides available upgrades, so entries carry HELD and UPGRADEABLE statuses. On other BSDs the pkg_info fallback runs and every entry is INSTALLED. The marker presence tells process() which format to parse, so the two formats never mix.
  • build_package_map() now returns the same list[PackageInfo] shape (name lives on each entry, so a name-keyed dict only duplicated it). Phase 1 merged after the v3.9.2 release, so this signature change is not in any released version.
  • PackageInfo gains to_json() so json_encode can serialize fact output (CLI fact command and the test harness).
  • ensure_packages() additionally accepts list[PackageInfo], normalizing to a name-keyed dict internally. Existing dict-shaped callers are unchanged.
  • New operations: pkg.update(force=False) (non-idempotent catalog refresh) and pkg.upgrade() (noops when nothing is upgradeable). pkg.packages gains latest; packages locked with pkg lock always noop, even with latest=True.
  • Test harness: parse_value in tests/util.py builds PackageInfo from a {"packageinfo": {...}} tagged dict (same spirit as the existing set: / datetime: conventions). Later phases reuse this hook.

Test plan

  • New fact fixtures: FreeBSD output with locked, upgradeable, and multi-version packages; pkg_info fallback; empty output.
  • New operation fixtures: pkg.update (plain/force), pkg.upgrade (noop/upgrades), pkg.packages with latest (upgrade, up-to-date noop, held noop).
  • Existing pkg.packages fixtures updated to the list shape; behaviour unchanged.
  • tests/test_facts_packages.py updated for the list return plus a to_json() round-trip test; tests/test_operations_utils.py gains a list[PackageInfo] case.

Requirements

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)

@wowi42 wowi42 added new feature operations Issues with operations. facts Issues with facts. labels Jun 10, 2026
@wowi42 wowi42 changed the title feat(pkg): migrate FreeBSD pkg to PackageInfo (phase 2 of #1725) feat(operations.pkg): migrate FreeBSD pkg to PackageInfo (phase 2 of #1725) Jun 11, 2026
@DonDebonair

Copy link
Copy Markdown
Collaborator

After merging #1878, PackageInfo shouldn't need to_json anymore. JSON encoding is now baked into the test harness.

If you rebase (likely after #1878 merge), I will review so you can continue on the grand plan :)

wowi42 added 2 commits July 14, 2026 11:13
…ness

- Remove PackageInfo.to_json now that pyinfra-testing serializes dataclasses
- Extend pyinfra_cli json_encode with enum/dataclass support
- Normalize dict-shaped PkgPackages values in pkg operations
- Update pkg operation fixtures from packageinfo tags to plain dicts
- Update tests
@wowi42 wowi42 force-pushed the feat/pkg-unified-packages branch from 8787b2e to 65c4f3e Compare July 14, 2026 09:35
…t in pkg ops

Replace the private _package_info_from_value helper with a public
PackageInfo.from_dict classmethod so the conversion lives next to the
model and can be reused by later package-manager migrations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

facts Issues with facts. new feature operations Issues with operations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants