Skip to content

Follow package defaults, keep unknown keys, add prune - #53

Open
nicoloesch wants to merge 2 commits into
mainfrom
29-preserve-package-values
Open

nicoloesch wants to merge 2 commits into
mainfrom
29-preserve-package-values

Conversation

@nicoloesch

@nicoloesch nicoloesch commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #48 (22-structured-resolver-errors) and targets that branch. Retarget to main once #48 has landed.

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. prune is the explicit way to remove them.

Changes

  • Stop storing defaults
    • resolve_fields reads the raw stored section, not a model dump that included defaults.
    • A field is written if it was already stored, passed as a flag or plan_configure value, 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.
  • Keep unknown keys
    • unknown_keys() returns the stored keys a package has no field for, and commit_section() carries them over unchanged on save.
    • configure names the kept keys after saving.
  • Prompts
    • The prompt default is empty and the effective value is shown as [Enter = x]. Enter leaves a field as it is, and typing a value, even the default, stores it.
    • Booleans use y/n/Enter in place of confirm. Anything else asks again.
    • A sensitive field shows [Enter = keep] and never its value.
  • Plan result
    • plan_package_config() returns a frozen PackagePlan with the candidate stack, defaulted_fields and unknown_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 returns plan_package_config(...).config.
  • Prune
    • prune_unknown_keys(config, package_configs) returns a PruneReport with 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 prune lists the keys and changes nothing until --apply is passed. A package that fails to load is skipped with a warning.
  • Update docs/config-reference.md and docs/api/package-base.md. Add tests/test_package_values.py and CLI tests, and update two prompt tests that assumed the old behaviour.

Behaviour

  • Non-breaking API. plan_configure keeps its signature and return type, and the new names are additions.
  • Saved files change. A section no longer gains the package defaults, and unknown keys are no longer dropped. Files that already contain materialised defaults are not cleaned up and keep those values.
  • PackageConfigBase.to_extra_dict() is unchanged.
  • Interactive prompts behave differently. Enter no longer re-enters the shown default as a stored value.
  • Pruning with an older package version removes keys that a newer version sharing the file may use. prune says so and only lists unless --apply is passed.

Checklist

  • Applied exactly one label (feature)
  • Tests pass locally (pytest -q): 654 passed
  • Lint and type checks pass (ruff check ., ty check src/ tests/)

@nicoloesch nicoloesch added the feature New backwards-compatible functionality. MINOR: x.y+1.z label Oct 27, 2026
@nicoloesch
nicoloesch marked this pull request as ready for review November 7, 2026 17:39
@nicoloesch
nicoloesch force-pushed the 29-preserve-package-values branch from a80c399 to 0258bc6 Compare November 16, 2026 21:28
@nicoloesch
nicoloesch requested a review from gkennos November 16, 2026 21:30
@nicoloesch
nicoloesch marked this pull request as draft November 16, 2026 21:32
@nicoloesch
nicoloesch marked this pull request as ready for review November 16, 2026 22:05
@nicoloesch
nicoloesch added this pull request to stack #59 November 16, 2026 22:05
@nicoloesch nicoloesch added feature New backwards-compatible functionality. MINOR: x.y+1.z and removed feature New backwards-compatible functionality. MINOR: x.y+1.z labels Nov 16, 2026
@nicoloesch
nicoloesch force-pushed the 29-preserve-package-values branch 2 times, most recently from 17c9bf7 to 260f2fc Compare November 18, 2026 03:42
"\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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Base automatically changed from 22-structured-resolver-errors to main November 19, 2026 20:51
@nicoloesch
nicoloesch force-pushed the 29-preserve-package-values branch from 260f2fc to 6b37046 Compare November 19, 2026 20:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New backwards-compatible functionality. MINOR: x.y+1.z

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve explicit package configuration and define unknown-key/default round-trip policy

2 participants