Repository navigation
Follow package defaults, keep unknown keys, add prune - #53
nicoloesch wants to merge 2 commits into
Conversation
a80c399 to
0258bc6
Compare
17c9bf7 to
260f2fc
Compare
| "\n[yellow]Not changed.[/yellow] A key unknown to the installed version may belong " | ||
| "to a newer one sharing this file. Run with --apply to remove them." | ||
| ) | ||
| return |
There was a problem hiding this comment.
prune --apply saves without checking whether the config changed since it was read. A concurrent CLI save can be overwritten.
I don't know that we are worried too much about concurrent writes like this, but since we hold a shared global path as the default better to be safe than sorry? Save lock stops writes interleaving but does not stop prune --apply from replacing newer config with stale snapshot...
| classes: list[type[PackageConfigBase]] = [] | ||
| for ep in sorted(entry_points(group=ENTRY_POINT_GROUP), key=lambda e: e.name): | ||
| try: | ||
| classes.append(ep.load()) |
There was a problem hiding this comment.
Prune accepts multiple package classes with the same tool_name. It applies each schema in sequence, so each can classify the other’s valid keys as unknown and remove them. The report can also omit keys removed by an earlier class.
Could duplicate tool_name registrations be treated as ambiguous and excluded from pruning?
260f2fc to
6b37046
Compare
Summary
A package's
[tools.<name>]section now stores only the values the user set. Defaults are followed from the package code, and stored keys the installed package does not declare are kept instead of deleted.pruneis the explicit way to remove them.Changes
resolve_fieldsreads the raw stored section, not a model dump that included defaults.plan_configurevalue, or entered at a prompt. A value used only for validation is not written.PackageConfigBase.to_explicit_dict()serialises just the fields that were supplied.unknown_keys()returns the stored keys a package has no field for, andcommit_section()carries them over unchanged on save.configurenames the kept keys after saving.[Enter = x]. Enter leaves a field as it is, and typing a value, even the default, stores it.confirm. Anything else asks again.[Enter = keep]and never its value.plan_package_config()returns a frozenPackagePlanwith the candidate stack,defaulted_fieldsandunknown_fields. Only names are reported. The stack is left out of the repr because tool sections can hold secrets.plan_configure()keeps its signature and returnsplan_package_config(...).config.prune_unknown_keys(config, package_configs)returns aPruneReportwith a validated copy and the removed names per tool. It leaves the input unchanged and does no file I/O. Sections without a package class are not touched.omop-config prunelists the keys and changes nothing until--applyis passed. A package that fails to load is skipped with a warning.docs/config-reference.mdanddocs/api/package-base.md. Addtests/test_package_values.pyand CLI tests, and update two prompt tests that assumed the old behaviour.Behaviour
plan_configurekeeps its signature and return type, and the new names are additions.PackageConfigBase.to_extra_dict()is unchanged.prunesays so and only lists unless--applyis passed.Checklist
feature)pytest -q): 654 passedruff check .,ty check src/ tests/)