feat(facts.util.packages): add PackageInfo model (phase 1 of #1725)#1726
Open
wowi42 wants to merge 3 commits intopyinfra-dev:3.xfrom
Open
feat(facts.util.packages): add PackageInfo model (phase 1 of #1725)#1726wowi42 wants to merge 3 commits intopyinfra-dev:3.xfrom
wowi42 wants to merge 3 commits intopyinfra-dev:3.xfrom
Conversation
Introduce PackageInfo, PackageStatus and build_package_map() so package facts can return rich, structured data instead of dict[str, set[str]]. Update operations.util.packaging.ensure_packages to accept either the existing dict[str, set[str]] or the new dict[str, PackageInfo], and honour HELD / UPGRADEABLE / INSTALLED status when present. No manager migrations yet, so existing facts/ops keep returning the legacy shape and behave identically. Refs pyinfra-dev#1725
Add cases that previously had no coverage: - versioned _has_package against PackageInfo (matching and mismatching) - present=False uninstall with PackageInfo (installed and held) - UPGRADEABLE with a pinned version request goes through install, not upgrade Refs pyinfra-dev#1725
…sion output Sets are hash-randomized for strings, so picking a single version via next(iter(versions)) and joining via ",".join(value) produced different strings across runs. Sort first so: - PackageInfo.installed_version chosen by build_package_map() is stable - ensure_packages() noop messages are deterministic when a manager reports multiple installed versions for the same name Lock both behaviours with regression tests. Refs pyinfra-dev#1725
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of the staged rollout tracked in #1725 (replacing the rotted #1594).
PackageInfodataclass,PackageStatusenum, andbuild_package_map()insrc/pyinfra/facts/util/packages.py.operations/util/packaging.ensure_packages()to accept either the legacydict[str, set[str]]or the newdict[str, PackageInfo]. WhenPackageInfois provided,HELDpackages always noop,UPGRADEABLEpackages are upgraded whenlatest=True, andINSTALLEDpackages with no available upgrade noop with an "up to date" message.latest=Truestill blindly adds every versionless package to the upgrade list, and noop messages keep the existing format.build_package_map()and_format_version()sort their input set before consuming it, so noop strings and the choseninstalled_versionare stable across runs. Set iteration order is hash-randomized for strings, so the previous behaviour was non-deterministic.Test plan
tests/test_facts_packages.py: unit tests forPackageInfoandbuild_package_map, including status precedence, frozen instances, empty version sets, and deterministic selection from a multi-version set.tests/test_operations_utils.py::TestEnsurePackagesDualFormat: 14 cases covering both shapes; pinned-version match/mismatch againstPackageInfo; uninstall paths (installed, held, missing);latestinteraction withHELD,UPGRADEABLE, and pinned versions; sorted multi-version noop string.Requirements
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)