Skip to content

[feature] Add ref, refs and read_text OmegaConf resolvers - #303

Open
ptomecek wants to merge 3 commits into
mainfrom
feature/config-resolvers
Open

ptomecek wants to merge 3 commits into
mainfrom
feature/config-resolvers

Conversation

@ptomecek

@ptomecek ptomecek commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds three OmegaConf resolvers, registered only under the cc. prefix so they don't replace another library's resolver of the same bare name.

${cc.ref:KEY} returns the registry path /KEY (dots become slashes), or null when the config holds no value at KEY. A config can then refer to a registered model by name, sharing the instance as /KEY does, and still switch an optional model off by setting it to null. Today that takes ${cc.if_else:${cc.is_none_or_empty:${oc.select:KEY,null}},null,/KEY}, and ${KEY} copies the model's configuration instead of sharing the instance.

${cc.refs:KEY} maps each non-null entry of the mapping at KEY to its registry path, for a field that holds the models a config group selected. ${cc.read_text:PATH} and ${cc.read_text:PACKAGE,RESOURCE} return the text of a file or of a resource inside an installed package, so long text such as a prompt can live in its own file and still be part of the configuration, and so of the cache key. ${cc.cmd:cat ...} shells out and can't locate package resources. Hydra parses string values again when it instantiates a config, so read_text rejects text containing ${; otherwise an interpolation in the file, such as ${cc.cmd:...}, would be resolved and could run a command.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build configuration
  • Other (describe below)

Checklist

  • Linting passes (make lint)
  • Tests pass (make test)
  • New tests added for new functionality
  • Documentation updated (if applicable)
  • Changelog / version bump (if applicable)

${cc.ref:KEY} returns the registry path /KEY, or null when the config
holds no value at KEY, so a config can refer to a registered model by
name and still switch an optional one off by setting it to null.

${cc.refs:KEY} maps each non-null entry of the mapping at KEY to its
registry path, for a field holding the models a config group selected.

${cc.read_text:PATH} and ${cc.read_text:PACKAGE,RESOURCE} return the
text of a file or of a resource inside an installed package, so long
text such as a prompt can live in its own file and still be part of
the configuration.

Signed-off-by: Pascal Tomecek <40371786+ptomecek@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

    1 files  ±0      1 suites  ±0   2m 32s ⏱️ +7s
1 639 tests +4  1 637 ✅ +7  2 💤  - 3  0 ❌ ±0 
1 726 runs  +4  1 724 ✅ +7  2 💤  - 3  0 ❌ ±0 

Results for commit 3454977. ± Comparison against base commit 424a17f.

This pull request skips 1 and un-skips 4 tests.
ccflow.tests.enums.test_pydantic ‑ test_json_schema_no_csp
ccflow.tests.enums.test_pydantic ‑ test_json_schema_csp
ccflow.tests.examples.test_calculator.TestCalculatorCli ‑ test_cli
ccflow.tests.examples.test_etl.TestEtl ‑ test_cli
ccflow.tests.utils.test_tokenize.TestAdversarialFixes ‑ test_function_docstring_still_stripped

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

    1 files  ± 0      1 suites  ±0   2m 12s ⏱️ -13s
1 675 tests +40  1 673 ✅ +43  2 💤  - 3  0 ❌ ±0 
1 762 runs  +40  1 760 ✅ +43  2 💤  - 3  0 ❌ ±0 

Results for commit 0198354. ± Comparison against base commit 424a17f.

This pull request skips 1 and un-skips 4 tests.
ccflow.tests.enums.test_pydantic ‑ test_json_schema_no_csp
ccflow.tests.enums.test_pydantic ‑ test_json_schema_csp
ccflow.tests.examples.test_calculator.TestCalculatorCli ‑ test_cli
ccflow.tests.examples.test_etl.TestEtl ‑ test_cli
ccflow.tests.utils.test_tokenize.TestAdversarialFixes ‑ test_function_docstring_still_stripped

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (424a17f) to head (0198354).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
+ Coverage   93.63%   93.71%   +0.08%     
==========================================
  Files         205      205              
  Lines       23158    23538     +380     
  Branches     1519     1547      +28     
==========================================
+ Hits        21683    22058     +375     
- Misses       1181     1187       +6     
+ Partials      294      293       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

timkpaine and others added 2 commits November 30, 2026 14:58
ref and refs returned null or an empty mapping for a mistyped key, a mandatory (???) value, or a key written relative to a config_key, which switched a model off with no error. They now raise when the parent of the key is absent, when a value on the way is mandatory, or when the key is relative, and still return null for an absent or null leaf so optional models can be left out. refs also raises when the key holds something other than a mapping, and turns entry names into strings.

ref, refs and read_text are registered only under the cc. prefix, so they don't replace another library's resolver of the same bare name. The docs now cover these errors, that list indexes are not supported, and how read_text treats relative paths and paths with commas.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Hydra parses string values again when it instantiates a config, so an
interpolation inside text read by read_text would be resolved then, and
a resolver such as cmd would run. read_text now raises for text
containing "${", leaving the text exactly as it would be if written
into the config as a literal string.

Signed-off-by: Pascal Tomecek <40371786+ptomecek@users.noreply.github.com>
@ptomecek
ptomecek marked this pull request as ready for review December 2, 2026 01:10
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.

2 participants