Skip to content

feat: add configuration profiles - #26

Merged
bhirsz merged 2 commits into
mainfrom
feat/profiles
Aug 30, 2026
Merged

feat: add configuration profiles#26
bhirsz merged 2 commits into
mainfrom
feat/profiles

Conversation

@bhirsz

@bhirsz bhirsz commented Aug 30, 2026

Copy link
Copy Markdown
Member

Summary

Implements configuration profiles (#4) — named sets of config overrides
that are selected at runtime with a new builtin --profile option.

[tool.mytool]
loglevel = "INFO"
console = "verbose"

[tool.mytool.profiles.ci]
loglevel = "DEBUG"
console = "dotted"

[tool.mytool.profiles.dev]
inherits = ["ci"]     # merge ci first...
console = "verbose"   # ...then override
$ mytool --profile ci
$ mytool --profile 'ci-*'              # glob
$ mytool --profile ci --profile extra  # multiple, merged in order

Behaviour

  • Selection by exact name or fnmatch glob; every pattern must match at
    least one profile, else ConfigDiscoveryError.
  • Override, not extend — profile values replace the base (and earlier
    profiles); lists are replaced, not appended.
  • inherits (name or list) merges parents first, recursively, with cycle
    detection.
  • precedence (int, default 0) orders multiple selected profiles — lower
    applied first, higher wins; ties keep selection order.
  • enabled = false skips a directly selected profile (inherited parents
    still contribute).
  • Profiles sit in the TOML layer, so CLI args and env vars still win.
  • Read from the nearest project config; profiles/inherits/precedence/
    enabled are reserved keys, never treated as options.

Scope (deliberately minimal)

Modeled on a subset of robotcode's profiles. Not included (can follow later):
hidden, detached, default_profiles, extend_profiles, condition
expressions, and env-based profile activation. Value extension from profiles
(append-style extend_*) is intentionally omitted.

Changes

  • profiles.py: selection, glob, inherits, precedence, enabled, overlay build.
  • base.py: builtin --profile option.
  • processor.py: _apply_profiles overlays selected profiles onto the base
    section before mapping; strips the reserved profiles table.
  • __init__.py: export build_profile_overlay, select_profiles.
  • README.md: new "Profiles" section.
  • tests/test_profiles.py: 16 tests.

Closes #4

@bhirsz bhirsz mentioned this pull request Aug 30, 2026
@bhirsz
bhirsz changed the base branch from main to feat/env-args August 30, 2026 13:29
Base automatically changed from feat/env-args to main August 30, 2026 13:34
bhirsz and others added 2 commits August 30, 2026 15:34
Add named configuration profiles declared under
<section>.profiles.<name> in the tool's TOML file. A new builtin
--profile option (repeatable, glob-aware) selects one or more profiles
whose values are merged onto the base config before the usual key
mapping and precedence, so CLI args and env vars still win.

Supported: exact/glob selection, multiple profiles ordered by
precedence, inherits (recursive, cycle-checked), and enabled=false to
skip a directly selected profile. Values override (lists are replaced,
not appended). The reserved profiles/inherits/precedence/enabled keys
are consumed and never treated as options.

Closes #4

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bhirsz
bhirsz merged commit 44ed0ca into main Aug 30, 2026
8 checks passed
@bhirsz
bhirsz deleted the feat/profiles branch August 30, 2026 13:34
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.

Analyze profiles support

1 participant