Skip to content

Let a caller ask which targets a configuration declares - #144

Merged
ps-pufferfish merged 2 commits into
mainfrom
declared-targets
Sep 7, 2026
Merged

ps-pufferfish merged 2 commits into
mainfrom
declared-targets

Conversation

@ps-pufferfish

Copy link
Copy Markdown
Contributor

Why

A caller that generates one configuration into several places has somewhere to put each target, and so needs to know which targets there are. relcoord is that caller: it holds a manifests directory per cluster and generates a target into each.

With no way to ask, it opens config.toml itself and composes find_config_file, load_toml_file, config_version and parse_targets into a small loader of its own — this package's business, in another repository. Two costs: it has to keep its own idea of what a target is, and it can reach a different conclusion about a configuration than generate() does. It also has to import parse_targets, which reads more like an internal of the loader than a contract.

declared_targets(config_dir) is the question those four calls were spelling out:

from manifest_builder import declared_targets

declared_targets(Path("conf"))   # ("platform-dev", "platform-prod")

Behaviour

  • The declared names, in the order the file declares them.
  • None for a directory that declares config blocks directly, and for one holding no config file at all — which generate() reports on better than a version check would.
  • A malformed target raises here the same way generating it would, since it is parse_targets that decides.

That None also answers the question the caller was really asking. generate() takes target or vars and rejects the wrong one for the layout, so a caller has to know which layout the file is before it can call at all — which is why relcoord was reading the file in the first place. One call now covers both.

What it lets the caller stop doing

portswigger-cloud/relcoord#98 needs this. That PR is about a related problem — relcoord asks each configured output for the target of its own name, so a config repository declaring only the clusters it deploys to fails with Unknown target on the rest — and on top of this it shrinks to one call in place of a four-call composition and a version branch.

Verification

276 passed; ruff check, ruff format --check and ty check clean. Six new tests: the names in declared order, None for both block-style layouts and for a missing file, a manifest-builder.toml, and a target without sections failing the way generating it would.

README gains a short Asking which targets a configuration declares subsection under Targets and sections.

A caller that generates one configuration into several places -- relcoord, into
a manifests directory per cluster -- has somewhere to put each target and needs
to know which targets exist. Without a way to ask, it opens config.toml and
composes find_config_file, load_toml_file, config_version and parse_targets
into a small loader of its own, which is this package's business in another
repository: it has to track what a target is, and can reach a different
conclusion about a configuration than generate() does.

The names alone answer it, with None distinguishing a directory that declares
blocks directly -- which also tells a caller to pass variables rather than a
target, the reason it was reading the file in the first place.
@ps-pufferfish
ps-pufferfish merged commit 341a1f9 into main Sep 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant